ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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.

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 }
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

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

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 }
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['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276

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)
27 {
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 }
static generateRandomCode()
$data
global $ilDB

References $code, $data, $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 $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 }

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

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 }

References $ilDB.

Referenced by getCodesData(), and getCodesForExport().

+ Here is the caller graph for this function:

◆ generateRandomCode()

static ilAccountCode::generateRandomCode ( )
staticprotected

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

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 }

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

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

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 }

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

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 }

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

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 }

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

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

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 }

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

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 }

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: