ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 (int $a_ref_id, string $a_type, string $a_code)
 
static generateCode ()
 Generate new registration key. More...
 

Static Protected Member Functions

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

Protected Attributes

const CODE_LENGTH = 10
 

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 27 of file class.ilMembershipRegistrationCodeUtils.php.

Member Function Documentation

◆ generateCode()

static ilMembershipRegistrationCodeUtils::generateCode ( )
static

Generate new registration key.

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

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

115  : string
116  {
117  // missing : 01iloO
118  $map = "23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
119 
120  $code = "";
121  $max = strlen($map) - 1;
122  for ($loop = 1; $loop <= self::CODE_LENGTH; $loop++) {
123  $code .= $map[random_int(0, $max)];
124  }
125  return $code;
126  }
+ Here is the caller graph for this function:

◆ handleCode()

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

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

References $DIC, Vendor\Package\$e, $lng, 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, and ilMembershipRegistrationException\REGISTRATION_INVALID_OFFLINE.

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

31  : void
32  {
33  global $DIC;
34  $main_tpl = $DIC->ui()->mainTemplate();
35 
36  $lng = $DIC->language();
37  $tree = $DIC->repositoryTree();
38 
39  $lng->loadLanguageModule($a_type);
40  try {
41  self::useCode($a_code, $a_ref_id);
43  $main_tpl->setOnScreenMessage('success', sprintf($lng->txt($a_type . "_admission_link_success_registration"), $title), true);
44  ilUtil::redirect(ilLink::_getLink($a_ref_id));
46  switch ($e->getCode()) {
48  $main_tpl->setOnScreenMessage('success', $e->getMessage(), true);
49  break;
51  $main_tpl->setOnScreenMessage('failure', $lng->txt($a_type . "_admission_link_failure_membership_limited"), true);
52  break;
54  $main_tpl->setOnScreenMessage('failure', $lng->txt($a_type . "_admission_link_failure_registration_period"), true);
55  break;
56  case ilMembershipRegistrationException::ADMISSION_LINK_INVALID://admission link is invalid
57  $main_tpl->setOnScreenMessage('failure', $lng->txt($a_type . "_admission_link_failure_invalid_code"), true);
58  break;
60  $main_tpl->setOnScreenMessage('failure', $lng->txt($a_type . '_admission_link_failure_offline'), true);
61  break;
63  $main_tpl->setOnScreenMessage('failure', $lng->txt($a_type . '_admission_link_failure_availability'), true);
64  break;
65  default:
66  $main_tpl->setOnScreenMessage('failure', $e->getMessage(), true);
67  break;
68  }
69  $parent_id = $tree->getParentId($a_ref_id);
70  ilUtil::redirect(ilLink::_getLink($parent_id));
71  }
72  }
static _lookupTitle(int $obj_id)
global $DIC
Definition: shib_login.php:22
static _lookupObjectId(int $ref_id)
static redirect(string $a_script)
global $lng
Definition: privfeed.php:31
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lookupObjectsByCode()

static ilMembershipRegistrationCodeUtils::lookupObjectsByCode ( string  $a_code)
staticprotected

Get all objects with enabled access codes.

Returns
int[]

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

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

132  : array
133  {
134  return array_merge(
137  );
138  }
static lookupObjectsByCode(string $a_code)
static lookupObjectsByCode(string $a_code)
+ Here is the call graph for this function:

◆ useCode()

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

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

Parameters
int$a_endnodeReference id of node in tree
Exceptions
ilDatabaseException
ilMembershipRegistrationException
ilObjectNotFoundException
Todo:
: throw an error if registration fails (max members, availibility...)

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

References $DIC, $ref_id, ilObject\_lookupObjId(), ilMembershipRegistrationException\ADMISSION_LINK_INVALID, ilCourseConstants\CRS_MEMBER, ilObjectFactory\getInstanceByRefId(), and ilParticipants\IL_GRP_MEMBER.

83  : void
84  {
85  global $DIC;
86 
87  $tree = $DIC->repositoryTree();
88  $ilUser = $DIC->user();
89 
90  $obj_ids = self::lookupObjectsByCode($a_code);
91 
92  if (!$obj_ids) {
94  'Admission code is not valid',
96  );
97  }
98 
99  foreach ($tree->getPathId($a_endnode) as $ref_id) {
100  if (in_array(ilObject::_lookupObjId($ref_id), $obj_ids)) {
101  $member_obj = ilObjectFactory::getInstanceByRefId($ref_id, false);
102  if ($member_obj instanceof ilObjCourse) {
103  $member_obj->register($ilUser->getId(), ilCourseConstants::CRS_MEMBER);
104  }
105  if ($member_obj instanceof ilObjGroup) {
106  $member_obj->register($ilUser->getId(), ilParticipants::IL_GRP_MEMBER, true);
107  }
108  }
109  }
110  }
static _lookupObjId(int $ref_id)
$ref_id
Definition: ltiauth.php:65
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
global $DIC
Definition: shib_login.php:22
Class ilObjGroup.
+ Here is the call graph for this function:

Field Documentation

◆ CODE_LENGTH

const ilMembershipRegistrationCodeUtils::CODE_LENGTH = 10
protected

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


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