40 $code = self::generateRandomCode();
41 $chk =
$ilDB->queryF(
"SELECT code_id FROM " . self::DB_TABLE .
" WHERE code = %s", array(
"text"), array($code));
42 $found = (bool)
$ilDB->numRows($chk);
46 'code_id' => array(
'integer',
$id),
47 'code' => array(
'text', $code),
48 'generated' => array(
'integer', $stamp),
49 'valid_until' => array(
'text', $valid_until)
59 $map =
"23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
62 $max = strlen($map) - 1;
63 for ($loop = 1; $loop <= self::CODE_LENGTH; $loop++) {
64 $code .= $map[random_int(0, $max)];
71 string $order_direction,
75 string $filter_valid_until,
76 string $filter_generated
83 $where = self::filterToSQL($filter_code, $filter_valid_until, $filter_generated);
86 $set =
$ilDB->query(
"SELECT COUNT(*) AS cnt FROM " . self::DB_TABLE . $where);
88 if ($rec =
$ilDB->fetchAssoc($set)) {
92 $sql =
"SELECT * FROM " . self::DB_TABLE . $where;
94 $sql .=
" ORDER BY " . $order_field .
" " . $order_direction;
98 $ilDB->setLimit($limit, $offset);
99 $set =
$ilDB->query($sql);
101 while ($rec =
$ilDB->fetchAssoc($set)) {
104 return array(
"cnt" => $cnt,
"set" => $result);
114 $ilDB = $DIC[
'ilDB'];
116 $set =
$ilDB->query(
"SELECT * FROM " . self::DB_TABLE .
" WHERE " .
$ilDB->in(
"code_id", $ids,
false,
"integer"));
118 while ($rec =
$ilDB->fetchAssoc($set)) {
131 $ilDB = $DIC[
'ilDB'];
134 return $ilDB->manipulate(
"DELETE FROM " . self::DB_TABLE .
" WHERE " .
$ilDB->in(
"code_id", $ids,
false,
"integer"));
146 $ilDB = $DIC[
'ilDB'];
148 $set =
$ilDB->query(
"SELECT DISTINCT(generated) AS generated FROM " . self::DB_TABLE .
" ORDER BY generated");
150 while ($rec =
$ilDB->fetchAssoc($set)) {
151 $result[] = $rec[
"generated"];
158 string $filter_valid_until,
159 string $filter_generated
163 $ilDB = $DIC[
'ilDB'];
167 $where[] =
$ilDB->like(
"code",
"text",
"%" . $filter_code .
"%");
169 if ($filter_valid_until) {
170 $where[] =
"valid_until = " .
$ilDB->quote($filter_valid_until,
"text");
172 if ($filter_generated) {
173 $where[] =
"generated = " .
$ilDB->quote($filter_generated,
"text");
176 return " WHERE " . implode(
" AND ", $where);
184 string $filter_valid_until,
185 string $filter_generated
189 $ilDB = $DIC[
'ilDB'];
192 $where = self::filterToSQL($filter_code, $filter_valid_until, $filter_generated);
195 $set =
$ilDB->query(
"SELECT code FROM " . self::DB_TABLE . $where .
" ORDER BY code_id");
197 while ($rec =
$ilDB->fetchAssoc($set)) {
198 $result[] = $rec[
"code"];
208 public static function useCode(
string $code): bool
217 if ($code_data[
"alimit"]) {
218 switch ($code_data[
"alimit"]) {
220 return $code_data[
'alimitdt'];
234 $GLOBALS[
'DIC'][
'rbacadmin']->assignUser($grole, $user->
getId());
237 if ($code_data[
"role_local"]) {
238 $code_local_roles = explode(
";", $code_data[
"role_local"]);
239 foreach ($code_local_roles as $role_id) {
240 $GLOBALS[
'DIC'][
'rbacadmin']->assignUser($role_id, $user->
getId());
243 $role_obj =
$GLOBALS[
'DIC'][
'rbacreview']->getObjectOfRole($role_id);
248 $role_ref = end($role_refs);
265 if ($code_data[
"alimit"]) {
266 switch ($code_data[
"alimit"]) {
276 $rel = unserialize($code_data[
"alimitdt"], [
"allowed_classes" =>
false]);
setTimeLimitUnlimited(bool $a_unlimited)
static getCodeRole(string $code)
static useCode(string $code)
static applyRoleAssignments(ilObjUser $user, string $code)
static getCodeValidUntil(string $code)
static _getAllReferences(int $id)
get all reference ids for object ID
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static isUnusedCode(string $code)
static getGenerationDates()
static getCodesForExport(string $filter_code, string $filter_valid_until, string $filter_generated)
setTimeLimitUntil(?int $a_until)
static getCodeData(string $code)
static loadCodesByIds(array $ids)
static isUnusedCode(string $code)
static deleteCodes(array $ids)
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
static getCodesData(string $order_field, string $order_direction, int $offset, int $limit, string $filter_code, string $filter_valid_until, string $filter_generated)
static filterToSQL(string $filter_code, string $filter_valid_until, string $filter_generated)
static generateRandomCode()
static create(string $valid_until, int $stamp)
static applyAccessLimits(ilObjUser $user, string $code)
static useCode(string $code)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...