19 declare(strict_types=1);
28 protected const DB_TABLE =
'reg_registration_codes';
42 $ilDB = $DIC->database();
49 $code = self::generateRandomCode();
51 "SELECT code_id FROM " . self::DB_TABLE .
" WHERE code = %s",
55 $found = (bool)
$ilDB->numRows($chk);
59 'code_id' => [
'integer',
$id],
60 'code' => [
'text', $code],
61 'generated_on' => [
'integer', $stamp],
62 'role' => [
'integer', $role],
63 'role_local' => [
'text', implode(
";", $local_roles)],
64 'alimit' => [
'text', $limit],
65 'alimitdt' => [
'text', $limit_date],
66 'reg_enabled' => [
'integer', $reg_type],
67 'ext_enabled' => [
'integer', $ext_type]
77 $map =
"23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
80 $max = strlen($map) - 1;
81 for ($loop = 1; $loop <= self::CODE_LENGTH; $loop++) {
82 $code .= $map[random_int(0, $max)];
93 $set =
$ilDB->query(
"SELECT used FROM " . self::DB_TABLE .
" WHERE code = " .
$ilDB->quote($code,
"text"));
94 $set =
$ilDB->fetchAssoc($set);
95 return $set && !$set[
"used"];
102 $ilDB = $DIC->database();
104 $query =
'SELECT alimit, alimitdt FROM reg_registration_codes ' .
105 'WHERE used = ' .
$ilDB->quote(0,
'integer') .
' ' .
106 'AND reg_enabled = ' .
$ilDB->quote(1,
'integer') .
' ' .
107 'AND code = ' .
$ilDB->quote($a_code,
'text');
116 if ($row[
'alimit'] ===
'absolute') {
117 $clock_factory = (new \ILIAS\Data\Factory())->clock();
120 $clock_factory->system()->now()->getTimezone()
123 $is_valid = $right_interval >= $clock_factory->system()->now();
131 $code_data = self::getCodeData($code);
133 if ($code_data[
"alimit"]) {
134 switch ($code_data[
"alimit"]) {
136 return $code_data[
'alimitdt'];
142 public static function useCode(
string $code): bool
146 $ilDB = $DIC->database();
147 return (
bool)
$ilDB->update(
149 [
"used" => [
"timestamp", time()]],
150 [
"code" => [
"text", $code]]
158 $ilDB = $DIC->database();
159 $set =
$ilDB->query(
"SELECT role FROM " . self::DB_TABLE .
" WHERE code = " .
$ilDB->quote($code,
"text"));
160 $row =
$ilDB->fetchAssoc($set);
161 if (isset($row[
"role"])) {
162 return (
int) $row[
"role"];
171 $ilDB = $DIC->database();
172 $set =
$ilDB->query(
"SELECT role, role_local, alimit, alimitdt, reg_enabled, ext_enabled" .
173 " FROM " . self::DB_TABLE .
174 " WHERE code = " .
$ilDB->quote($code,
"text"));
175 return $ilDB->fetchAssoc($set);
184 $grole = self::getCodeRole($code);
186 $GLOBALS[
'DIC'][
'rbacadmin']->assignUser($grole, $user->
getId());
188 $code_data = self::getCodeData($code);
189 if ($code_data[
"role_local"]) {
190 $code_local_roles = explode(
";", $code_data[
"role_local"]);
191 foreach ($code_local_roles as $role_id) {
192 $GLOBALS[
'DIC'][
'rbacadmin']->assignUser($role_id, $user->
getId());
195 $role_obj =
$GLOBALS[
'DIC'][
'rbacreview']->getObjectOfRole($role_id);
200 $role_ref = end($role_refs);
215 $code_data = self::getCodeData($code);
217 if ($code_data[
"alimit"]) {
218 switch ($code_data[
"alimit"]) {
228 $rel = unserialize($code_data[
"alimitdt"], [
"allowed_classes" =>
false]);
setTimeLimitUnlimited(bool $a_unlimited)
static getCodeRole(string $code)
static getCodeValidUntil(string $code)
static _getAllReferences(int $id)
get all reference ids for object ID
setTimeLimitUntil(?int $a_until)
static getCodeData(string $code)
static isValidRegistrationCode(string $a_code)
static isUnusedCode(string $code)
static create(int $role, int $stamp, array $local_roles, ?string $limit, ?string $limit_date, bool $reg_type, bool $ext_type)
static useCode(string $code)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
static generateRandomCode()
static applyRoleAssignments(ilObjUser $user, string $code)
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...
static applyAccessLimits(ilObjUser $user, string $code)