18 public static function create($role, $stamp, $local_roles, $limit, $limit_date, $reg_type, $ext_type)
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);
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),
45 'generated_on' =>
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;
65 for($loop = 1; $loop <= self::CODE_LENGTH; $loop++)
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 if($order_field ==
'generated')
92 $order_field =
'generated_on';
94 $sql .=
" ORDER BY ".$order_field.
" ".$order_direction;
98 $ilDB->setLimit((
int)$limit, (
int)$offset);
99 $set = $ilDB->query($sql);
101 while($rec = $ilDB->fetchAssoc($set))
103 $rec[
'generated'] = $rec[
'generated_on'];
113 $set = $ilDB->query(
"SELECT * FROM ".self::DB_TABLE.
" WHERE ".$ilDB->in(
"code_id", $ids,
false,
"integer"));
115 while($rec = $ilDB->fetchAssoc($set))
128 return $ilDB->manipulate(
"DELETE FROM ".self::DB_TABLE.
" WHERE ".$ilDB->in(
"code_id", $ids,
false,
"integer"));
137 $set = $ilDB->query(
"SELECT DISTINCT(generated_on) genr FROM ".self::DB_TABLE.
" ORDER BY genr");
139 while($rec = $ilDB->fetchAssoc($set))
146 protected static function filterToSQL($filter_code, $filter_role, $filter_generated, $filter_access_limitation)
153 $where[] = $ilDB->like(
"code",
"text",
"%".$filter_code.
"%");
157 $where[] =
"role = ".$ilDB->quote($filter_role,
"integer");
159 if($filter_generated)
161 $where[] =
"generated_on = ".$ilDB->quote($filter_generated,
"text");
163 if($filter_access_limitation)
165 $where[] =
"alimit = ".$ilDB->quote($filter_access_limitation,
"text");
169 return " WHERE ".implode(
" AND ", $where);
177 public static function getCodesForExport($filter_code, $filter_role, $filter_generated, $filter_access_limitation)
182 $where = self::filterToSQL($filter_code, $filter_role, $filter_generated, $filter_access_limitation);
185 $set = $ilDB->query(
"SELECT code FROM ".self::DB_TABLE.$where.
" ORDER BY code_id");
187 while($rec = $ilDB->fetchAssoc($set))
204 $set = $ilDB->query(
"SELECT used FROM ".self::DB_TABLE.
" WHERE code = ".$ilDB->quote(
$code,
"text"));
205 $set = $ilDB->fetchAssoc($set);
206 if($set && !$set[
"used"])
222 $query =
'SELECT code_id FROM reg_registration_codes '.
223 'WHERE used = '.$ilDB->quote(0,
'integer').
' '.
224 'AND reg_enabled = '.$ilDB->quote(1,
'integer').
' '.
225 'AND code = '.$ilDB->quote($a_code,
'text');
228 return $res->numRows() ? true :
false;
242 $set = $ilDB->query(
"SELECT role FROM ".self::DB_TABLE.
" WHERE code = ".$ilDB->quote(
$code,
"text"));
243 $row = $ilDB->fetchAssoc($set);
244 if(isset(
$row[
"role"]))
254 $set = $ilDB->query(
"SELECT role, role_local, alimit, alimitdt, reg_enabled, ext_enabled".
255 " FROM ".self::DB_TABLE.
256 " WHERE code = ".$ilDB->quote(
$code,
"text"));
257 $row = $ilDB->fetchAssoc($set);
static getCodeData($code)
static getCodesData($order_field, $order_direction, $offset, $limit, $filter_code, $filter_role, $filter_generated, $filter_access_limitation)
static deleteCodes(array $ids)
static getGenerationDates()
static filterToSQL($filter_code, $filter_role, $filter_generated, $filter_access_limitation)
static create($role, $stamp, $local_roles, $limit, $limit_date, $reg_type, $ext_type)
static getCodeRole($code)
static isValidRegistrationCode($a_code)
Check if given code is a valid registration code.
static loadCodesByIds(array $ids)
Class ilRegistrationCode.
Create styles array
The data for the language used.
static generateRandomCode()
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
static getCodesForExport($filter_code, $filter_role, $filter_generated, $filter_access_limitation)
static isUnusedCode($code)
Check if code has been used already type $ilDB.