18 public static function create($valid_until, $stamp)
22 $id = $ilDB->nextId(self::DB_TABLE);
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);
34 'code_id' =>
array(
'integer', $id),
36 'generated' =>
array(
'integer', $stamp),
37 'valid_until' =>
array(
'text', $valid_until)
40 $ilDB->insert(self::DB_TABLE,
$data);
47 $map =
"23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
50 $max = strlen($map)-1;
51 for($loop = 1; $loop <= self::CODE_LENGTH; $loop++)
53 $code .= $map[mt_rand(0, $max)];
58 public static function getCodesData($order_field, $order_direction, $offset, $limit, $filter_code, $filter_valid_until, $filter_generated)
63 $where = self::filterToSQL($filter_code, $filter_valid_until, $filter_generated);
66 $set = $ilDB->query(
"SELECT COUNT(*) AS cnt FROM ".self::DB_TABLE.$where);
68 if ($rec = $ilDB->fetchAssoc($set))
73 $sql =
"SELECT * FROM ".self::DB_TABLE.$where;
76 $sql .=
" ORDER BY ".$order_field.
" ".$order_direction;
80 $ilDB->setLimit((
int)$limit, (
int)$offset);
81 $set = $ilDB->query($sql);
83 while($rec = $ilDB->fetchAssoc($set))
94 $set = $ilDB->query(
"SELECT * FROM ".self::DB_TABLE.
" WHERE ".$ilDB->in(
"code_id", $ids,
false,
"integer"));
96 while($rec = $ilDB->fetchAssoc($set))
109 return $ilDB->manipulate(
"DELETE FROM ".self::DB_TABLE.
" WHERE ".$ilDB->in(
"code_id", $ids,
false,
"integer"));
118 $set = $ilDB->query(
"SELECT DISTINCT(generated) AS generated FROM ".self::DB_TABLE.
" ORDER BY generated");
120 while($rec = $ilDB->fetchAssoc($set))
127 protected static function filterToSQL($filter_code, $filter_valid_until, $filter_generated)
134 $where[] = $ilDB->like(
"code",
"text",
"%".$filter_code.
"%");
136 if($filter_valid_until)
138 $where[] =
"valid_until = ".$ilDB->quote($filter_valid_until,
"text");
140 if($filter_generated)
142 $where[] =
"generated = ".$ilDB->quote($filter_generated,
"text");
146 return " WHERE ".implode(
" AND ", $where);
159 $where = self::filterToSQL($filter_code, $filter_valid_until, $filter_generated);
162 $set = $ilDB->query(
"SELECT code FROM ".self::DB_TABLE.$where.
" ORDER BY code_id");
164 while($rec = $ilDB->fetchAssoc($set))
175 include_once
'./Services/Registration/classes/class.ilRegistrationCode.php';
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"])
192 include_once
'./Services/Registration/classes/class.ilRegistrationCode.php';
202 include_once
'./Services/Registration/classes/class.ilRegistrationCode.php';
205 if($code_data[
"alimit"])
207 switch($code_data[
"alimit"])
210 return $code_data[
'alimitdt'];
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"]))
219 return $row[
"valid_until"];
225 include_once
'./Services/Registration/classes/class.ilRegistrationCode.php';
233 if($code_data[
"role_local"])
235 $code_local_roles = explode(
";", $code_data[
"role_local"]);
236 foreach((
array) $code_local_roles as $role_id)
241 $role_obj =
$GLOBALS[
'rbacreview']->getObjectOfRole($role_id);
247 $role_ref = end($role_refs);
258 include_once
'./Services/Registration/classes/class.ilRegistrationCode.php';
261 if($code_data[
"alimit"])
263 switch($code_data[
"alimit"])
274 $rel = unserialize($code_data[
"alimitdt"]);
276 include_once
'./Services/Calendar/classes/class.ilDateTime.php';
static applyRoleAssignments(ilObjUser $user, $code)
static applyAccessLimits(ilObjUser $user, $code)
static getCodeData($code)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static getGenerationDates()
static getCodesForExport($filter_code, $filter_valid_until, $filter_generated)
static getCodesData($order_field, $order_direction, $offset, $limit, $filter_code, $filter_valid_until, $filter_generated)
static _getAllReferences($a_id)
get all reference ids of object
setTimeLimitUnlimited($a_unlimited)
setTimeLimitUntil($a_until)
static getCodeRole($code)
getId()
get object id public
static loadCodesByIds(array $ids)
static deleteCodes(array $ids)
static filterToSQL($filter_code, $filter_valid_until, $filter_generated)
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
static generateRandomCode()
static getCodeValidUntil($code)
static _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par="")
add an item to user's personal desktop
static isUnusedCode($code)
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static create($valid_until, $stamp)
static isUnusedCode($code)
Check if code has been used already type $ilDB.