ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 258 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().

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

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

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

Referenced by ilStartUpGUI\processCode().

226  {
227  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
228 
229  $recommended_content_manager = new ilRecommendedContentManager();
230 
231  $grole = ilRegistrationCode::getCodeRole($code);
232  if ($grole) {
233  $GLOBALS['DIC']['rbacadmin']->assignUser($grole, $user->getId());
234  }
235  $code_data = ilRegistrationCode::getCodeData($code);
236  if ($code_data["role_local"]) {
237  $code_local_roles = explode(";", $code_data["role_local"]);
238  foreach ((array) $code_local_roles as $role_id) {
239  $GLOBALS['DIC']['rbacadmin']->assignUser($role_id, $user->getId());
240 
241  // patch to remove for 45 due to mantis 21953
242  $role_obj = $GLOBALS['DIC']['rbacreview']->getObjectOfRole($role_id);
243  switch (ilObject::_lookupType($role_obj)) {
244  case 'crs':
245  case 'grp':
246  $role_refs = ilObject::_getAllReferences($role_obj);
247  $role_ref = end($role_refs);
248  // deactivated for now, see discussion at
249  // https://docu.ilias.de/goto_docu_wiki_wpage_5620_1357.html
250  //$recommended_content_manager->addObjectRecommendation($user->getId(), $role_ref);
251  break;
252  }
253  }
254  }
255  return true;
256  }
static _getAllReferences($a_id)
get all reference ids of object
getId()
get object id public
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static _lookupType($a_id, $a_reference=false)
lookup object type
Recommended content manager (business logic)
+ 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 19 of file class.ilAccountCode.php.

References $data, $DIC, and $ilDB.

Referenced by ilAccountCodesGUI\createCodes().

20  {
21  global $DIC;
22 
23  $ilDB = $DIC['ilDB'];
24 
25  $id = $ilDB->nextId(self::DB_TABLE);
26 
27  // create unique code
28  $found = true;
29  while ($found) {
30  $code = self::generateRandomCode();
31  $chk = $ilDB->queryF("SELECT code_id FROM " . self::DB_TABLE . " WHERE code = %s", array("text"), array($code));
32  $found = (bool) $ilDB->numRows($chk);
33  }
34 
35  $data = array(
36  'code_id' => array('integer', $id),
37  'code' => array('text', $code),
38  'generated' => array('integer', $stamp),
39  'valid_until' => array('text', $valid_until)
40  );
41 
42  $ilDB->insert(self::DB_TABLE, $data);
43  return $id;
44  }
$data
Definition: storeScorm.php:23
global $ilDB
$DIC
Definition: xapitoken.php:46
+ Here is the caller graph for this function:

◆ deleteCodes()

static ilAccountCode::deleteCodes ( array  $ids)
static

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

References $DIC, and $ilDB.

Referenced by ilAccountCodesGUI\deleteCodes().

105  {
106  global $DIC;
107 
108  $ilDB = $DIC['ilDB'];
109 
110  if (sizeof($ids)) {
111  return $ilDB->manipulate("DELETE FROM " . self::DB_TABLE . " WHERE " . $ilDB->in("code_id", $ids, false, "integer"));
112  }
113  return false;
114  }
global $ilDB
$DIC
Definition: xapitoken.php:46
+ Here is the caller graph for this function:

◆ filterToSQL()

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

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

References $DIC, and $ilDB.

131  {
132  global $DIC;
133 
134  $ilDB = $DIC['ilDB'];
135 
136  $where = array();
137  if ($filter_code) {
138  $where[] = $ilDB->like("code", "text", "%" . $filter_code . "%");
139  }
140  if ($filter_valid_until) {
141  $where[] = "valid_until = " . $ilDB->quote($filter_valid_until, "text");
142  }
143  if ($filter_generated) {
144  $where[] = "generated = " . $ilDB->quote($filter_generated, "text");
145  }
146  if (sizeof($where)) {
147  return " WHERE " . implode(" AND ", $where);
148  } else {
149  return "";
150  }
151  }
global $ilDB
$DIC
Definition: xapitoken.php:46

◆ generateRandomCode()

static ilAccountCode::generateRandomCode ( )
staticprotected

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

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

◆ getCodesData()

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

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

References $DIC, $ilDB, and $result.

Referenced by ilAccountCodesTableGUI\getItems().

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

◆ getCodesForExport()

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

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

References $DIC, $ilDB, and $result.

Referenced by ilAccountCodesGUI\exportCodes().

154  {
155  global $DIC;
156 
157  $ilDB = $DIC['ilDB'];
158 
159  // filter
160  $where = self::filterToSQL($filter_code, $filter_valid_until, $filter_generated);
161 
162  // set query
163  $set = $ilDB->query("SELECT code FROM " . self::DB_TABLE . $where . " ORDER BY code_id");
164  $result = array();
165  while ($rec = $ilDB->fetchAssoc($set)) {
166  $result[] = $rec["code"];
167  }
168  return $result;
169  }
$result
global $ilDB
$DIC
Definition: xapitoken.php:46
+ Here is the caller graph for this function:

◆ getCodeValidUntil()

static ilAccountCode::getCodeValidUntil (   $code)
static

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

References $DIC, $ilDB, and ilRegistrationCode\getCodeData().

Referenced by ilStartUpGUI\processCode().

202  {
203  global $DIC;
204 
205  $ilDB = $DIC['ilDB'];
206 
207  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
208  $code_data = ilRegistrationCode::getCodeData($code);
209 
210  if ($code_data["alimit"]) {
211  switch ($code_data["alimit"]) {
212  case "absolute":
213  return $code_data['alimitdt'];
214  }
215  }
216  return "0";
217 
218  $set = $ilDB->query("SELECT valid_until FROM " . self::DB_TABLE . " WHERE code = " . $ilDB->quote($code, "text"));
219  $row = $ilDB->fetchAssoc($set);
220  if (isset($row["valid_until"])) {
221  return $row["valid_until"];
222  }
223  }
global $ilDB
$DIC
Definition: xapitoken.php:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getGenerationDates()

static ilAccountCode::getGenerationDates ( )
static

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

References $DIC, $ilDB, and $result.

Referenced by ilAccountCodesTableGUI\initFilter().

117  {
118  global $DIC;
119 
120  $ilDB = $DIC['ilDB'];
121 
122  $set = $ilDB->query("SELECT DISTINCT(generated) AS generated FROM " . self::DB_TABLE . " ORDER BY generated");
123  $result = array();
124  while ($rec = $ilDB->fetchAssoc($set)) {
125  $result[] = $rec["generated"];
126  }
127  return $result;
128  }
$result
global $ilDB
$DIC
Definition: xapitoken.php:46
+ Here is the caller graph for this function:

◆ isUnusedCode()

static ilAccountCode::isUnusedCode (   $code)
static

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

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

Referenced by ilStartUpGUI\processCode().

172  {
173  global $DIC;
174 
175  $ilDB = $DIC['ilDB'];
176 
177  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
178  return ilRegistrationCode::isUnusedCode($code);
179 
180 
181  $set = $ilDB->query("SELECT used FROM " . self::DB_TABLE . " WHERE code = " . $ilDB->quote($code, "text"));
182  $set = $ilDB->fetchAssoc($set);
183  if ($set && !$set["used"]) {
184  return true;
185  }
186  return false;
187  }
global $ilDB
$DIC
Definition: xapitoken.php:46
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 90 of file class.ilAccountCode.php.

References $DIC, $ilDB, and $result.

Referenced by ilAccountCodesGUI\deleteConfirmation().

91  {
92  global $DIC;
93 
94  $ilDB = $DIC['ilDB'];
95 
96  $set = $ilDB->query("SELECT * FROM " . self::DB_TABLE . " WHERE " . $ilDB->in("code_id", $ids, false, "integer"));
97  $result = array();
98  while ($rec = $ilDB->fetchAssoc($set)) {
99  $result[] = $rec;
100  }
101  return $result;
102  }
$result
global $ilDB
$DIC
Definition: xapitoken.php:46
+ Here is the caller graph for this function:

◆ useCode()

static ilAccountCode::useCode (   $code)
static

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

References $DIC, $ilDB, and ilRegistrationCode\useCode().

Referenced by ilStartUpGUI\processCode().

190  {
191  global $DIC;
192 
193  $ilDB = $DIC['ilDB'];
194 
195  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
196  return (bool) ilRegistrationCode::useCode($code);
197 
198  return (bool) $ilDB->update(self::DB_TABLE, array("used" => array("timestamp", time())), array("code" => array("text", $code)));
199  }
global $ilDB
$DIC
Definition: xapitoken.php:46
+ 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: