ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilRegistrationCode Class Reference

Class ilRegistrationCode. More...

+ Collaboration diagram for ilRegistrationCode:

Static Public Member Functions

static create (int $role, int $stamp, array $local_roles, ?string $limit, ?string $limit_date, bool $reg_type, bool $ext_type)
 
static isUnusedCode (string $code)
 
static isValidRegistrationCode (string $a_code)
 
static getCodeValidUntil (string $code)
 
static useCode (string $code)
 
static getCodeRole (string $code)
 
static getCodeData (string $code)
 
static applyRoleAssignments (ilObjUser $user, string $code)
 
static applyAccessLimits (ilObjUser $user, string $code)
 

Data Fields

const CODE_LENGTH = 10
 

Static Protected Member Functions

static generateRandomCode ()
 

Protected Attributes

const DB_TABLE = 'reg_registration_codes'
 

Detailed Description

Member Function Documentation

◆ applyAccessLimits()

static ilRegistrationCode::applyAccessLimits ( ilObjUser  $user,
string  $code 
)
static

Definition at line 211 of file class.ilRegistrationCode.php.

References IL_CAL_DATE, IL_CAL_DAY, IL_CAL_MONTH, IL_CAL_UNIX, IL_CAL_YEAR, ilObjUser\setTimeLimitUnlimited(), and ilObjUser\setTimeLimitUntil().

Referenced by ilStartUpGUI\processCode().

214  : void {
215  $code_data = self::getCodeData($code);
216 
217  if ($code_data["alimit"]) {
218  switch ($code_data["alimit"]) {
219  case "absolute":
220  $end = new ilDateTime($code_data['alimitdt'], IL_CAL_DATE);
221  //$user->setTimeLimitFrom(time());
222  $user->setTimeLimitUntil($end->get(IL_CAL_UNIX));
223  $user->setTimeLimitUnlimited(false);
224  break;
225 
226  case "relative":
227 
228  $rel = unserialize($code_data["alimitdt"], ["allowed_classes" => false]);
229 
230  $end = new ilDateTime(time(), IL_CAL_UNIX);
231 
232  if ($rel['y'] > 0) {
233  $end->increment(IL_CAL_YEAR, (int) $rel['y']);
234  }
235 
236  if ($rel['m'] > 0) {
237  $end->increment(IL_CAL_MONTH, (int) $rel['m']);
238  }
239 
240  if ($rel['d'] > 0) {
241  $end->increment(IL_CAL_DAY, (int) $rel['d']);
242  }
243 
244  //$user->setTimeLimitFrom(time());
245  $user->setTimeLimitUntil($end->get(IL_CAL_UNIX));
246  $user->setTimeLimitUnlimited(false);
247  break;
248 
249  case 'unlimited':
250  $user->setTimeLimitUnlimited(true);
251  break;
252  }
253  } else {
254  $user->setTimeLimitUnlimited(true);
255  }
256  }
setTimeLimitUnlimited(bool $a_unlimited)
const IL_CAL_MONTH
const IL_CAL_UNIX
setTimeLimitUntil(?int $a_until)
const IL_CAL_DAY
const IL_CAL_DATE
const IL_CAL_YEAR
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ applyRoleAssignments()

static ilRegistrationCode::applyRoleAssignments ( ilObjUser  $user,
string  $code 
)
static

Definition at line 178 of file class.ilRegistrationCode.php.

References $GLOBALS, ilObject\_getAllReferences(), ilObject\_lookupType(), and ilObject\getId().

Referenced by ilStartUpGUI\processCode().

181  : bool {
182  $recommended_content_manager = new ilRecommendedContentManager();
183 
184  $grole = self::getCodeRole($code);
185  if ($grole) {
186  $GLOBALS['DIC']['rbacadmin']->assignUser($grole, $user->getId());
187  }
188  $code_data = self::getCodeData($code);
189  if ($code_data["role_local"]) {
190  $code_local_roles = explode(";", $code_data["role_local"]);
191  foreach ($code_local_roles as $role_id) {
192  $GLOBALS['DIC']['rbacadmin']->assignUser($role_id, $user->getId());
193 
194  // patch to remove for 45 due to mantis 21953
195  $role_obj = $GLOBALS['DIC']['rbacreview']->getObjectOfRole($role_id);
196  switch (ilObject::_lookupType($role_obj)) {
197  case 'crs':
198  case 'grp':
199  $role_refs = ilObject::_getAllReferences($role_obj);
200  $role_ref = end($role_refs);
201  // deactivated for now, see discussion at
202  // https://docu.ilias.de/goto_docu_wiki_wpage_5620_1357.html
203  //$recommended_content_manager->addObjectRecommendation($user->getId(), $role_ref);
204  break;
205  }
206  }
207  }
208  return true;
209  }
static _getAllReferences(int $id)
get all reference ids for object ID
$GLOBALS["DIC"]
Definition: wac.php:53
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ create()

static ilRegistrationCode::create ( int  $role,
int  $stamp,
array  $local_roles,
?string  $limit,
?string  $limit_date,
bool  $reg_type,
bool  $ext_type 
)
static

Definition at line 31 of file class.ilRegistrationCode.php.

References $data, $DIC, $id, and $ilDB.

Referenced by ilRegistrationSettingsGUI\createCodes().

39  : int {
40  global $DIC;
41 
42  $ilDB = $DIC->database();
43  $id = $ilDB->nextId(self::DB_TABLE);
44 
45  // create unique code
46  $found = true;
47  $code = '';
48  while ($found) {
49  $code = self::generateRandomCode();
50  $chk = $ilDB->queryF(
51  "SELECT code_id FROM " . self::DB_TABLE . " WHERE code = %s",
52  ["text"],
53  [$code]
54  );
55  $found = (bool) $ilDB->numRows($chk);
56  }
57 
58  $data = [
59  'code_id' => ['integer', $id],
60  'code' => ['text', $code],
61  'generated_on' => ['integer', $stamp],
62  'role' => ['integer', $role],
63  'role_local' => ['text', implode(";", $local_roles)],
64  'alimit' => ['text', $limit],
65  'alimitdt' => ['text', $limit_date],
66  'reg_enabled' => ['integer', $reg_type],
67  'ext_enabled' => ['integer', $ext_type]
68  ];
69 
70  $ilDB->insert(self::DB_TABLE, $data);
71  return $id;
72  }
global $DIC
Definition: shib_login.php:26
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the caller graph for this function:

◆ generateRandomCode()

static ilRegistrationCode::generateRandomCode ( )
staticprotected

Definition at line 74 of file class.ilRegistrationCode.php.

74  : string
75  {
76  // missing : 01iloO
77  $map = "23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
78 
79  $code = "";
80  $max = strlen($map) - 1;
81  for ($loop = 1; $loop <= self::CODE_LENGTH; $loop++) {
82  $code .= $map[random_int(0, $max)];
83  }
84  return $code;
85  }

◆ getCodeData()

static ilRegistrationCode::getCodeData ( string  $code)
static

Definition at line 167 of file class.ilRegistrationCode.php.

References $DIC, and $ilDB.

Referenced by ilAccountRegistrationGUI\createUser().

167  : array
168  {
169  global $DIC;
170 
171  $ilDB = $DIC->database();
172  $set = $ilDB->query("SELECT role, role_local, alimit, alimitdt, reg_enabled, ext_enabled" .
173  " FROM " . self::DB_TABLE .
174  " WHERE code = " . $ilDB->quote($code, "text"));
175  return $ilDB->fetchAssoc($set);
176  }
global $DIC
Definition: shib_login.php:26
+ Here is the caller graph for this function:

◆ getCodeRole()

static ilRegistrationCode::getCodeRole ( string  $code)
static

Definition at line 154 of file class.ilRegistrationCode.php.

References $DIC, and $ilDB.

Referenced by ilAccountRegistrationGUI\saveForm().

154  : int
155  {
156  global $DIC;
157 
158  $ilDB = $DIC->database();
159  $set = $ilDB->query("SELECT role FROM " . self::DB_TABLE . " WHERE code = " . $ilDB->quote($code, "text"));
160  $row = $ilDB->fetchAssoc($set);
161  if (isset($row["role"])) {
162  return (int) $row["role"];
163  }
164  return 0;
165  }
global $DIC
Definition: shib_login.php:26
+ Here is the caller graph for this function:

◆ getCodeValidUntil()

static ilRegistrationCode::getCodeValidUntil ( string  $code)
static

Definition at line 129 of file class.ilRegistrationCode.php.

Referenced by ilStartUpGUI\processCode().

129  : string
130  {
131  $code_data = self::getCodeData($code);
132 
133  if ($code_data["alimit"]) {
134  switch ($code_data["alimit"]) {
135  case "absolute":
136  return $code_data['alimitdt'];
137  }
138  }
139  return "0";
140  }
+ Here is the caller graph for this function:

◆ isUnusedCode()

static ilRegistrationCode::isUnusedCode ( string  $code)
static

Definition at line 87 of file class.ilRegistrationCode.php.

References $DIC, and $ilDB.

Referenced by ilStartUpGUI\processCode().

87  : bool
88  {
89  global $DIC;
90 
91  $ilDB = $DIC['ilDB'];
92 
93  $set = $ilDB->query("SELECT used FROM " . self::DB_TABLE . " WHERE code = " . $ilDB->quote($code, "text"));
94  $set = $ilDB->fetchAssoc($set);
95  return $set && !$set["used"];
96  }
global $DIC
Definition: shib_login.php:26
+ Here is the caller graph for this function:

◆ isValidRegistrationCode()

static ilRegistrationCode::isValidRegistrationCode ( string  $a_code)
static

Definition at line 98 of file class.ilRegistrationCode.php.

References $DIC, $ilDB, and $res.

Referenced by ilAccountRegistrationGUI\saveForm().

98  : bool
99  {
100  global $DIC;
101 
102  $ilDB = $DIC->database();
103 
104  $query = 'SELECT alimit, alimitdt FROM reg_registration_codes ' .
105  'WHERE used = ' . $ilDB->quote(0, 'integer') . ' ' .
106  'AND reg_enabled = ' . $ilDB->quote(1, 'integer') . ' ' .
107  'AND code = ' . $ilDB->quote($a_code, 'text');
108  $res = $ilDB->query($query);
109  if ($ilDB->numRows($res) !== 1) {
110  return false;
111  }
112 
113  $is_valid = true;
114 
115  $row = $ilDB->fetchAssoc($res);
116  if ($row['alimit'] === 'absolute') {
117  $clock_factory = (new \ILIAS\Data\Factory())->clock();
118  $right_interval = new DateTimeImmutable(
119  $row['alimitdt'],
120  $clock_factory->system()->now()->getTimezone()
121  );
122 
123  $is_valid = $right_interval >= $clock_factory->system()->now();
124  }
125 
126  return $is_valid;
127  }
$res
Definition: ltiservices.php:66
global $DIC
Definition: shib_login.php:26
+ Here is the caller graph for this function:

◆ useCode()

static ilRegistrationCode::useCode ( string  $code)
static

Definition at line 142 of file class.ilRegistrationCode.php.

References $DIC, and $ilDB.

Referenced by ilAccountRegistrationGUI\createUser(), and ilStartUpGUI\processCode().

142  : bool
143  {
144  global $DIC;
145 
146  $ilDB = $DIC->database();
147  return (bool) $ilDB->update(
148  self::DB_TABLE,
149  ["used" => ["timestamp", time()]],
150  ["code" => ["text", $code]]
151  );
152  }
global $DIC
Definition: shib_login.php:26
+ Here is the caller graph for this function:

Field Documentation

◆ CODE_LENGTH

const ilRegistrationCode::CODE_LENGTH = 10

◆ DB_TABLE

const ilRegistrationCode::DB_TABLE = 'reg_registration_codes'
protected

Definition at line 28 of file class.ilRegistrationCode.php.


The documentation for this class was generated from the following file: