ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $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  }
61 
62 
63 
74  protected static function useCode($a_code, $a_endnode)
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  }
98 
103  public static function generateCode()
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  }
115 
121  protected static function lookupObjectsByCode($a_code)
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  }
128 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
Class ilObjectFactory.
static lookupObjectsByCode($a_code)
Stores registration keys for key based registration on courses and groups.
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:47
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.
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)
global $lng
Definition: privfeed.php:17
Class ilObjGroup.
static redirect($a_script)