ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  {
30  self::useCode($a_code,$a_ref_id);
32  ilUtil::sendSuccess(sprintf($lng->txt($a_type."_admission_link_success_registration"),$title),true);
34  }
36  {
37  switch($e->getCode())
38  {
39  case 124://added to waiting list
40  ilUtil::sendSuccess($e->getMessage(),true);
41  break;
42  case 123://object is full
43  ilUtil::sendFailure($lng->txt($a_type."_admission_link_failure_membership_limited"), true);
44  break;
45  case 789://out of registration period
46  ilUtil::sendFailure($lng->txt($a_type."_admission_link_failure_registration_period"), true);
47  break;
48  default:
49  ilUtil::sendFailure($e->getMessage(), true);
50  break;
51  }
52  $GLOBALS['ilLog']->logStack();
53  $GLOBALS['ilLog']->write($e->getCode().': '.$e->getMessage());
54 
55  $parent_id = $tree->getParentId($a_ref_id);
57  }
58  }
59 
60 
61 
72  protected static function useCode($a_code,$a_endnode)
73  {
74  global $tree,$ilUser;
75 
76  $obj_ids = self::lookupObjectsByCode($a_code);
77  foreach($tree->getPathId($a_endnode) as $ref_id)
78  {
79  if(in_array(ilObject::_lookupObjId($ref_id), $obj_ids))
80  {
82  {
83  $obj->register($ilUser->getId());
84  }
85  }
86  }
87  }
88 
93  public static function generateCode()
94  {
95  // missing : 01iloO
96  $map = "23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
97 
98  $code = "";
99  $max = strlen($map)-1;
100  for($loop = 1; $loop <= self::CODE_LENGTH; $loop++)
101  {
102  $code .= $map[mt_rand(0, $max)];
103  }
104  return $code;
105  }
106 
112  protected static function lookupObjectsByCode($a_code)
113  {
114  include_once './Modules/Group/classes/class.ilObjGroup.php';
115  include_once './Modules/Course/classes/class.ilObjCourse.php';
116 
117  return array_merge(ilObjGroup::lookupObjectsByCode($a_code), ilObjCourse::lookupObjectsByCode($a_code));
118  }
119 }
120 ?>