18 public static function create($valid_until, $stamp)
22 $id = $ilDB->nextId(self::DB_TABLE);
27 $code = self::generateRandomCode();
28 $chk = $ilDB->queryF(
"SELECT code_id FROM " . self::DB_TABLE .
" WHERE code = %s",
array(
"text"),
array(
$code));
29 $found = (bool) $ilDB->numRows($chk);
35 'generated' =>
array(
'integer', $stamp),
36 'valid_until' =>
array(
'text', $valid_until)
39 $ilDB->insert(self::DB_TABLE,
$data);
46 $map =
"23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
49 $max = strlen($map)-1;
50 for ($loop = 1; $loop <= self::CODE_LENGTH; $loop++) {
51 $code .= $map[mt_rand(0, $max)];
56 public static function getCodesData($order_field, $order_direction, $offset, $limit, $filter_code, $filter_valid_until, $filter_generated)
61 $where = self::filterToSQL($filter_code, $filter_valid_until, $filter_generated);
64 $set = $ilDB->query(
"SELECT COUNT(*) AS cnt FROM " . self::DB_TABLE . $where);
66 if ($rec = $ilDB->fetchAssoc($set)) {
70 $sql =
"SELECT * FROM " . self::DB_TABLE . $where;
72 $sql .=
" ORDER BY " . $order_field .
" " . $order_direction;
76 $ilDB->setLimit((
int) $limit, (
int) $offset);
77 $set = $ilDB->query($sql);
79 while ($rec = $ilDB->fetchAssoc($set)) {
89 $set = $ilDB->query(
"SELECT * FROM " . self::DB_TABLE .
" WHERE " . $ilDB->in(
"code_id", $ids,
false,
"integer"));
91 while ($rec = $ilDB->fetchAssoc($set)) {
102 return $ilDB->manipulate(
"DELETE FROM " . self::DB_TABLE .
" WHERE " . $ilDB->in(
"code_id", $ids,
false,
"integer"));
111 $set = $ilDB->query(
"SELECT DISTINCT(generated) AS generated FROM " . self::DB_TABLE .
" ORDER BY generated");
113 while ($rec = $ilDB->fetchAssoc($set)) {
119 protected static function filterToSQL($filter_code, $filter_valid_until, $filter_generated)
125 $where[] = $ilDB->like(
"code",
"text",
"%" . $filter_code .
"%");
127 if ($filter_valid_until) {
128 $where[] =
"valid_until = " . $ilDB->quote($filter_valid_until,
"text");
130 if ($filter_generated) {
131 $where[] =
"generated = " . $ilDB->quote($filter_generated,
"text");
133 if (
sizeof($where)) {
134 return " WHERE " . implode(
" AND ", $where);
145 $where = self::filterToSQL($filter_code, $filter_valid_until, $filter_generated);
148 $set = $ilDB->query(
"SELECT code FROM " . self::DB_TABLE . $where .
" ORDER BY code_id");
150 while ($rec = $ilDB->fetchAssoc($set)) {
160 include_once
'./Services/Registration/classes/class.ilRegistrationCode.php';
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"]) {
176 include_once
'./Services/Registration/classes/class.ilRegistrationCode.php';
186 include_once
'./Services/Registration/classes/class.ilRegistrationCode.php';
189 if ($code_data[
"alimit"]) {
190 switch ($code_data[
"alimit"]) {
192 return $code_data[
'alimitdt'];
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"];
206 include_once
'./Services/Registration/classes/class.ilRegistrationCode.php';
213 if ($code_data[
"role_local"]) {
214 $code_local_roles = explode(
";", $code_data[
"role_local"]);
215 foreach ((
array) $code_local_roles as $role_id) {
219 $role_obj =
$GLOBALS[
'rbacreview']->getObjectOfRole($role_id);
224 $role_ref = end($role_refs);
235 include_once
'./Services/Registration/classes/class.ilRegistrationCode.php';
238 if ($code_data[
"alimit"]) {
239 switch ($code_data[
"alimit"]) {
249 $rel = unserialize($code_data[
"alimitdt"]);
251 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.
if(!array_key_exists('StateId', $_REQUEST)) $id
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.