ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilMembershipRegistrationCodeUtils Class Reference

Stores registration keys for key based registration on courses and groups. More...

+ Collaboration diagram for ilMembershipRegistrationCodeUtils:

Static Public Member Functions

static handleCode ($a_ref_id, $a_type, $a_code)
 Handle target parameter. More...
 
static generateCode ()
 Generate new registration key. More...
 

Data Fields

const CODE_LENGTH = 10
 

Static Protected Member Functions

static useCode ($a_code, $a_endnode)
 Use a registration code and assign the logged in user to the (parent) course/group that offer the code. More...
 
static lookupObjectsByCode ($a_code)
 Get all objects with enabled access codes. More...
 

Detailed Description

Stores registration keys for key based registration on courses and groups.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 13 of file class.ilMembershipRegistrationCodeUtils.php.

Member Function Documentation

◆ generateCode()

static ilMembershipRegistrationCodeUtils::generateCode ( )
static

Generate new registration key.

Returns

Definition at line 103 of file class.ilMembershipRegistrationCodeUtils.php.

References $code.

Referenced by ilObjCourse\__createDefaultSettings(), ilObjGroup\cloneObject(), ilObjCourse\cloneSettings(), ilObjCourseGUI\initEditForm(), and ilObjGroupGUI\initForm().

104  {
105  // missing : 01iloO
106  $map = "23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
107 
108  $code = "";
109  $max = strlen($map)-1;
110  for ($loop = 1; $loop <= self::CODE_LENGTH; $loop++) {
111  $code .= $map[mt_rand(0, $max)];
112  }
113  return $code;
114  }
$code
Definition: example_050.php:99
+ Here is the caller graph for this function:

◆ handleCode()

static ilMembershipRegistrationCodeUtils::handleCode (   $a_ref_id,
  $a_type,
  $a_code 
)
static

Handle target parameter.

Parameters
object$a_target
Returns

Definition at line 23 of file class.ilMembershipRegistrationCodeUtils.php.

References $a_type, $ilUser, $lng, $title, ilLink\_getLink(), ilObject\_lookupObjectId(), ilObject\_lookupTitle(), ilMembershipRegistrationException\ADDED_TO_WAITINGLIST, ilMembershipRegistrationException\ADMISSION_LINK_INVALID, ilMembershipRegistrationException\OBJECT_IS_FULL, ilMembershipRegistrationException\OUT_OF_REGISTRATION_PERIOD, ilUtil\redirect(), ilMembershipRegistrationException\REGISTRATION_INVALID_AVAILABILITY, ilMembershipRegistrationException\REGISTRATION_INVALID_OFFLINE, ilUtil\sendFailure(), and ilUtil\sendSuccess().

Referenced by ilObjGroupGUI\_goto(), and ilObjCourseGUI\_goto().

24  {
25  global $lng, $tree, $ilUser;
26  include_once './Services/Link/classes/class.ilLink.php';
27  $lng->loadLanguageModule($a_type);
28  try {
29  self::useCode($a_code, $a_ref_id);
31  ilUtil::sendSuccess(sprintf($lng->txt($a_type . "_admission_link_success_registration"), $title), true);
34  switch ($e->getCode()) {
36  ilUtil::sendSuccess($e->getMessage(), true);
37  break;
39  ilUtil::sendFailure($lng->txt($a_type . "_admission_link_failure_membership_limited"), true);
40  break;
42  ilUtil::sendFailure($lng->txt($a_type . "_admission_link_failure_registration_period"), true);
43  break;
44  case ilMembershipRegistrationException::ADMISSION_LINK_INVALID://admission link is invalid
45  ilUtil::sendFailure($lng->txt($a_type . "_admission_link_failure_invalid_code"), true);
46  break;
48  ilUtil::sendFailure($lng->txt($a_type . '_admission_link_failure_offline'), true);
49  break;
51  ilUtil::sendFailure($lng->txt($a_type . '_admission_link_failure_availability'), true);
52  break;
53  default:
54  ilUtil::sendFailure($e->getMessage(), true);
55  break;
56  }
57  $parent_id = $tree->getParentId($a_ref_id);
59  }
60  }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static _lookupTitle($a_id)
lookup object title
static _lookupObjectId($a_ref_id)
lookup object id
$a_type
Definition: workflow.php:92
$ilUser
Definition: imgupload.php:18
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $lng
Definition: privfeed.php:17
static redirect($a_script)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lookupObjectsByCode()

static ilMembershipRegistrationCodeUtils::lookupObjectsByCode (   $a_code)
staticprotected

Get all objects with enabled access codes.

Parameters
string$a_code
Returns

Definition at line 121 of file class.ilMembershipRegistrationCodeUtils.php.

References ilObjGroup\lookupObjectsByCode(), and ilObjCourse\lookupObjectsByCode().

122  {
123  include_once './Modules/Group/classes/class.ilObjGroup.php';
124  include_once './Modules/Course/classes/class.ilObjCourse.php';
125 
126  return array_merge(ilObjGroup::lookupObjectsByCode($a_code), ilObjCourse::lookupObjectsByCode($a_code));
127  }
static lookupObjectsByCode($a_code)
static lookupObjectsByCode($a_code)
+ Here is the call graph for this function:

◆ useCode()

static ilMembershipRegistrationCodeUtils::useCode (   $a_code,
  $a_endnode 
)
staticprotected

Use a registration code and assign the logged in user to the (parent) course/group that offer the code.

Todo:
: throw an error if registration fails (max members, availibility...)
Parameters
string$a_code
int$a_endnodeReference id of node in tree
Returns

Definition at line 74 of file class.ilMembershipRegistrationCodeUtils.php.

References $factory, $ilUser, ilObject\_lookupObjId(), ilMembershipRegistrationException\ADMISSION_LINK_INVALID, ilCourseConstants\CRS_MEMBER, and IL_GRP_MEMBER.

75  {
76  global $tree,$ilUser;
77 
78  $obj_ids = self::lookupObjectsByCode($a_code);
79 
80  if (!$obj_ids) {
81  include_once './Services/Membership/exceptions/class.ilMembershipRegistrationException.php';
83  }
84 
85  foreach ($tree->getPathId($a_endnode) as $ref_id) {
86  if (in_array(ilObject::_lookupObjId($ref_id), $obj_ids)) {
87  $factory = new ilObjectFactory();
88  $member_obj = $factory->getInstanceByRefId($ref_id, false);
89  if ($member_obj instanceof ilObjCourse) {
90  $member_obj->register($ilUser->getId(), ilCourseConstants::CRS_MEMBER);
91  }
92  if ($member_obj instanceof ilObjGroup) {
93  $member_obj->register($ilUser->getId(), IL_GRP_MEMBER, true);
94  }
95  }
96  }
97  }
Class ilObjectFactory.
$factory
Definition: metadata.php:47
const IL_GRP_MEMBER
Class ilObjCourse.
static _lookupObjId($a_id)
$ilUser
Definition: imgupload.php:18
Class ilObjGroup.
+ Here is the call graph for this function:

Field Documentation

◆ CODE_LENGTH

const ilMembershipRegistrationCodeUtils::CODE_LENGTH = 10

Definition at line 15 of file class.ilMembershipRegistrationCodeUtils.php.


The documentation for this class was generated from the following file: