18 public static function create($valid_until, $stamp)
29 $code = self::generateRandomCode();
30 $chk =
$ilDB->queryF(
"SELECT code_id FROM " . self::DB_TABLE .
" WHERE code = %s", array(
"text"), array(
$code));
31 $found = (bool)
$ilDB->numRows($chk);
35 'code_id' => array(
'integer',
$id),
36 'code' => array(
'text',
$code),
37 'generated' => array(
'integer', $stamp),
38 'valid_until' => array(
'text', $valid_until)
48 $map =
"23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
51 $max = strlen(
$map) - 1;
52 for ($loop = 1; $loop <= self::CODE_LENGTH; $loop++) {
58 public static function getCodesData($order_field, $order_direction, $offset, $limit, $filter_code, $filter_valid_until, $filter_generated)
65 $where = self::filterToSQL($filter_code, $filter_valid_until, $filter_generated);
68 $set =
$ilDB->query(
"SELECT COUNT(*) AS cnt FROM " . self::DB_TABLE . $where);
70 if ($rec =
$ilDB->fetchAssoc($set)) {
74 $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)) {
86 return array(
"cnt" => $cnt,
"set" =>
$result);
95 $set =
$ilDB->query(
"SELECT * FROM " . self::DB_TABLE .
" WHERE " .
$ilDB->in(
"code_id", $ids,
false,
"integer"));
97 while ($rec =
$ilDB->fetchAssoc($set)) {
107 $ilDB = $DIC[
'ilDB'];
110 return $ilDB->manipulate(
"DELETE FROM " . self::DB_TABLE .
" WHERE " .
$ilDB->in(
"code_id", $ids,
false,
"integer"));
119 $ilDB = $DIC[
'ilDB'];
121 $set =
$ilDB->query(
"SELECT DISTINCT(generated) AS generated FROM " . self::DB_TABLE .
" ORDER BY generated");
123 while ($rec =
$ilDB->fetchAssoc($set)) {
129 protected static function filterToSQL($filter_code, $filter_valid_until, $filter_generated)
133 $ilDB = $DIC[
'ilDB'];
137 $where[] =
$ilDB->like(
"code",
"text",
"%" . $filter_code .
"%");
139 if ($filter_valid_until) {
140 $where[] =
"valid_until = " .
$ilDB->quote($filter_valid_until,
"text");
142 if ($filter_generated) {
143 $where[] =
"generated = " .
$ilDB->quote($filter_generated,
"text");
145 if (
sizeof($where)) {
146 return " WHERE " . implode(
" AND ", $where);
156 $ilDB = $DIC[
'ilDB'];
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)) {
174 $ilDB = $DIC[
'ilDB'];
176 include_once
'./Services/Registration/classes/class.ilRegistrationCode.php';
180 $set =
$ilDB->query(
"SELECT used FROM " . self::DB_TABLE .
" WHERE code = " .
$ilDB->quote(
$code,
"text"));
181 $set =
$ilDB->fetchAssoc($set);
182 if ($set && !$set[
"used"]) {
192 $ilDB = $DIC[
'ilDB'];
194 include_once
'./Services/Registration/classes/class.ilRegistrationCode.php';
197 return (
bool)
$ilDB->update(self::DB_TABLE, array(
"used" => array(
"timestamp", time())), array(
"code" => array(
"text",
$code)));
204 $ilDB = $DIC[
'ilDB'];
206 include_once
'./Services/Registration/classes/class.ilRegistrationCode.php';
209 if ($code_data[
"alimit"]) {
210 switch ($code_data[
"alimit"]) {
212 return $code_data[
'alimitdt'];
217 $set =
$ilDB->query(
"SELECT valid_until FROM " . self::DB_TABLE .
" WHERE code = " .
$ilDB->quote(
$code,
"text"));
219 if (isset(
$row[
"valid_until"])) {
220 return $row[
"valid_until"];
226 include_once
'./Services/Registration/classes/class.ilRegistrationCode.php';
230 $GLOBALS[
'DIC'][
'rbacadmin']->assignUser($grole, $user->
getId());
233 if ($code_data[
"role_local"]) {
234 $code_local_roles = explode(
";", $code_data[
"role_local"]);
235 foreach ((array) $code_local_roles as $role_id) {
236 $GLOBALS[
'DIC'][
'rbacadmin']->assignUser($role_id, $user->
getId());
239 $role_obj =
$GLOBALS[
'DIC'][
'rbacreview']->getObjectOfRole($role_id);
244 $role_ref = end($role_refs);
255 include_once
'./Services/Registration/classes/class.ilRegistrationCode.php';
258 if ($code_data[
"alimit"]) {
259 switch ($code_data[
"alimit"]) {
269 $rel = unserialize($code_data[
"alimitdt"]);
271 include_once
'./Services/Calendar/classes/class.ilDateTime.php';
static applyRoleAssignments(ilObjUser $user, $code)
static applyAccessLimits(ilObjUser $user, $code)
static getCodeData($code)
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)
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)
static create($valid_until, $stamp)
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
static isUnusedCode($code)
Check if code has been used already type $ilDB.