18 public static function create($role, $stamp, $local_roles, $limit, $limit_date, $reg_type, $ext_type)
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),
50 'reg_enabled' => array(
'integer',$reg_type),
51 'ext_enabled' => array(
'integer',$ext_type)
54 $ilDB->insert(self::DB_TABLE, $data);
61 $map =
"23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
64 $max = strlen($map)-1;
67 $code .= $map[mt_rand(0, $max)];
72 public static function getCodesData($order_field, $order_direction, $offset, $limit, $filter_code, $filter_role, $filter_generated, $filter_access_limitation)
77 $where =
self::filterToSQL($filter_code, $filter_role, $filter_generated, $filter_access_limitation);
80 $set = $ilDB->query(
"SELECT COUNT(*) AS cnt FROM ".self::DB_TABLE.$where);
82 if ($rec = $ilDB->fetchAssoc($set))
87 $sql =
"SELECT * FROM ".self::DB_TABLE.$where;
90 $sql .=
" ORDER BY ".$order_field.
" ".$order_direction;
94 $ilDB->setLimit((
int)$limit, (
int)$offset);
95 $set = $ilDB->query($sql);
97 while($rec = $ilDB->fetchAssoc($set))
101 return array(
"cnt" => $cnt,
"set" =>
$result);
108 $set = $ilDB->query(
"SELECT * FROM ".self::DB_TABLE.
" WHERE ".$ilDB->in(
"code_id", $ids,
false,
"integer"));
110 while($rec = $ilDB->fetchAssoc($set))
123 return $ilDB->manipulate(
"DELETE FROM ".self::DB_TABLE.
" WHERE ".$ilDB->in(
"code_id", $ids,
false,
"integer"));
132 $set = $ilDB->query(
"SELECT DISTINCT(generated) AS generated FROM ".self::DB_TABLE.
" ORDER BY generated");
134 while($rec = $ilDB->fetchAssoc($set))
141 protected static function filterToSQL($filter_code, $filter_role, $filter_generated, $filter_access_limitation)
148 $where[] = $ilDB->like(
"code",
"text",
"%".$filter_code.
"%");
152 $where[] =
"role = ".$ilDB->quote($filter_role,
"integer");
154 if($filter_generated)
156 $where[] =
"generated = ".$ilDB->quote($filter_generated,
"text");
158 if($filter_access_limitation)
160 $where[] =
"alimit = ".$ilDB->quote($filter_access_limitation,
"text");
164 return " WHERE ".implode(
" AND ", $where);
172 public static function getCodesForExport($filter_code, $filter_role, $filter_generated, $filter_access_limitation)
177 $where =
self::filterToSQL($filter_code, $filter_role, $filter_generated, $filter_access_limitation);
180 $set = $ilDB->query(
"SELECT code FROM ".self::DB_TABLE.$where.
" ORDER BY code_id");
182 while($rec = $ilDB->fetchAssoc($set))
193 $set = $ilDB->query(
"SELECT used FROM ".self::DB_TABLE.
" WHERE code = ".$ilDB->quote($code,
"text"));
194 $set = $ilDB->fetchAssoc($set);
195 if($set && !$set[
"used"])
206 return (
bool)$ilDB->update(self::DB_TABLE, array(
"used"=>array(
"timestamp", time())), array(
"code"=>array(
"text", $code)));
213 $set = $ilDB->query(
"SELECT role FROM ".self::DB_TABLE.
" WHERE code = ".$ilDB->quote($code,
"text"));
214 $row = $ilDB->fetchAssoc($set);
215 if(isset(
$row[
"role"]))
225 $set = $ilDB->query(
"SELECT role, role_local, alimit, alimitdt, reg_enabled, ext_enabled".
226 " FROM ".self::DB_TABLE.
227 " WHERE code = ".$ilDB->quote($code,
"text"));
228 $row = $ilDB->fetchAssoc($set);