18 public static function create($valid_until, $stamp)
22 $id = $ilDB->nextId(self::DB_TABLE);
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),
35 'code' => array(
'text', $code),
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;
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)
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))
87 return array(
"cnt" => $cnt,
"set" =>
$result);
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';
195 return (
bool)$ilDB->update(self::DB_TABLE, array(
"used"=>array(
"timestamp", time())), array(
"code"=>array(
"text", $code)));
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';