ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilAccountCode Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilAccountCode:

Static Public Member Functions

static create (string $valid_until, int $stamp)
 
static getCodesData (string $order_field, string $order_direction, int $offset, int $limit, string $filter_code, string $filter_valid_until, string $filter_generated)
 
static loadCodesByIds (array $ids)
 
static deleteCodes (array $ids)
 
static getGenerationDates ()
 
static getCodesForExport (string $filter_code, string $filter_valid_until, string $filter_generated)
 
static isUnusedCode (string $code)
 
static useCode (string $code)
 
static getCodeValidUntil (string $code)
 
static applyRoleAssignments (ilObjUser $user, string $code)
 
static applyAccessLimits (ilObjUser $user, string $code)
 

Data Fields

const DB_TABLE = 'usr_account_codes'
 
const CODE_LENGTH = 10
 

Static Protected Member Functions

static generateRandomCode ()
 
static filterToSQL (string $filter_code, string $filter_valid_until, string $filter_generated)
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 22 of file class.ilAccountCode.php.

Member Function Documentation

◆ applyAccessLimits()

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

Definition at line 259 of file class.ilAccountCode.php.

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

Referenced by ilStartUpGUI\processCode().

262  : void {
263  $code_data = ilRegistrationCode::getCodeData($code);
264 
265  if ($code_data["alimit"]) {
266  switch ($code_data["alimit"]) {
267  case "absolute":
268  $end = new ilDateTime($code_data['alimitdt'], IL_CAL_DATE);
269  //$user->setTimeLimitFrom(time());
270  $user->setTimeLimitUntil($end->get(IL_CAL_UNIX));
271  $user->setTimeLimitUnlimited(0);
272  break;
273 
274  case "relative":
275 
276  $rel = unserialize($code_data["alimitdt"], ["allowed_classes" => false]);
277 
278  $end = new ilDateTime(time(), IL_CAL_UNIX);
279 
280  if ($rel['y'] > 0) {
281  $end->increment(IL_CAL_YEAR, $rel['y']);
282  }
283 
284  if ($rel['m'] > 0) {
285  $end->increment(IL_CAL_MONTH, $rel['m']);
286  }
287 
288  if ($rel['d'] > 0) {
289  $end->increment(IL_CAL_DAY, $rel['d']);
290  }
291 
292  //$user->setTimeLimitFrom(time());
293  $user->setTimeLimitUntil($end->get(IL_CAL_UNIX));
294  $user->setTimeLimitUnlimited(0);
295  break;
296 
297  case 'unlimited':
298  $user->setTimeLimitUnlimited(1);
299  break;
300 
301  }
302  } else {
303  $user->setTimeLimitUnlimited(1);
304  }
305  }
setTimeLimitUnlimited(bool $a_unlimited)
const IL_CAL_MONTH
const IL_CAL_UNIX
setTimeLimitUntil(?int $a_until)
static getCodeData(string $code)
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 ilAccountCode::applyRoleAssignments ( ilObjUser  $user,
string  $code 
)
static

Definition at line 226 of file class.ilAccountCode.php.

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

Referenced by ilStartUpGUI\processCode().

229  : bool {
230  $recommended_content_manager = new ilRecommendedContentManager();
231 
232  $grole = ilRegistrationCode::getCodeRole($code);
233  if ($grole) {
234  $GLOBALS['DIC']['rbacadmin']->assignUser($grole, $user->getId());
235  }
236  $code_data = ilRegistrationCode::getCodeData($code);
237  if ($code_data["role_local"]) {
238  $code_local_roles = explode(";", $code_data["role_local"]);
239  foreach ($code_local_roles as $role_id) {
240  $GLOBALS['DIC']['rbacadmin']->assignUser($role_id, $user->getId());
241 
242  // patch to remove for 45 due to mantis 21953
243  $role_obj = $GLOBALS['DIC']['rbacreview']->getObjectOfRole($role_id);
244  switch (ilObject::_lookupType($role_obj)) {
245  case 'crs':
246  case 'grp':
247  $role_refs = ilObject::_getAllReferences($role_obj);
248  $role_ref = end($role_refs);
249  // deactivated for now, see discussion at
250  // https://docu.ilias.de/goto_docu_wiki_wpage_5620_1357.html
251  //$recommended_content_manager->addObjectRecommendation($user->getId(), $role_ref);
252  break;
253  }
254  }
255  }
256  return true;
257  }
static getCodeRole(string $code)
static _getAllReferences(int $id)
get all reference ids for object ID
static getCodeData(string $code)
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
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 ilAccountCode::create ( string  $valid_until,
int  $stamp 
)
static

Definition at line 27 of file class.ilAccountCode.php.

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

Referenced by ilAccountCodesGUI\createCodes().

30  : int {
31  global $DIC;
32 
33  $ilDB = $DIC['ilDB'];
34  $code = "";
35  $id = $ilDB->nextId(self::DB_TABLE);
36 
37  // create unique code
38  $found = true;
39  while ($found) {
40  $code = self::generateRandomCode();
41  $chk = $ilDB->queryF("SELECT code_id FROM " . self::DB_TABLE . " WHERE code = %s", array("text"), array($code));
42  $found = (bool) $ilDB->numRows($chk);
43  }
44 
45  $data = array(
46  'code_id' => array('integer', $id),
47  'code' => array('text', $code),
48  'generated' => array('integer', $stamp),
49  'valid_until' => array('text', $valid_until)
50  );
51 
52  $ilDB->insert(self::DB_TABLE, $data);
53  return $id;
54  }
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 ilAccountCode::deleteCodes ( array  $ids)
static
Parameters
string[]$ids

Definition at line 127 of file class.ilAccountCode.php.

References $DIC, and $ilDB.

Referenced by ilAccountCodesGUI\deleteCodes().

127  : bool
128  {
129  global $DIC;
130 
131  $ilDB = $DIC['ilDB'];
132 
133  if (count($ids)) {
134  return $ilDB->manipulate("DELETE FROM " . self::DB_TABLE . " WHERE " . $ilDB->in("code_id", $ids, false, "integer"));
135  }
136  return false;
137  }
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ filterToSQL()

static ilAccountCode::filterToSQL ( string  $filter_code,
string  $filter_valid_until,
string  $filter_generated 
)
staticprotected

Definition at line 156 of file class.ilAccountCode.php.

References $DIC, and $ilDB.

160  : string {
161  global $DIC;
162 
163  $ilDB = $DIC['ilDB'];
164 
165  $where = array();
166  if ($filter_code) {
167  $where[] = $ilDB->like("code", "text", "%" . $filter_code . "%");
168  }
169  if ($filter_valid_until) {
170  $where[] = "valid_until = " . $ilDB->quote($filter_valid_until, "text");
171  }
172  if ($filter_generated) {
173  $where[] = "generated = " . $ilDB->quote($filter_generated, "text");
174  }
175  if (count($where)) {
176  return " WHERE " . implode(" AND ", $where);
177  } else {
178  return "";
179  }
180  }
global $DIC
Definition: feed.php:28

◆ generateRandomCode()

static ilAccountCode::generateRandomCode ( )
staticprotected

Definition at line 56 of file class.ilAccountCode.php.

56  : string
57  {
58  // missing : 01iloO
59  $map = "23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
60 
61  $code = "";
62  $max = strlen($map) - 1;
63  for ($loop = 1; $loop <= self::CODE_LENGTH; $loop++) {
64  $code .= $map[random_int(0, $max)];
65  }
66  return $code;
67  }

◆ getCodesData()

static ilAccountCode::getCodesData ( string  $order_field,
string  $order_direction,
int  $offset,
int  $limit,
string  $filter_code,
string  $filter_valid_until,
string  $filter_generated 
)
static

Definition at line 69 of file class.ilAccountCode.php.

References $DIC, and $ilDB.

Referenced by ilAccountCodesTableGUI\getItems().

77  : array {
78  global $DIC;
79 
80  $ilDB = $DIC['ilDB'];
81 
82  // filter
83  $where = self::filterToSQL($filter_code, $filter_valid_until, $filter_generated);
84 
85  // count query
86  $set = $ilDB->query("SELECT COUNT(*) AS cnt FROM " . self::DB_TABLE . $where);
87  $cnt = 0;
88  if ($rec = $ilDB->fetchAssoc($set)) {
89  $cnt = $rec["cnt"];
90  }
91 
92  $sql = "SELECT * FROM " . self::DB_TABLE . $where;
93  if ($order_field) {
94  $sql .= " ORDER BY " . $order_field . " " . $order_direction;
95  }
96 
97  // set query
98  $ilDB->setLimit($limit, $offset);
99  $set = $ilDB->query($sql);
100  $result = array();
101  while ($rec = $ilDB->fetchAssoc($set)) {
102  $result[] = $rec;
103  }
104  return array("cnt" => $cnt, "set" => $result);
105  }
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ getCodesForExport()

static ilAccountCode::getCodesForExport ( string  $filter_code,
string  $filter_valid_until,
string  $filter_generated 
)
static

Definition at line 182 of file class.ilAccountCode.php.

References $DIC, and $ilDB.

Referenced by ilAccountCodesGUI\exportCodes().

186  : array {
187  global $DIC;
188 
189  $ilDB = $DIC['ilDB'];
190 
191  // filter
192  $where = self::filterToSQL($filter_code, $filter_valid_until, $filter_generated);
193 
194  // set query
195  $set = $ilDB->query("SELECT code FROM " . self::DB_TABLE . $where . " ORDER BY code_id");
196  $result = array();
197  while ($rec = $ilDB->fetchAssoc($set)) {
198  $result[] = $rec["code"];
199  }
200  return $result;
201  }
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ getCodeValidUntil()

static ilAccountCode::getCodeValidUntil ( string  $code)
static

Definition at line 213 of file class.ilAccountCode.php.

References ilRegistrationCode\getCodeData().

Referenced by ilStartUpGUI\processCode().

213  : string
214  {
215  $code_data = ilRegistrationCode::getCodeData($code);
216 
217  if ($code_data["alimit"]) {
218  switch ($code_data["alimit"]) {
219  case "absolute":
220  return $code_data['alimitdt'];
221  }
222  }
223  return "0";
224  }
static getCodeData(string $code)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getGenerationDates()

static ilAccountCode::getGenerationDates ( )
static
Returns
string[]

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

References $DIC, and $ilDB.

Referenced by ilAccountCodesTableGUI\initFilter().

142  : array
143  {
144  global $DIC;
145 
146  $ilDB = $DIC['ilDB'];
147 
148  $set = $ilDB->query("SELECT DISTINCT(generated) AS generated FROM " . self::DB_TABLE . " ORDER BY generated");
149  $result = array();
150  while ($rec = $ilDB->fetchAssoc($set)) {
151  $result[] = $rec["generated"];
152  }
153  return $result;
154  }
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ isUnusedCode()

static ilAccountCode::isUnusedCode ( string  $code)
static

Definition at line 203 of file class.ilAccountCode.php.

References ilRegistrationCode\isUnusedCode().

Referenced by ilStartUpGUI\processCode().

203  : bool
204  {
205  return ilRegistrationCode::isUnusedCode($code);
206  }
static isUnusedCode(string $code)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadCodesByIds()

static ilAccountCode::loadCodesByIds ( array  $ids)
static
Returns
array<string,string>[]

Definition at line 110 of file class.ilAccountCode.php.

References $DIC, and $ilDB.

Referenced by ilAccountCodesGUI\deleteConfirmation().

110  : array
111  {
112  global $DIC;
113 
114  $ilDB = $DIC['ilDB'];
115 
116  $set = $ilDB->query("SELECT * FROM " . self::DB_TABLE . " WHERE " . $ilDB->in("code_id", $ids, false, "integer"));
117  $result = array();
118  while ($rec = $ilDB->fetchAssoc($set)) {
119  $result[] = $rec;
120  }
121  return $result;
122  }
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ useCode()

static ilAccountCode::useCode ( string  $code)
static

Definition at line 208 of file class.ilAccountCode.php.

References ilRegistrationCode\useCode().

Referenced by ilStartUpGUI\processCode().

208  : bool
209  {
210  return ilRegistrationCode::useCode($code);
211  }
static useCode(string $code)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ CODE_LENGTH

const ilAccountCode::CODE_LENGTH = 10

Definition at line 25 of file class.ilAccountCode.php.

Referenced by ilAccountCodesTableGUI\initFilter().

◆ DB_TABLE

const ilAccountCode::DB_TABLE = 'usr_account_codes'

Definition at line 24 of file class.ilAccountCode.php.


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