ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilAccountCode Class Reference

Class ilAccountCode. More...

+ Collaboration diagram for ilAccountCode:

Static Public Member Functions

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

Data Fields

const DB_TABLE = 'usr_account_codes'
 
const CODE_LENGTH = 10
 

Static Protected Member Functions

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

Detailed Description

Class ilAccountCode.

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
Id
class.ilRegistrationSettingsGUI.php 23797 2010-05-07 15:54:03Z jluetzen

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

Member Function Documentation

◆ applyAccessLimits()

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

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

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

Referenced by ilStartUpGUI\processCode().

234  {
235  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
237 
238  if ($code_data["alimit"]) {
239  switch ($code_data["alimit"]) {
240  case "absolute":
241  $end = new ilDateTime($code_data['alimitdt'], IL_CAL_DATE);
242  //$user->setTimeLimitFrom(time());
243  $user->setTimeLimitUntil($end->get(IL_CAL_UNIX));
244  $user->setTimeLimitUnlimited(0);
245  break;
246 
247  case "relative":
248 
249  $rel = unserialize($code_data["alimitdt"]);
250 
251  include_once './Services/Calendar/classes/class.ilDateTime.php';
252  $end = new ilDateTime(time(), IL_CAL_UNIX);
253 
254  if ($rel['y'] > 0) {
255  $end->increment(IL_CAL_YEAR, $rel['y']);
256  }
257 
258  if ($rel['m'] > 0) {
259  $end->increment(IL_CAL_MONTH, $rel['m']);
260  }
261 
262  if ($rel['d'] > 0) {
263  $end->increment(IL_CAL_DAY, $rel['d']);
264  }
265 
266  //$user->setTimeLimitFrom(time());
267  $user->setTimeLimitUntil($end->get(IL_CAL_UNIX));
268  $user->setTimeLimitUnlimited(0);
269  break;
270 
271  case 'unlimited':
272  $user->setTimeLimitUnlimited(1);
273  break;
274 
275  }
276  } else {
277  $user->setTimeLimitUnlimited(1);
278  }
279  }
$code
Definition: example_050.php:99
$end
Definition: saml1-acs.php:18
const IL_CAL_MONTH
const IL_CAL_UNIX
setTimeLimitUnlimited($a_unlimited)
const IL_CAL_DAY
setTimeLimitUntil($a_until)
Date and time handling
const IL_CAL_DATE
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
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,
  $code 
)
static

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

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

Referenced by ilStartUpGUI\processCode().

205  {
206  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
207 
209  if ($grole) {
210  $GLOBALS['rbacadmin']->assignUser($grole, $user->getId());
211  }
213  if ($code_data["role_local"]) {
214  $code_local_roles = explode(";", $code_data["role_local"]);
215  foreach ((array) $code_local_roles as $role_id) {
216  $GLOBALS['rbacadmin']->assignUser($role_id, $user->getId());
217 
218  // patch to remove for 45 due to mantis 21953
219  $role_obj = $GLOBALS['rbacreview']->getObjectOfRole($role_id);
220  switch (ilObject::_lookupType($role_obj)) {
221  case 'crs':
222  case 'grp':
223  $role_refs = ilObject::_getAllReferences($role_obj);
224  $role_ref = end($role_refs);
225  ilObjUser::_addDesktopItem($user->getId(), $role_ref, ilObject::_lookupType($role_obj));
226  break;
227  }
228  }
229  }
230  return true;
231  }
$code
Definition: example_050.php:99
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static _getAllReferences($a_id)
get all reference ids of object
getId()
get object id public
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
static _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par="")
add an item to user's personal desktop
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ create()

static ilAccountCode::create (   $valid_until,
  $stamp 
)
static

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

References $code, $data, $id, $ilDB, and array.

Referenced by ilAccountCodesGUI\createCodes().

19  {
20  global $ilDB;
21 
22  $id = $ilDB->nextId(self::DB_TABLE);
23 
24  // create unique code
25  $found = true;
26  while ($found) {
27  $code = self::generateRandomCode();
28  $chk = $ilDB->queryF("SELECT code_id FROM " . self::DB_TABLE . " WHERE code = %s", array("text"), array($code));
29  $found = (bool) $ilDB->numRows($chk);
30  }
31 
32  $data = array(
33  'code_id' => array('integer', $id),
34  'code' => array('text', $code),
35  'generated' => array('integer', $stamp),
36  'valid_until' => array('text', $valid_until)
37  );
38 
39  $ilDB->insert(self::DB_TABLE, $data);
40  return $id;
41  }
$code
Definition: example_050.php:99
if(!array_key_exists('StateId', $_REQUEST)) $id
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ deleteCodes()

static ilAccountCode::deleteCodes ( array  $ids)
static

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

References $ilDB.

Referenced by ilAccountCodesGUI\deleteCodes().

98  {
99  global $ilDB;
100 
101  if (sizeof($ids)) {
102  return $ilDB->manipulate("DELETE FROM " . self::DB_TABLE . " WHERE " . $ilDB->in("code_id", $ids, false, "integer"));
103  }
104  return false;
105  }
global $ilDB
+ Here is the caller graph for this function:

◆ filterToSQL()

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

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

References $ilDB, and array.

120  {
121  global $ilDB;
122 
123  $where = array();
124  if ($filter_code) {
125  $where[] = $ilDB->like("code", "text", "%" . $filter_code . "%");
126  }
127  if ($filter_valid_until) {
128  $where[] ="valid_until = " . $ilDB->quote($filter_valid_until, "text");
129  }
130  if ($filter_generated) {
131  $where[] ="generated = " . $ilDB->quote($filter_generated, "text");
132  }
133  if (sizeof($where)) {
134  return " WHERE " . implode(" AND ", $where);
135  } else {
136  return "";
137  }
138  }
Create styles array
The data for the language used.
global $ilDB

◆ generateRandomCode()

static ilAccountCode::generateRandomCode ( )
staticprotected

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

References $code.

44  {
45  // missing : 01iloO
46  $map = "23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
47 
48  $code = "";
49  $max = strlen($map)-1;
50  for ($loop = 1; $loop <= self::CODE_LENGTH; $loop++) {
51  $code .= $map[mt_rand(0, $max)];
52  }
53  return $code;
54  }
$code
Definition: example_050.php:99

◆ getCodesData()

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

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

References $ilDB, $result, and array.

Referenced by ilAccountCodesTableGUI\getItems().

57  {
58  global $ilDB;
59 
60  // filter
61  $where = self::filterToSQL($filter_code, $filter_valid_until, $filter_generated);
62 
63  // count query
64  $set = $ilDB->query("SELECT COUNT(*) AS cnt FROM " . self::DB_TABLE . $where);
65  $cnt = 0;
66  if ($rec = $ilDB->fetchAssoc($set)) {
67  $cnt = $rec["cnt"];
68  }
69 
70  $sql = "SELECT * FROM " . self::DB_TABLE . $where;
71  if ($order_field) {
72  $sql .= " ORDER BY " . $order_field . " " . $order_direction;
73  }
74 
75  // set query
76  $ilDB->setLimit((int) $limit, (int) $offset);
77  $set = $ilDB->query($sql);
78  $result = array();
79  while ($rec = $ilDB->fetchAssoc($set)) {
80  $result[] = $rec;
81  }
82  return array("cnt" => $cnt, "set" => $result);
83  }
$result
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ getCodesForExport()

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

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

References $ilDB, $result, and array.

Referenced by ilAccountCodesGUI\exportCodes().

141  {
142  global $ilDB;
143 
144  // filter
145  $where = self::filterToSQL($filter_code, $filter_valid_until, $filter_generated);
146 
147  // set query
148  $set = $ilDB->query("SELECT code FROM " . self::DB_TABLE . $where . " ORDER BY code_id");
149  $result = array();
150  while ($rec = $ilDB->fetchAssoc($set)) {
151  $result[] = $rec["code"];
152  }
153  return $result;
154  }
$result
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ getCodeValidUntil()

static ilAccountCode::getCodeValidUntil (   $code)
static

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

References $code, $ilDB, $row, and ilRegistrationCode\getCodeData().

Referenced by ilStartUpGUI\processCode().

183  {
184  global $ilDB;
185 
186  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
188 
189  if ($code_data["alimit"]) {
190  switch ($code_data["alimit"]) {
191  case "absolute":
192  return $code_data['alimitdt'];
193  }
194  }
195  return "0";
196 
197  $set = $ilDB->query("SELECT valid_until FROM " . self::DB_TABLE . " WHERE code = " . $ilDB->quote($code, "text"));
198  $row = $ilDB->fetchAssoc($set);
199  if (isset($row["valid_until"])) {
200  return $row["valid_until"];
201  }
202  }
$code
Definition: example_050.php:99
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getGenerationDates()

static ilAccountCode::getGenerationDates ( )
static

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

References $ilDB, $result, and array.

Referenced by ilAccountCodesTableGUI\initFilter().

108  {
109  global $ilDB;
110 
111  $set = $ilDB->query("SELECT DISTINCT(generated) AS generated FROM " . self::DB_TABLE . " ORDER BY generated");
112  $result = array();
113  while ($rec = $ilDB->fetchAssoc($set)) {
114  $result[] = $rec["generated"];
115  }
116  return $result;
117  }
$result
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ isUnusedCode()

static ilAccountCode::isUnusedCode (   $code)
static

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

References $code, $ilDB, and ilRegistrationCode\isUnusedCode().

Referenced by ilStartUpGUI\processCode().

157  {
158  global $ilDB;
159 
160  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
162 
163 
164  $set = $ilDB->query("SELECT used FROM " . self::DB_TABLE . " WHERE code = " . $ilDB->quote($code, "text"));
165  $set = $ilDB->fetchAssoc($set);
166  if ($set && !$set["used"]) {
167  return true;
168  }
169  return false;
170  }
$code
Definition: example_050.php:99
global $ilDB
static isUnusedCode($code)
Check if code has been used already type $ilDB.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadCodesByIds()

static ilAccountCode::loadCodesByIds ( array  $ids)
static

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

References $ilDB, $result, and array.

Referenced by ilAccountCodesGUI\deleteConfirmation().

86  {
87  global $ilDB;
88 
89  $set = $ilDB->query("SELECT * FROM " . self::DB_TABLE . " WHERE " . $ilDB->in("code_id", $ids, false, "integer"));
90  $result = array();
91  while ($rec = $ilDB->fetchAssoc($set)) {
92  $result[] = $rec;
93  }
94  return $result;
95  }
$result
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ useCode()

static ilAccountCode::useCode (   $code)
static

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

References $code, $ilDB, array, time, and ilRegistrationCode\useCode().

Referenced by ilStartUpGUI\processCode().

173  {
174  global $ilDB;
175 
176  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
177  return (bool) ilRegistrationCode::useCode($code);
178 
179  return (bool) $ilDB->update(self::DB_TABLE, array("used"=>array("timestamp", time())), array("code"=>array("text", $code)));
180  }
$code
Definition: example_050.php:99
Create styles array
The data for the language used.
global $ilDB
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
+ 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 16 of file class.ilAccountCode.php.

Referenced by ilAccountCodesTableGUI\initFilter().

◆ DB_TABLE

const ilAccountCode::DB_TABLE = 'usr_account_codes'

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


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