ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 getCodesData (string $order_field, string $order_direction, int $offset, int $limit, string $filter_code, int $filter_role, string $filter_generated, string $filter_access_limitation)
 
static loadCodesByIds (array $ids)
 
static deleteCodes (array $ids)
 
static getGenerationDates ()
 
static getCodesForExport (string $filter_code, ?int $filter_role, string $filter_generated, string $filter_access_limitation)
 
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'
 

Static Private Member Functions

static filterToSQL (string $filter_code, ?int $filter_role, string $filter_generated, string $filter_access_limitation)
 

Detailed Description

Member Function Documentation

◆ applyAccessLimits()

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

Definition at line 355 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().

358  : void {
359  $code_data = self::getCodeData($code);
360 
361  if ($code_data["alimit"]) {
362  switch ($code_data["alimit"]) {
363  case "absolute":
364  $end = new ilDateTime($code_data['alimitdt'], IL_CAL_DATE);
365  //$user->setTimeLimitFrom(time());
366  $user->setTimeLimitUntil($end->get(IL_CAL_UNIX));
367  $user->setTimeLimitUnlimited(false);
368  break;
369 
370  case "relative":
371 
372  $rel = unserialize($code_data["alimitdt"], ["allowed_classes" => false]);
373 
374  $end = new ilDateTime(time(), IL_CAL_UNIX);
375 
376  if ($rel['y'] > 0) {
377  $end->increment(IL_CAL_YEAR, (int) $rel['y']);
378  }
379 
380  if ($rel['m'] > 0) {
381  $end->increment(IL_CAL_MONTH, (int) $rel['m']);
382  }
383 
384  if ($rel['d'] > 0) {
385  $end->increment(IL_CAL_DAY, (int) $rel['d']);
386  }
387 
388  //$user->setTimeLimitFrom(time());
389  $user->setTimeLimitUntil($end->get(IL_CAL_UNIX));
390  $user->setTimeLimitUnlimited(false);
391  break;
392 
393  case 'unlimited':
394  $user->setTimeLimitUnlimited(true);
395  break;
396  }
397  } else {
398  $user->setTimeLimitUnlimited(true);
399  }
400  }
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 322 of file class.ilRegistrationCode.php.

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

Referenced by ilStartUpGUI\processCode().

325  : bool {
326  $recommended_content_manager = new ilRecommendedContentManager();
327 
328  $grole = self::getCodeRole($code);
329  if ($grole) {
330  $GLOBALS['DIC']['rbacadmin']->assignUser($grole, $user->getId());
331  }
332  $code_data = self::getCodeData($code);
333  if ($code_data["role_local"]) {
334  $code_local_roles = explode(";", $code_data["role_local"]);
335  foreach ($code_local_roles as $role_id) {
336  $GLOBALS['DIC']['rbacadmin']->assignUser($role_id, $user->getId());
337 
338  // patch to remove for 45 due to mantis 21953
339  $role_obj = $GLOBALS['DIC']['rbacreview']->getObjectOfRole($role_id);
340  switch (ilObject::_lookupType($role_obj)) {
341  case 'crs':
342  case 'grp':
343  $role_refs = ilObject::_getAllReferences($role_obj);
344  $role_ref = end($role_refs);
345  // deactivated for now, see discussion at
346  // https://docu.ilias.de/goto_docu_wiki_wpage_5620_1357.html
347  //$recommended_content_manager->addObjectRecommendation($user->getId(), $role_ref);
348  break;
349  }
350  }
351  }
352  return true;
353  }
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:22
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the caller graph for this function:

◆ deleteCodes()

static ilRegistrationCode::deleteCodes ( array  $ids)
static

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

References $DIC, and $ilDB.

Referenced by ilRegistrationSettingsGUI\deleteCodes().

149  : bool
150  {
151  global $DIC;
152 
153  $ilDB = $DIC->database();
154  if (count($ids)) {
155  return (bool) $ilDB->manipulate("DELETE FROM " . self::DB_TABLE . " WHERE " . $ilDB->in(
156  "code_id",
157  $ids,
158  false,
159  "integer"
160  ));
161  }
162  return false;
163  }
global $DIC
Definition: shib_login.php:22
+ Here is the caller graph for this function:

◆ filterToSQL()

static ilRegistrationCode::filterToSQL ( string  $filter_code,
?int  $filter_role,
string  $filter_generated,
string  $filter_access_limitation 
)
staticprivate

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

References $DIC, and $ilDB.

184  : string {
185  global $DIC;
186 
187  $ilDB = $DIC['ilDB'];
188 
189  $where = [];
190  if ($filter_code) {
191  $where[] = $ilDB->like("code", "text", "%" . $filter_code . "%");
192  }
193  if ($filter_role) {
194  $where[] = "role = " . $ilDB->quote($filter_role, "integer");
195  }
196  if ($filter_generated) {
197  $where[] = "generated_on = " . $ilDB->quote($filter_generated, "text");
198  }
199  if ($filter_access_limitation) {
200  $where[] = "alimit = " . $ilDB->quote($filter_access_limitation, "text");
201  }
202  if (count($where)) {
203  return " WHERE " . implode(" AND ", $where);
204  }
205 
206  return "";
207  }
global $DIC
Definition: shib_login.php:22

◆ 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 311 of file class.ilRegistrationCode.php.

References $DIC, and $ilDB.

Referenced by ilAccountRegistrationGUI\createUser().

311  : array
312  {
313  global $DIC;
314 
315  $ilDB = $DIC->database();
316  $set = $ilDB->query("SELECT role, role_local, alimit, alimitdt, reg_enabled, ext_enabled" .
317  " FROM " . self::DB_TABLE .
318  " WHERE code = " . $ilDB->quote($code, "text"));
319  return $ilDB->fetchAssoc($set);
320  }
global $DIC
Definition: shib_login.php:22
+ Here is the caller graph for this function:

◆ getCodeRole()

static ilRegistrationCode::getCodeRole ( string  $code)
static

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

References $DIC, and $ilDB.

Referenced by ilAccountRegistrationGUI\saveForm().

298  : int
299  {
300  global $DIC;
301 
302  $ilDB = $DIC->database();
303  $set = $ilDB->query("SELECT role FROM " . self::DB_TABLE . " WHERE code = " . $ilDB->quote($code, "text"));
304  $row = $ilDB->fetchAssoc($set);
305  if (isset($row["role"])) {
306  return (int) $row["role"];
307  }
308  return 0;
309  }
global $DIC
Definition: shib_login.php:22
+ Here is the caller graph for this function:

◆ getCodesData()

static ilRegistrationCode::getCodesData ( string  $order_field,
string  $order_direction,
int  $offset,
int  $limit,
string  $filter_code,
int  $filter_role,
string  $filter_generated,
string  $filter_access_limitation 
)
static

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

References $DIC, and $ilDB.

Referenced by ilRegistrationCodesTableGUI\getItems().

96  : array {
97  global $DIC;
98 
99  $ilDB = $DIC->database();
100 
101  // filter
102  $where = self::filterToSQL($filter_code, $filter_role, $filter_generated, $filter_access_limitation);
103 
104  // count query
105  $set = $ilDB->query("SELECT COUNT(*) AS cnt FROM " . self::DB_TABLE . $where);
106  $cnt = 0;
107  if ($rec = $ilDB->fetchAssoc($set)) {
108  $cnt = $rec["cnt"];
109  }
110 
111  $sql = "SELECT * FROM " . self::DB_TABLE . $where;
112  if ($order_field) {
113  if ($order_field === 'generated') {
114  $order_field = 'generated_on';
115  }
116  $sql .= " ORDER BY " . $order_field . " " . $order_direction;
117  }
118 
119  // set query
120  $ilDB->setLimit($limit, $offset);
121  $set = $ilDB->query($sql);
122  $result = [];
123  while ($rec = $ilDB->fetchAssoc($set)) {
124  $rec['generated'] = $rec['generated_on'];
125  $result[] = $rec;
126  }
127  return ["cnt" => $cnt, "set" => $result];
128  }
global $DIC
Definition: shib_login.php:22
+ Here is the caller graph for this function:

◆ getCodesForExport()

static ilRegistrationCode::getCodesForExport ( string  $filter_code,
?int  $filter_role,
string  $filter_generated,
string  $filter_access_limitation 
)
static

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

References $DIC, and $ilDB.

Referenced by ilRegistrationSettingsGUI\exportCodes().

214  : array {
215  global $DIC;
216 
217  $ilDB = $DIC->database();
218 
219  // filter
220  $where = self::filterToSQL($filter_code, $filter_role, $filter_generated, $filter_access_limitation);
221 
222  // set query
223  $set = $ilDB->query("SELECT code FROM " . self::DB_TABLE . $where . " ORDER BY code_id");
224  $result = [];
225  while ($rec = $ilDB->fetchAssoc($set)) {
226  $result[] = $rec["code"];
227  }
228  return $result;
229  }
global $DIC
Definition: shib_login.php:22
+ Here is the caller graph for this function:

◆ getCodeValidUntil()

static ilRegistrationCode::getCodeValidUntil ( string  $code)
static

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

Referenced by ilStartUpGUI\processCode().

273  : string
274  {
275  $code_data = self::getCodeData($code);
276 
277  if ($code_data["alimit"]) {
278  switch ($code_data["alimit"]) {
279  case "absolute":
280  return $code_data['alimitdt'];
281  }
282  }
283  return "0";
284  }
+ Here is the caller graph for this function:

◆ getGenerationDates()

static ilRegistrationCode::getGenerationDates ( )
static

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

References $DIC, and $ilDB.

Referenced by ilRegistrationCodesTableGUI\initFilter().

165  : array
166  {
167  global $DIC;
168 
169  $ilDB = $DIC->database();
170 
171  $set = $ilDB->query("SELECT DISTINCT(generated_on) genr FROM " . self::DB_TABLE . " ORDER BY genr");
172  $result = [];
173  while ($rec = $ilDB->fetchAssoc($set)) {
174  $result[] = $rec["genr"];
175  }
176  return $result;
177  }
global $DIC
Definition: shib_login.php:22
+ Here is the caller graph for this function:

◆ isUnusedCode()

static ilRegistrationCode::isUnusedCode ( string  $code)
static

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

References $DIC, and $ilDB.

Referenced by ilStartUpGUI\processCode().

231  : bool
232  {
233  global $DIC;
234 
235  $ilDB = $DIC['ilDB'];
236 
237  $set = $ilDB->query("SELECT used FROM " . self::DB_TABLE . " WHERE code = " . $ilDB->quote($code, "text"));
238  $set = $ilDB->fetchAssoc($set);
239  return $set && !$set["used"];
240  }
global $DIC
Definition: shib_login.php:22
+ Here is the caller graph for this function:

◆ isValidRegistrationCode()

static ilRegistrationCode::isValidRegistrationCode ( string  $a_code)
static

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

References $DIC, $ilDB, and $res.

Referenced by ilAccountRegistrationGUI\saveForm().

242  : bool
243  {
244  global $DIC;
245 
246  $ilDB = $DIC->database();
247 
248  $query = 'SELECT alimit, alimitdt FROM reg_registration_codes ' .
249  'WHERE used = ' . $ilDB->quote(0, 'integer') . ' ' .
250  'AND reg_enabled = ' . $ilDB->quote(1, 'integer') . ' ' .
251  'AND code = ' . $ilDB->quote($a_code, 'text');
252  $res = $ilDB->query($query);
253  if ($ilDB->numRows($res) !== 1) {
254  return false;
255  }
256 
257  $is_valid = true;
258 
259  $row = $ilDB->fetchAssoc($res);
260  if ($row['alimit'] === 'absolute') {
261  $clock_factory = (new \ILIAS\Data\Factory())->clock();
262  $right_interval = new DateTimeImmutable(
263  $row['alimitdt'],
264  $clock_factory->system()->now()->getTimezone()
265  );
266 
267  $is_valid = $right_interval >= $clock_factory->system()->now();
268  }
269 
270  return $is_valid;
271  }
$res
Definition: ltiservices.php:66
global $DIC
Definition: shib_login.php:22
+ Here is the caller graph for this function:

◆ loadCodesByIds()

static ilRegistrationCode::loadCodesByIds ( array  $ids)
static

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

References $DIC, and $ilDB.

Referenced by ilRegistrationSettingsGUI\deleteConfirmation().

130  : array
131  {
132  global $DIC;
133 
134  $ilDB = $DIC->database();
135 
136  $set = $ilDB->query("SELECT * FROM " . self::DB_TABLE . " WHERE " . $ilDB->in(
137  "code_id",
138  $ids,
139  false,
140  "integer"
141  ));
142  $result = [];
143  while ($rec = $ilDB->fetchAssoc($set)) {
144  $result[] = $rec;
145  }
146  return $result;
147  }
global $DIC
Definition: shib_login.php:22
+ Here is the caller graph for this function:

◆ useCode()

static ilRegistrationCode::useCode ( string  $code)
static

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

References $DIC, and $ilDB.

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

286  : bool
287  {
288  global $DIC;
289 
290  $ilDB = $DIC->database();
291  return (bool) $ilDB->update(
292  self::DB_TABLE,
293  ["used" => ["timestamp", time()]],
294  ["code" => ["text", $code]]
295  );
296  }
global $DIC
Definition: shib_login.php:22
+ 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: