ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 256 of file class.ilAccountCode.php.

References $code, 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().

257  {
258  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
260 
261  if($code_data["alimit"])
262  {
263  switch($code_data["alimit"])
264  {
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  {
281  $end->increment(IL_CAL_YEAR, $rel['y']);
282  }
283 
284  if($rel['m'] > 0)
285  {
286  $end->increment(IL_CAL_MONTH, $rel['m']);
287  }
288 
289  if($rel['d'] > 0)
290  {
291  $end->increment(IL_CAL_DAY, $rel['d']);
292  }
293 
294  //$user->setTimeLimitFrom(time());
295  $user->setTimeLimitUntil($end->get(IL_CAL_UNIX));
296  $user->setTimeLimitUnlimited(0);
297  break;
298 
299  case 'unlimited':
300  $user->setTimeLimitUnlimited(1);
301  break;
302 
303  }
304  }
305  else
306  {
307  $user->setTimeLimitUnlimited(1);
308  }
309 
310  }
$code
Definition: example_050.php:99
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 223 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().

224  {
225  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
226 
228  if($grole)
229  {
230  $GLOBALS['rbacadmin']->assignUser($grole,$user->getId());
231  }
233  if($code_data["role_local"])
234  {
235  $code_local_roles = explode(";", $code_data["role_local"]);
236  foreach((array) $code_local_roles as $role_id)
237  {
238  $GLOBALS['rbacadmin']->assignUser($role_id,$user->getId());
239 
240  // patch to remove for 45 due to mantis 21953
241  $role_obj = $GLOBALS['rbacreview']->getObjectOfRole($role_id);
242  switch(ilObject::_lookupType($role_obj))
243  {
244  case 'crs':
245  case 'grp':
246  $role_refs = ilObject::_getAllReferences($role_obj);
247  $role_ref = end($role_refs);
248  ilObjUser::_addDesktopItem($user->getId(),$role_ref,ilObject::_lookupType($role_obj));
249  break;
250  }
251  }
252  }
253  return true;
254  }
$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, $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  {
28  $code = self::generateRandomCode();
29  $chk = $ilDB->queryF("SELECT code_id FROM ".self::DB_TABLE." WHERE code = %s", array("text"), array($code));
30  $found = (bool)$ilDB->numRows($chk);
31  }
32 
33  $data = array(
34  'code_id' => array('integer', $id),
35  'code' => array('text', $code),
36  'generated' => array('integer', $stamp),
37  'valid_until' => array('text', $valid_until)
38  );
39 
40  $ilDB->insert(self::DB_TABLE, $data);
41  return $id;
42  }
$code
Definition: example_050.php:99
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 103 of file class.ilAccountCode.php.

References $ilDB.

Referenced by ilAccountCodesGUI\deleteCodes().

104  {
105  global $ilDB;
106 
107  if(sizeof($ids))
108  {
109  return $ilDB->manipulate("DELETE FROM ".self::DB_TABLE." WHERE ".$ilDB->in("code_id", $ids, false, "integer"));
110  }
111  return false;
112  }
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 127 of file class.ilAccountCode.php.

References $ilDB, and array.

128  {
129  global $ilDB;
130 
131  $where = array();
132  if($filter_code)
133  {
134  $where[] = $ilDB->like("code", "text", "%".$filter_code."%");
135  }
136  if($filter_valid_until)
137  {
138  $where[] ="valid_until = ".$ilDB->quote($filter_valid_until, "text");
139  }
140  if($filter_generated)
141  {
142  $where[] ="generated = ".$ilDB->quote($filter_generated, "text");
143  }
144  if(sizeof($where))
145  {
146  return " WHERE ".implode(" AND ", $where);
147  }
148  else
149  {
150  return "";
151  }
152  }
Create styles array
The data for the language used.
global $ilDB

◆ generateRandomCode()

static ilAccountCode::generateRandomCode ( )
staticprotected

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

References $code.

45  {
46  // missing : 01iloO
47  $map = "23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
48 
49  $code = "";
50  $max = strlen($map)-1;
51  for($loop = 1; $loop <= self::CODE_LENGTH; $loop++)
52  {
53  $code .= $map[mt_rand(0, $max)];
54  }
55  return $code;
56  }
$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 58 of file class.ilAccountCode.php.

References $ilDB, $result, and array.

Referenced by ilAccountCodesTableGUI\getItems().

59  {
60  global $ilDB;
61 
62  // filter
63  $where = self::filterToSQL($filter_code, $filter_valid_until, $filter_generated);
64 
65  // count query
66  $set = $ilDB->query("SELECT COUNT(*) AS cnt FROM ".self::DB_TABLE.$where);
67  $cnt = 0;
68  if ($rec = $ilDB->fetchAssoc($set))
69  {
70  $cnt = $rec["cnt"];
71  }
72 
73  $sql = "SELECT * FROM ".self::DB_TABLE.$where;
74  if($order_field)
75  {
76  $sql .= " ORDER BY ".$order_field." ".$order_direction;
77  }
78 
79  // set query
80  $ilDB->setLimit((int)$limit, (int)$offset);
81  $set = $ilDB->query($sql);
82  $result = array();
83  while($rec = $ilDB->fetchAssoc($set))
84  {
85  $result[] = $rec;
86  }
87  return array("cnt" => $cnt, "set" => $result);
88  }
$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 154 of file class.ilAccountCode.php.

References $ilDB, $result, and array.

Referenced by ilAccountCodesGUI\exportCodes().

155  {
156  global $ilDB;
157 
158  // filter
159  $where = self::filterToSQL($filter_code, $filter_valid_until, $filter_generated);
160 
161  // set query
162  $set = $ilDB->query("SELECT code FROM ".self::DB_TABLE.$where." ORDER BY code_id");
163  $result = array();
164  while($rec = $ilDB->fetchAssoc($set))
165  {
166  $result[] = $rec["code"];
167  }
168  return $result;
169  }
$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 198 of file class.ilAccountCode.php.

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

Referenced by ilStartUpGUI\processCode().

199  {
200  global $ilDB;
201 
202  include_once './Services/Registration/classes/class.ilRegistrationCode.php';
204 
205  if($code_data["alimit"])
206  {
207  switch($code_data["alimit"])
208  {
209  case "absolute":
210  return $code_data['alimitdt'];
211  }
212  }
213  return "0";
214 
215  $set = $ilDB->query("SELECT valid_until FROM ".self::DB_TABLE." WHERE code = ".$ilDB->quote($code, "text"));
216  $row = $ilDB->fetchAssoc($set);
217  if(isset($row["valid_until"]))
218  {
219  return $row["valid_until"];
220  }
221  }
$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 114 of file class.ilAccountCode.php.

References $ilDB, $result, and array.

Referenced by ilAccountCodesTableGUI\initFilter().

115  {
116  global $ilDB;
117 
118  $set = $ilDB->query("SELECT DISTINCT(generated) AS generated FROM ".self::DB_TABLE." ORDER BY generated");
119  $result = array();
120  while($rec = $ilDB->fetchAssoc($set))
121  {
122  $result[] = $rec["generated"];
123  }
124  return $result;
125  }
$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 171 of file class.ilAccountCode.php.

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

Referenced by ilStartUpGUI\processCode().

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

References $ilDB, $result, and array.

Referenced by ilAccountCodesGUI\deleteConfirmation().

91  {
92  global $ilDB;
93 
94  $set = $ilDB->query("SELECT * FROM ".self::DB_TABLE." WHERE ".$ilDB->in("code_id", $ids, false, "integer"));
95  $result = array();
96  while($rec = $ilDB->fetchAssoc($set))
97  {
98  $result[] = $rec;
99  }
100  return $result;
101  }
$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 188 of file class.ilAccountCode.php.

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

Referenced by ilStartUpGUI\processCode().

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