ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables 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 useCode (string $code)
 
static getCodeRole (string $code)
 
static getCodeData (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

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

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

Referenced by ilRegistrationSettingsGUI\createCodes().

40  : int {
41  global $DIC;
42 
43  $ilDB = $DIC->database();
44  $id = $ilDB->nextId(self::DB_TABLE);
45 
46  // create unique code
47  $found = true;
48  $code = '';
49  while ($found) {
50  $code = self::generateRandomCode();
51  $chk = $ilDB->queryF(
52  "SELECT code_id FROM " . self::DB_TABLE . " WHERE code = %s",
53  ["text"],
54  [$code]
55  );
56  $found = (bool) $ilDB->numRows($chk);
57  }
58 
59  $data = [
60  'code_id' => ['integer', $id],
61  'code' => ['text', $code],
62  'generated_on' => ['integer', $stamp],
63  'role' => ['integer', $role],
64  'role_local' => ['text', implode(";", $local_roles)],
65  'alimit' => ['text', $limit],
66  'alimitdt' => ['text', $limit_date],
67  'reg_enabled' => ['integer', $reg_type],
68  'ext_enabled' => ['integer', $ext_type]
69  ];
70 
71  $ilDB->insert(self::DB_TABLE, $data);
72  return $id;
73  }
global $DIC
Definition: feed.php:28
$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 150 of file class.ilRegistrationCode.php.

References $DIC, and $ilDB.

Referenced by ilRegistrationSettingsGUI\deleteCodes().

150  : bool
151  {
152  global $DIC;
153 
154  $ilDB = $DIC->database();
155  if (count($ids)) {
156  return (bool) $ilDB->manipulate("DELETE FROM " . self::DB_TABLE . " WHERE " . $ilDB->in(
157  "code_id",
158  $ids,
159  false,
160  "integer"
161  ));
162  }
163  return false;
164  }
global $DIC
Definition: feed.php:28
+ 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 180 of file class.ilRegistrationCode.php.

References $DIC, and $ilDB.

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

◆ generateRandomCode()

static ilRegistrationCode::generateRandomCode ( )
staticprotected

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

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

◆ getCodeData()

static ilRegistrationCode::getCodeData ( string  $code)
static

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

References $DIC, and $ilDB.

Referenced by ilAccountCode\applyAccessLimits(), ilAccountCode\applyRoleAssignments(), ilAccountCode\getCodeValidUntil(), and ilAccountRegistrationGUI\saveForm().

299  : array
300  {
301  global $DIC;
302 
303  $ilDB = $DIC->database();
304  $set = $ilDB->query("SELECT role, role_local, alimit, alimitdt, reg_enabled, ext_enabled" .
305  " FROM " . self::DB_TABLE .
306  " WHERE code = " . $ilDB->quote($code, "text"));
307  return $ilDB->fetchAssoc($set);
308  }
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ getCodeRole()

static ilRegistrationCode::getCodeRole ( string  $code)
static

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

References $DIC, and $ilDB.

Referenced by ilAccountCode\applyRoleAssignments(), and ilAccountRegistrationGUI\saveForm().

286  : int
287  {
288  global $DIC;
289 
290  $ilDB = $DIC->database();
291  $set = $ilDB->query("SELECT role FROM " . self::DB_TABLE . " WHERE code = " . $ilDB->quote($code, "text"));
292  $row = $ilDB->fetchAssoc($set);
293  if (isset($row["role"])) {
294  return (int) $row["role"];
295  }
296  return 0;
297  }
global $DIC
Definition: feed.php:28
+ 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 88 of file class.ilRegistrationCode.php.

References $DIC, and $ilDB.

Referenced by ilRegistrationCodesTableGUI\getItems().

97  : array {
98  global $DIC;
99 
100  $ilDB = $DIC->database();
101 
102  // filter
103  $where = self::filterToSQL($filter_code, $filter_role, $filter_generated, $filter_access_limitation);
104 
105  // count query
106  $set = $ilDB->query("SELECT COUNT(*) AS cnt FROM " . self::DB_TABLE . $where);
107  $cnt = 0;
108  if ($rec = $ilDB->fetchAssoc($set)) {
109  $cnt = $rec["cnt"];
110  }
111 
112  $sql = "SELECT * FROM " . self::DB_TABLE . $where;
113  if ($order_field) {
114  if ($order_field === 'generated') {
115  $order_field = 'generated_on';
116  }
117  $sql .= " ORDER BY " . $order_field . " " . $order_direction;
118  }
119 
120  // set query
121  $ilDB->setLimit($limit, $offset);
122  $set = $ilDB->query($sql);
123  $result = [];
124  while ($rec = $ilDB->fetchAssoc($set)) {
125  $rec['generated'] = $rec['generated_on'];
126  $result[] = $rec;
127  }
128  return ["cnt" => $cnt, "set" => $result];
129  }
global $DIC
Definition: feed.php:28
+ 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 210 of file class.ilRegistrationCode.php.

References $DIC, and $ilDB.

Referenced by ilRegistrationSettingsGUI\exportCodes().

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

◆ getGenerationDates()

static ilRegistrationCode::getGenerationDates ( )
static

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

References $DIC, and $ilDB.

Referenced by ilRegistrationCodesTableGUI\initFilter().

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

◆ isUnusedCode()

static ilRegistrationCode::isUnusedCode ( string  $code)
static

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

References $DIC, and $ilDB.

Referenced by ilAccountCode\isUnusedCode().

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

◆ isValidRegistrationCode()

static ilRegistrationCode::isValidRegistrationCode ( string  $a_code)
static

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

References $DIC, $ilDB, $query, and $res.

Referenced by ilAccountRegistrationGUI\saveForm().

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

◆ loadCodesByIds()

static ilRegistrationCode::loadCodesByIds ( array  $ids)
static

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

References $DIC, and $ilDB.

Referenced by ilRegistrationSettingsGUI\deleteConfirmation().

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

◆ useCode()

static ilRegistrationCode::useCode ( string  $code)
static

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

References $DIC, and $ilDB.

Referenced by ilAccountRegistrationGUI\saveForm(), and ilAccountCode\useCode().

274  : bool
275  {
276  global $DIC;
277 
278  $ilDB = $DIC->database();
279  return (bool) $ilDB->update(
280  self::DB_TABLE,
281  ["used" => ["timestamp", time()]],
282  ["code" => ["text", $code]]
283  );
284  }
global $DIC
Definition: feed.php:28
+ 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 29 of file class.ilRegistrationCode.php.


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