ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMembershipRegistrationCodeUtils.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
14 {
15  const CODE_LENGTH = 10;
16 
17 
23  public static function handleCode($a_ref_id, $a_type, $a_code)
24  {
25  global $DIC;
26 
27  $lng = $DIC['lng'];
28  $tree = $DIC['tree'];
29  $ilUser = $DIC['ilUser'];
30  include_once './Services/Link/classes/class.ilLink.php';
31  $lng->loadLanguageModule($a_type);
32  try {
33  self::useCode($a_code, $a_ref_id);
35  ilUtil::sendSuccess(sprintf($lng->txt($a_type . "_admission_link_success_registration"), $title), true);
38  switch ($e->getCode()) {
40  ilUtil::sendSuccess($e->getMessage(), true);
41  break;
43  ilUtil::sendFailure($lng->txt($a_type . "_admission_link_failure_membership_limited"), true);
44  break;
46  ilUtil::sendFailure($lng->txt($a_type . "_admission_link_failure_registration_period"), true);
47  break;
48  case ilMembershipRegistrationException::ADMISSION_LINK_INVALID://admission link is invalid
49  ilUtil::sendFailure($lng->txt($a_type . "_admission_link_failure_invalid_code"), true);
50  break;
52  ilUtil::sendFailure($lng->txt($a_type . '_admission_link_failure_offline'), true);
53  break;
55  ilUtil::sendFailure($lng->txt($a_type . '_admission_link_failure_availability'), true);
56  break;
57  default:
58  ilUtil::sendFailure($e->getMessage(), true);
59  break;
60  }
61  $parent_id = $tree->getParentId($a_ref_id);
63  }
64  }
65 
66 
67 
78  protected static function useCode($a_code, $a_endnode)
79  {
80  global $DIC;
81 
82  $tree = $DIC['tree'];
83  $ilUser = $DIC['ilUser'];
84 
85  $obj_ids = self::lookupObjectsByCode($a_code);
86 
87  if (!$obj_ids) {
88  include_once './Services/Membership/exceptions/class.ilMembershipRegistrationException.php';
90  }
91 
92  foreach ($tree->getPathId($a_endnode) as $ref_id) {
93  if (in_array(ilObject::_lookupObjId($ref_id), $obj_ids)) {
94  $factory = new ilObjectFactory();
95  $member_obj = $factory->getInstanceByRefId($ref_id, false);
96  if ($member_obj instanceof ilObjCourse) {
97  $member_obj->register($ilUser->getId(), ilCourseConstants::CRS_MEMBER);
98  }
99  if ($member_obj instanceof ilObjGroup) {
100  $member_obj->register($ilUser->getId(), IL_GRP_MEMBER, true);
101  }
102  }
103  }
104  }
105 
110  public static function generateCode()
111  {
112  // missing : 01iloO
113  $map = "23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
114 
115  $code = "";
116  $max = strlen($map) - 1;
117  for ($loop = 1; $loop <= self::CODE_LENGTH; $loop++) {
118  $code .= $map[mt_rand(0, $max)];
119  }
120  return $code;
121  }
122 
128  protected static function lookupObjectsByCode($a_code)
129  {
130  include_once './Modules/Group/classes/class.ilObjGroup.php';
131  include_once './Modules/Course/classes/class.ilObjCourse.php';
132 
133  return array_merge(
136  );
137  }
138 }
Class ilObjectFactory.
static lookupObjectsByCode($a_code)
Stores registration keys for key based registration on courses and groups.
global $DIC
Definition: saml.php:7
static lookupObjectsByCode($a_code)
Get all objects with enabled access codes.
static useCode($a_code, $a_endnode)
Use a registration code and assign the logged in user to the (parent) course/group that offer the cod...
$code
Definition: example_050.php:99
$factory
Definition: metadata.php:43
static _lookupTitle($a_id)
lookup object title
static handleCode($a_ref_id, $a_type, $a_code)
Handle target parameter.
const IL_GRP_MEMBER
static _lookupObjectId($a_ref_id)
lookup object id
$a_type
Definition: workflow.php:92
Class ilObjCourse.
$lng
static _lookupObjId($a_id)
$ilUser
Definition: imgupload.php:18
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static generateCode()
Generate new registration key.
static lookupObjectsByCode($a_code)
Class ilObjGroup.
static redirect($a_script)