ILIAS  Release_4_1_x_branch Revision 61804
 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  include_once './classes/class.ilLink.php';
26  try
27  {
28  self::useCode($a_code,$a_ref_id);
30  }
31  catch(Exception $e)
32  {
33  $GLOBALS['ilLog']->logStack();
34  $GLOBALS['ilLog']->write($e->getMessage());
36  }
37  }
38 
39 
40 
51  protected static function useCode($a_code,$a_endnode)
52  {
53  global $tree,$ilUser;
54 
55  $obj_ids = self::lookupObjectsByCode($a_code);
56  foreach($tree->getPathId($a_endnode) as $ref_id)
57  {
58  if(in_array(ilObject::_lookupObjId($ref_id), $obj_ids))
59  {
61  {
62  $GLOBALS['ilLog']->logStack();
63  $obj->register($ilUser->getId());
64  }
65  }
66  }
67  }
68 
73  public static function generateCode()
74  {
75  // missing : 01iloO
76  $map = "23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
77 
78  $code = "";
79  $max = strlen($map)-1;
80  for($loop = 1; $loop <= self::CODE_LENGTH; $loop++)
81  {
82  $code .= $map[mt_rand(0, $max)];
83  }
84  return $code;
85  }
86 
92  protected static function lookupObjectsByCode($a_code)
93  {
94  include_once './Modules/Group/classes/class.ilObjGroup.php';
95  include_once './Modules/Course/classes/class.ilObjCourse.php';
96 
97  return array_merge(ilObjGroup::lookupObjectsByCode($a_code), ilObjCourse::lookupObjectsByCode($a_code));
98  }
99 }
100 ?>