ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 253 of file class.ilAccountCode.php.

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

References $code, $end, $user, ilRegistrationCode\getCodeData(), IL_CAL_DATE, IL_CAL_DAY, IL_CAL_MONTH, IL_CAL_UNIX, and IL_CAL_YEAR.

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 224 of file class.ilAccountCode.php.

225 {
226 include_once './Services/Registration/classes/class.ilRegistrationCode.php';
227
229 if ($grole) {
230 $GLOBALS['DIC']['rbacadmin']->assignUser($grole, $user->getId());
231 }
233 if ($code_data["role_local"]) {
234 $code_local_roles = explode(";", $code_data["role_local"]);
235 foreach ((array) $code_local_roles as $role_id) {
236 $GLOBALS['DIC']['rbacadmin']->assignUser($role_id, $user->getId());
237
238 // patch to remove for 45 due to mantis 21953
239 $role_obj = $GLOBALS['DIC']['rbacreview']->getObjectOfRole($role_id);
240 switch (ilObject::_lookupType($role_obj)) {
241 case 'crs':
242 case 'grp':
243 $role_refs = ilObject::_getAllReferences($role_obj);
244 $role_ref = end($role_refs);
245 ilObjUser::_addDesktopItem($user->getId(), $role_ref, ilObject::_lookupType($role_obj));
246 break;
247 }
248 }
249 }
250 return true;
251 }
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
static _lookupType($a_id, $a_reference=false)
lookup object type
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.

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

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 $DIC;
21
22 $ilDB = $DIC['ilDB'];
23
24 $id = $ilDB->nextId(self::DB_TABLE);
25
26 // create unique code
27 $found = true;
28 while ($found) {
30 $chk = $ilDB->queryF("SELECT code_id FROM " . self::DB_TABLE . " WHERE code = %s", array("text"), array($code));
31 $found = (bool) $ilDB->numRows($chk);
32 }
33
34 $data = array(
35 'code_id' => array('integer', $id),
36 'code' => array('text', $code),
37 'generated' => array('integer', $stamp),
38 'valid_until' => array('text', $valid_until)
39 );
40
41 $ilDB->insert(self::DB_TABLE, $data);
42 return $id;
43 }
static generateRandomCode()
if(!array_key_exists('StateId', $_REQUEST)) $id
global $DIC
Definition: saml.php:7
global $ilDB
$data
Definition: bench.php:6

References $code, $data, $DIC, $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 103 of file class.ilAccountCode.php.

104 {
105 global $DIC;
106
107 $ilDB = $DIC['ilDB'];
108
109 if (sizeof($ids)) {
110 return $ilDB->manipulate("DELETE FROM " . self::DB_TABLE . " WHERE " . $ilDB->in("code_id", $ids, false, "integer"));
111 }
112 return false;
113 }

References $DIC, and $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 129 of file class.ilAccountCode.php.

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

References $DIC, and $ilDB.

Referenced by getCodesData(), and getCodesForExport().

+ Here is the caller graph for this function:

◆ generateRandomCode()

static ilAccountCode::generateRandomCode ( )
staticprotected

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

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

References $code, $map, 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 58 of file class.ilAccountCode.php.

59 {
60 global $DIC;
61
62 $ilDB = $DIC['ilDB'];
63
64 // filter
65 $where = self::filterToSQL($filter_code, $filter_valid_until, $filter_generated);
66
67 // count query
68 $set = $ilDB->query("SELECT COUNT(*) AS cnt FROM " . self::DB_TABLE . $where);
69 $cnt = 0;
70 if ($rec = $ilDB->fetchAssoc($set)) {
71 $cnt = $rec["cnt"];
72 }
73
74 $sql = "SELECT * FROM " . self::DB_TABLE . $where;
75 if ($order_field) {
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 $result[] = $rec;
85 }
86 return array("cnt" => $cnt, "set" => $result);
87 }
$result
static filterToSQL($filter_code, $filter_valid_until, $filter_generated)

References $DIC, $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 152 of file class.ilAccountCode.php.

153 {
154 global $DIC;
155
156 $ilDB = $DIC['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 $result[] = $rec["code"];
166 }
167 return $result;
168 }

References $DIC, $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 200 of file class.ilAccountCode.php.

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

References $code, $DIC, $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 115 of file class.ilAccountCode.php.

116 {
117 global $DIC;
118
119 $ilDB = $DIC['ilDB'];
120
121 $set = $ilDB->query("SELECT DISTINCT(generated) AS generated FROM " . self::DB_TABLE . " ORDER BY generated");
122 $result = array();
123 while ($rec = $ilDB->fetchAssoc($set)) {
124 $result[] = $rec["generated"];
125 }
126 return $result;
127 }

References $DIC, $ilDB, and $result.

Referenced by ilAccountCodesTableGUI\initFilter().

+ Here is the caller graph for this function:

◆ isUnusedCode()

static ilAccountCode::isUnusedCode (   $code)
static

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

171 {
172 global $DIC;
173
174 $ilDB = $DIC['ilDB'];
175
176 include_once './Services/Registration/classes/class.ilRegistrationCode.php';
178
179
180 $set = $ilDB->query("SELECT used FROM " . self::DB_TABLE . " WHERE code = " . $ilDB->quote($code, "text"));
181 $set = $ilDB->fetchAssoc($set);
182 if ($set && !$set["used"]) {
183 return true;
184 }
185 return false;
186 }
static isUnusedCode($code)
Check if code has been used already @global type $ilDB.

References $code, $DIC, $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 89 of file class.ilAccountCode.php.

90 {
91 global $DIC;
92
93 $ilDB = $DIC['ilDB'];
94
95 $set = $ilDB->query("SELECT * FROM " . self::DB_TABLE . " WHERE " . $ilDB->in("code_id", $ids, false, "integer"));
96 $result = array();
97 while ($rec = $ilDB->fetchAssoc($set)) {
98 $result[] = $rec;
99 }
100 return $result;
101 }

References $DIC, $ilDB, and $result.

Referenced by ilAccountCodesGUI\deleteConfirmation().

+ Here is the caller graph for this function:

◆ useCode()

static ilAccountCode::useCode (   $code)
static

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

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

References $code, $DIC, $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: