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.

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 }
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_YEAR
const IL_CAL_MONTH
const IL_CAL_DAY
@classDescription Date and time handling
setTimeLimitUntil($a_until)
setTimeLimitUnlimited($a_unlimited)
$code
Definition: example_050.php:99
$end
Definition: saml1-acs.php:18

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

+ 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.

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 }
static _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par="")
add an item to user's personal desktop
static _getAllReferences($a_id)
get all reference ids of object
getId()
get object id @access public
static _lookupType($a_id, $a_reference=false)
lookup object type
$GLOBALS['loaded']
Global hash that tracks already loaded includes.

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

Referenced by ilStartUpGUI\processCode().

+ 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.

19 {
20 global $ilDB;
21
22 $id = $ilDB->nextId(self::DB_TABLE);
23
24 // create unique code
25 $found = true;
26 while ($found) {
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 }
static generateRandomCode()
if(!array_key_exists('StateId', $_REQUEST)) $id
global $ilDB

References $code, $data, $id, $ilDB, and generateRandomCode().

Referenced by ilAccountCodesGUI\createCodes().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteCodes()

static ilAccountCode::deleteCodes ( array  $ids)
static

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

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 }

References $ilDB.

Referenced by ilAccountCodesGUI\deleteCodes().

+ 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.

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 }

References $ilDB.

Referenced by getCodesData(), and getCodesForExport().

+ Here is the caller graph for this function:

◆ generateRandomCode()

static ilAccountCode::generateRandomCode ( )
staticprotected

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

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 }

References $code, and CODE_LENGTH.

Referenced by create().

+ Here is the caller graph for this function:

◆ 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.

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
static filterToSQL($filter_code, $filter_valid_until, $filter_generated)

References $ilDB, $result, and filterToSQL().

Referenced by ilAccountCodesTableGUI\getItems().

+ Here is the call graph for this function:
+ 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.

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 }

References $ilDB, $result, and filterToSQL().

Referenced by ilAccountCodesGUI\exportCodes().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCodeValidUntil()

static ilAccountCode::getCodeValidUntil (   $code)
static

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

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 }

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

Referenced by ilStartUpGUI\processCode().

+ 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.

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 }

References $ilDB, and $result.

Referenced by ilAccountCodesTableGUI\initFilter().

+ Here is the caller graph for this function:

◆ isUnusedCode()

static ilAccountCode::isUnusedCode (   $code)
static

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

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 }
static isUnusedCode($code)
Check if code has been used already @global type $ilDB.

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

Referenced by ilStartUpGUI\processCode().

+ 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.

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 }

References $ilDB, and $result.

Referenced by ilAccountCodesGUI\deleteConfirmation().

+ Here is the caller graph for this function:

◆ useCode()

static ilAccountCode::useCode (   $code)
static

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

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 }

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

Referenced by ilStartUpGUI\processCode().

+ 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

◆ 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: