ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 case 125://admission link is invalid
49 ilUtil::sendFailure($lng->txt($a_type."_admission_link_failure_invalid_code"), true);
50 break;
51 default:
52 ilUtil::sendFailure($e->getMessage(), true);
53 break;
54 }
55 $GLOBALS['ilLog']->logStack();
56 $GLOBALS['ilLog']->write($e->getCode().': '.$e->getMessage());
57
58 $parent_id = $tree->getParentId($a_ref_id);
60 }
61 }
62
63
64
75 protected static function useCode($a_code,$a_endnode)
76 {
77 global $tree,$ilUser;
78
79 $obj_ids = self::lookupObjectsByCode($a_code);
80
81 if(!$obj_ids)
82 {
83 include_once './Services/Membership/exceptions/class.ilMembershipRegistrationException.php';
84 throw new ilMembershipRegistrationException('Admission code is not valid', '125');
85 }
86
87 foreach($tree->getPathId($a_endnode) as $ref_id)
88 {
89 if(in_array(ilObject::_lookupObjId($ref_id), $obj_ids))
90 {
92 {
93 $obj->register($ilUser->getId());
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 {
112 $code .= $map[mt_rand(0, $max)];
113 }
114 return $code;
115 }
116
122 protected static function lookupObjectsByCode($a_code)
123 {
124 include_once './Modules/Group/classes/class.ilObjGroup.php';
125 include_once './Modules/Course/classes/class.ilObjCourse.php';
126
127 return array_merge(ilObjGroup::lookupObjectsByCode($a_code), ilObjCourse::lookupObjectsByCode($a_code));
128 }
129}
130?>
Stores registration keys for key based registration on courses and groups.
static handleCode($a_ref_id, $a_type, $a_code)
Handle target parameter.
static generateCode()
Generate new registration key.
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...
static lookupObjectsByCode($a_code)
static lookupObjectsByCode($a_code)
getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _lookupObjectId($a_ref_id)
lookup object id
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static redirect($a_script)
http redirect to other script
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$code
Definition: example_050.php:99
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
global $lng
Definition: privfeed.php:40
$ref_id
Definition: sahs_server.php:39
global $ilUser
Definition: imgupload.php:15