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;
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)) {
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}
$factory
Definition: metadata.php:43
An exception for terminatinating execution or to throw for unit testing.
const IL_GRP_MEMBER
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...
Class ilObjCourse.
static lookupObjectsByCode($a_code)
Class ilObjGroup.
static lookupObjectsByCode($a_code)
Class ilObjectFactory.
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _lookupObjectId($a_ref_id)
lookup object id
static redirect($a_script)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$code
Definition: example_050.php:99
global $DIC
Definition: saml.php:7
$lng
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:92