18 public static function create($role, $stamp, $local_roles, $limit, $limit_date)
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);
33 if(is_array($local_roles))
35 $local_roles = implode(
";", $local_roles);
37 if($limit ==
"relative" && is_array($limit_date))
39 $limit_date = serialize($limit_date);
43 'code_id' => array(
'integer', $id),
44 'code' => array(
'text', $code),
45 'generated' => array(
'integer', $stamp),
46 'role' => array(
'integer', $role),
47 'role_local' => array(
'text', $local_roles),
48 'alimit' => array(
'text', $limit),
49 'alimitdt' => array(
'text', $limit_date)
52 $ilDB->insert(self::DB_TABLE, $data);
59 $map =
"23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
62 $max = strlen($map)-1;
65 $code .= $map[mt_rand(0, $max)];
70 public static function getCodesData($order_field, $order_direction, $offset, $limit, $filter_code, $filter_role, $filter_generated, $filter_access_limitation)
75 $where =
self::filterToSQL($filter_code, $filter_role, $filter_generated, $filter_access_limitation);
78 $set = $ilDB->query(
"SELECT COUNT(*) AS cnt FROM ".self::DB_TABLE.$where);
80 if ($rec = $ilDB->fetchAssoc($set))
85 $sql =
"SELECT * FROM ".self::DB_TABLE.$where;
88 $sql .=
" ORDER BY ".$order_field.
" ".$order_direction;
92 $ilDB->setLimit((
int)$limit, (
int)$offset);
93 $set = $ilDB->query($sql);
95 while($rec = $ilDB->fetchAssoc($set))
99 return array(
"cnt" => $cnt,
"set" =>
$result);
106 $set = $ilDB->query(
"SELECT * FROM ".self::DB_TABLE.
" WHERE ".$ilDB->in(
"code_id", $ids,
false,
"integer"));
108 while($rec = $ilDB->fetchAssoc($set))
121 return $ilDB->manipulate(
"DELETE FROM ".self::DB_TABLE.
" WHERE ".$ilDB->in(
"code_id", $ids,
false,
"integer"));
130 $set = $ilDB->query(
"SELECT DISTINCT(generated) AS generated FROM ".self::DB_TABLE.
" ORDER BY generated");
132 while($rec = $ilDB->fetchAssoc($set))
139 protected static function filterToSQL($filter_code, $filter_role, $filter_generated, $filter_access_limitation)
146 $where[] = $ilDB->like(
"code",
"text",
"%".$filter_code.
"%");
150 $where[] =
"role = ".$ilDB->quote($filter_role,
"integer");
152 if($filter_generated)
154 $where[] =
"generated = ".$ilDB->quote($filter_generated,
"text");
156 if($filter_access_limitation)
158 $where[] =
"alimit = ".$ilDB->quote($filter_access_limitation,
"text");
162 return " WHERE ".implode(
" AND ", $where);
170 public static function getCodesForExport($filter_code, $filter_role, $filter_generated, $filter_access_limitation)
175 $where =
self::filterToSQL($filter_code, $filter_role, $filter_generated, $filter_access_limitation);
178 $set = $ilDB->query(
"SELECT code FROM ".self::DB_TABLE.$where.
" ORDER BY code_id");
180 while($rec = $ilDB->fetchAssoc($set))
191 $set = $ilDB->query(
"SELECT used FROM ".self::DB_TABLE.
" WHERE code = ".$ilDB->quote($code,
"text"));
192 $set = $ilDB->fetchAssoc($set);
193 if($set && !$set[
"used"])
204 return (
bool)$ilDB->update(self::DB_TABLE, array(
"used"=>array(
"timestamp", time())), array(
"code"=>array(
"text", $code)));
211 $set = $ilDB->query(
"SELECT role FROM ".self::DB_TABLE.
" WHERE code = ".$ilDB->quote($code,
"text"));
212 $row = $ilDB->fetchAssoc($set);
213 if(isset(
$row[
"role"]))
223 $set = $ilDB->query(
"SELECT role, role_local, alimit, alimitdt".
224 " FROM ".self::DB_TABLE.
225 " WHERE code = ".$ilDB->quote($code,
"text"));
226 $row = $ilDB->fetchAssoc($set);