ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilRegistrationCode Class Reference

Class ilRegistrationCode. More...

+ Collaboration diagram for ilRegistrationCode:

Static Public Member Functions

static create ($role, $stamp, $local_roles, $limit, $limit_date, $reg_type, $ext_type)
 
static getCodesData ($order_field, $order_direction, $offset, $limit, $filter_code, $filter_role, $filter_generated, $filter_access_limitation)
 
static loadCodesByIds (array $ids)
 
static deleteCodes (array $ids)
 
static getGenerationDates ()
 
static getCodesForExport ($filter_code, $filter_role, $filter_generated, $filter_access_limitation)
 
static isUnusedCode ($code)
 Check if code has been used already @global type $ilDB. More...
 
static isValidRegistrationCode ($a_code)
 Check if given code is a valid registration code. More...
 
static useCode ($code)
 
static getCodeRole ($code)
 
static getCodeData ($code)
 

Data Fields

const DB_TABLE = 'reg_registration_codes'
 
const CODE_LENGTH = 10
 

Static Protected Member Functions

static generateRandomCode ()
 
static filterToSQL ($filter_code, $filter_role, $filter_generated, $filter_access_limitation)
 

Detailed Description

Class ilRegistrationCode.

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e
Version
Id
class.ilRegistrationSettingsGUI.php 23797 2010-05-07 15:54:03Z jluetzen

Definition at line 13 of file class.ilRegistrationCode.php.

Member Function Documentation

◆ create()

static ilRegistrationCode::create (   $role,
  $stamp,
  $local_roles,
  $limit,
  $limit_date,
  $reg_type,
  $ext_type 
)
static

Definition at line 18 of file class.ilRegistrationCode.php.

19 {
20 global $DIC;
21
22 $ilDB = $DIC['ilDB'];
23
24 $id = $ilDB->nextId(self::DB_TABLE);
25
26 // create unique code
27 $found = true;
28 while ($found) {
30 $chk = $ilDB->queryF("SELECT code_id FROM " . self::DB_TABLE . " WHERE code = %s", array("text"), array($code));
31 $found = (bool) $ilDB->numRows($chk);
32 }
33
34 if (is_array($local_roles)) {
35 $local_roles = implode(";", $local_roles);
36 }
37 if ($limit == "relative" && is_array($limit_date)) {
38 $limit_date = serialize($limit_date);
39 }
40
41 $data = array(
42 'code_id' => array('integer', $id),
43 'code' => array('text', $code),
44 'generated_on' => array('integer', $stamp),
45 'role' => array('integer', $role),
46 'role_local' => array('text', $local_roles),
47 'alimit' => array('text', $limit),
48 'alimitdt' => array('text', $limit_date),
49 'reg_enabled' => array('integer',$reg_type),
50 'ext_enabled' => array('integer',$ext_type)
51 );
52
53 $ilDB->insert(self::DB_TABLE, $data);
54 return $id;
55 }
$code
Definition: example_050.php:99
if(!array_key_exists('StateId', $_REQUEST)) $id
global $DIC
Definition: saml.php:7
global $ilDB
$data
Definition: bench.php:6

References $code, $data, $DIC, $id, $ilDB, and generateRandomCode().

Referenced by ilRegistrationSettingsGUI\createCodes().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteCodes()

static ilRegistrationCode::deleteCodes ( array  $ids)
static

Definition at line 119 of file class.ilRegistrationCode.php.

120 {
121 global $DIC;
122
123 $ilDB = $DIC['ilDB'];
124
125 if (sizeof($ids)) {
126 return $ilDB->manipulate("DELETE FROM " . self::DB_TABLE . " WHERE " . $ilDB->in("code_id", $ids, false, "integer"));
127 }
128 return false;
129 }

References $DIC, and $ilDB.

Referenced by ilRegistrationSettingsGUI\deleteCodes().

+ Here is the caller graph for this function:

◆ filterToSQL()

static ilRegistrationCode::filterToSQL (   $filter_code,
  $filter_role,
  $filter_generated,
  $filter_access_limitation 
)
staticprotected

Definition at line 145 of file class.ilRegistrationCode.php.

146 {
147 global $DIC;
148
149 $ilDB = $DIC['ilDB'];
150
151 $where = array();
152 if ($filter_code) {
153 $where[] = $ilDB->like("code", "text", "%" . $filter_code . "%");
154 }
155 if ($filter_role) {
156 $where[] = "role = " . $ilDB->quote($filter_role, "integer");
157 }
158 if ($filter_generated) {
159 $where[] = "generated_on = " . $ilDB->quote($filter_generated, "text");
160 }
161 if ($filter_access_limitation) {
162 $where[] = "alimit = " . $ilDB->quote($filter_access_limitation, "text");
163 }
164 if (sizeof($where)) {
165 return " WHERE " . implode(" AND ", $where);
166 } else {
167 return "";
168 }
169 }

References $DIC, and $ilDB.

Referenced by getCodesData(), and getCodesForExport().

+ Here is the caller graph for this function:

◆ generateRandomCode()

static ilRegistrationCode::generateRandomCode ( )
staticprotected

Definition at line 57 of file class.ilRegistrationCode.php.

58 {
59 // missing : 01iloO
60 $map = "23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
61
62 $code = "";
63 $max = strlen($map) - 1;
64 for ($loop = 1; $loop <= self::CODE_LENGTH; $loop++) {
65 $code .= $map[mt_rand(0, $max)];
66 }
67 return $code;
68 }

References $code, $map, and CODE_LENGTH.

Referenced by create().

+ Here is the caller graph for this function:

◆ getCodeData()

static ilRegistrationCode::getCodeData (   $code)
static

Definition at line 251 of file class.ilRegistrationCode.php.

252 {
253 global $DIC;
254
255 $ilDB = $DIC['ilDB'];
256
257 $set = $ilDB->query("SELECT role, role_local, alimit, alimitdt, reg_enabled, ext_enabled" .
258 " FROM " . self::DB_TABLE .
259 " WHERE code = " . $ilDB->quote($code, "text"));
260 $row = $ilDB->fetchAssoc($set);
261 return $row;
262 }
$row

References $code, $DIC, $ilDB, and $row.

Referenced by ilAccountCode\applyAccessLimits(), ilAccountCode\applyRoleAssignments(), and ilAccountCode\getCodeValidUntil().

+ Here is the caller graph for this function:

◆ getCodeRole()

static ilRegistrationCode::getCodeRole (   $code)
static

Definition at line 238 of file class.ilRegistrationCode.php.

239 {
240 global $DIC;
241
242 $ilDB = $DIC['ilDB'];
243
244 $set = $ilDB->query("SELECT role FROM " . self::DB_TABLE . " WHERE code = " . $ilDB->quote($code, "text"));
245 $row = $ilDB->fetchAssoc($set);
246 if (isset($row["role"])) {
247 return $row["role"];
248 }
249 }

References $code, $DIC, $ilDB, and $row.

Referenced by ilAccountCode\applyRoleAssignments(), and ilAccountRegistrationGUI\saveForm().

+ Here is the caller graph for this function:

◆ getCodesData()

static ilRegistrationCode::getCodesData (   $order_field,
  $order_direction,
  $offset,
  $limit,
  $filter_code,
  $filter_role,
  $filter_generated,
  $filter_access_limitation 
)
static

Definition at line 70 of file class.ilRegistrationCode.php.

71 {
72 global $DIC;
73
74 $ilDB = $DIC['ilDB'];
75
76 // filter
77 $where = self::filterToSQL($filter_code, $filter_role, $filter_generated, $filter_access_limitation);
78
79 // count query
80 $set = $ilDB->query("SELECT COUNT(*) AS cnt FROM " . self::DB_TABLE . $where);
81 $cnt = 0;
82 if ($rec = $ilDB->fetchAssoc($set)) {
83 $cnt = $rec["cnt"];
84 }
85
86 $sql = "SELECT * FROM " . self::DB_TABLE . $where;
87 if ($order_field) {
88 if ($order_field == 'generated') {
89 $order_field = 'generated_on';
90 }
91 $sql .= " ORDER BY " . $order_field . " " . $order_direction;
92 }
93
94 // set query
95 $ilDB->setLimit((int) $limit, (int) $offset);
96 $set = $ilDB->query($sql);
97 $result = array();
98 while ($rec = $ilDB->fetchAssoc($set)) {
99 $rec['generated'] = $rec['generated_on'];
100 $result[] = $rec;
101 }
102 return array("cnt" => $cnt, "set" => $result);
103 }
$result
static filterToSQL($filter_code, $filter_role, $filter_generated, $filter_access_limitation)

References $DIC, $ilDB, $result, and filterToSQL().

Referenced by ilRegistrationCodesTableGUI\getItems().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCodesForExport()

static ilRegistrationCode::getCodesForExport (   $filter_code,
  $filter_role,
  $filter_generated,
  $filter_access_limitation 
)
static

Definition at line 171 of file class.ilRegistrationCode.php.

172 {
173 global $DIC;
174
175 $ilDB = $DIC['ilDB'];
176
177 // filter
178 $where = self::filterToSQL($filter_code, $filter_role, $filter_generated, $filter_access_limitation);
179
180 // set query
181 $set = $ilDB->query("SELECT code FROM " . self::DB_TABLE . $where . " ORDER BY code_id");
182 $result = array();
183 while ($rec = $ilDB->fetchAssoc($set)) {
184 $result[] = $rec["code"];
185 }
186 return $result;
187 }

References $DIC, $ilDB, $result, and filterToSQL().

Referenced by ilRegistrationSettingsGUI\exportCodes().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getGenerationDates()

static ilRegistrationCode::getGenerationDates ( )
static

Definition at line 131 of file class.ilRegistrationCode.php.

132 {
133 global $DIC;
134
135 $ilDB = $DIC['ilDB'];
136
137 $set = $ilDB->query("SELECT DISTINCT(generated_on) genr FROM " . self::DB_TABLE . " ORDER BY genr");
138 $result = array();
139 while ($rec = $ilDB->fetchAssoc($set)) {
140 $result[] = $rec["genr"];
141 }
142 return $result;
143 }

References $DIC, $ilDB, and $result.

Referenced by ilRegistrationCodesTableGUI\initFilter().

+ Here is the caller graph for this function:

◆ isUnusedCode()

static ilRegistrationCode::isUnusedCode (   $code)
static

Check if code has been used already @global type $ilDB.

Parameters
type$code
Returns
boolean

Definition at line 195 of file class.ilRegistrationCode.php.

196 {
197 global $DIC;
198
199 $ilDB = $DIC['ilDB'];
200
201 $set = $ilDB->query("SELECT used FROM " . self::DB_TABLE . " WHERE code = " . $ilDB->quote($code, "text"));
202 $set = $ilDB->fetchAssoc($set);
203 if ($set && !$set["used"]) {
204 return true;
205 }
206 return false;
207 }

References $code, $DIC, and $ilDB.

Referenced by ilAccountCode\isUnusedCode().

+ Here is the caller graph for this function:

◆ isValidRegistrationCode()

static ilRegistrationCode::isValidRegistrationCode (   $a_code)
static

Check if given code is a valid registration code.

Parameters
string$a_codecode
Returns
bool

Definition at line 214 of file class.ilRegistrationCode.php.

215 {
216 global $DIC;
217
218 $ilDB = $DIC['ilDB'];
219
220 $query = 'SELECT code_id FROM reg_registration_codes ' .
221 'WHERE used = ' . $ilDB->quote(0, 'integer') . ' ' .
222 'AND reg_enabled = ' . $ilDB->quote(1, 'integer') . ' ' .
223 'AND code = ' . $ilDB->quote($a_code, 'text');
224 $res = $ilDB->query($query);
225
226 return $res->numRows() ? true : false;
227 }
$query
foreach($_POST as $key=> $value) $res

References $DIC, $ilDB, $query, and $res.

Referenced by ilAccountRegistrationGUI\saveForm().

+ Here is the caller graph for this function:

◆ loadCodesByIds()

static ilRegistrationCode::loadCodesByIds ( array  $ids)
static

Definition at line 105 of file class.ilRegistrationCode.php.

106 {
107 global $DIC;
108
109 $ilDB = $DIC['ilDB'];
110
111 $set = $ilDB->query("SELECT * FROM " . self::DB_TABLE . " WHERE " . $ilDB->in("code_id", $ids, false, "integer"));
112 $result = array();
113 while ($rec = $ilDB->fetchAssoc($set)) {
114 $result[] = $rec;
115 }
116 return $result;
117 }

References $DIC, $ilDB, and $result.

Referenced by ilRegistrationSettingsGUI\deleteConfirmation().

+ Here is the caller graph for this function:

◆ useCode()

static ilRegistrationCode::useCode (   $code)
static

Definition at line 229 of file class.ilRegistrationCode.php.

230 {
231 global $DIC;
232
233 $ilDB = $DIC['ilDB'];
234
235 return (bool) $ilDB->update(self::DB_TABLE, array("used" => array("timestamp", time())), array("code" => array("text", $code)));
236 }

References $code, $DIC, and $ilDB.

Referenced by ilAccountCode\useCode().

+ Here is the caller graph for this function:

Field Documentation

◆ CODE_LENGTH

const ilRegistrationCode::CODE_LENGTH = 10

◆ DB_TABLE

const ilRegistrationCode::DB_TABLE = 'reg_registration_codes'

Definition at line 15 of file class.ilRegistrationCode.php.


The documentation for this class was generated from the following file: