ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 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.

References $code, $data, $id, $ilDB, and array.

Referenced by ilRegistrationSettingsGUI\createCodes().

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

◆ deleteCodes()

static ilRegistrationCode::deleteCodes ( array  $ids)
static

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

References $ilDB.

Referenced by ilRegistrationSettingsGUI\deleteCodes().

114  {
115  global $ilDB;
116 
117  if (sizeof($ids)) {
118  return $ilDB->manipulate("DELETE FROM " . self::DB_TABLE . " WHERE " . $ilDB->in("code_id", $ids, false, "integer"));
119  }
120  return false;
121  }
global $ilDB
+ 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 135 of file class.ilRegistrationCode.php.

References $ilDB, and array.

136  {
137  global $ilDB;
138 
139  $where = array();
140  if ($filter_code) {
141  $where[] = $ilDB->like("code", "text", "%" . $filter_code . "%");
142  }
143  if ($filter_role) {
144  $where[] ="role = " . $ilDB->quote($filter_role, "integer");
145  }
146  if ($filter_generated) {
147  $where[] ="generated_on = " . $ilDB->quote($filter_generated, "text");
148  }
149  if ($filter_access_limitation) {
150  $where[] ="alimit = " . $ilDB->quote($filter_access_limitation, "text");
151  }
152  if (sizeof($where)) {
153  return " WHERE " . implode(" AND ", $where);
154  } else {
155  return "";
156  }
157  }
Create styles array
The data for the language used.
global $ilDB

◆ generateRandomCode()

static ilRegistrationCode::generateRandomCode ( )
staticprotected

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

References $code.

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

◆ getCodeData()

static ilRegistrationCode::getCodeData (   $code)
static

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

References $code, $ilDB, and $row.

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

230  {
231  global $ilDB;
232 
233  $set = $ilDB->query("SELECT role, role_local, alimit, alimitdt, reg_enabled, ext_enabled" .
234  " FROM " . self::DB_TABLE .
235  " WHERE code = " . $ilDB->quote($code, "text"));
236  $row = $ilDB->fetchAssoc($set);
237  return $row;
238  }
$code
Definition: example_050.php:99
global $ilDB
+ Here is the caller graph for this function:

◆ getCodeRole()

static ilRegistrationCode::getCodeRole (   $code)
static

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

References $code, $ilDB, and $row.

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

219  {
220  global $ilDB;
221 
222  $set = $ilDB->query("SELECT role FROM " . self::DB_TABLE . " WHERE code = " . $ilDB->quote($code, "text"));
223  $row = $ilDB->fetchAssoc($set);
224  if (isset($row["role"])) {
225  return $row["role"];
226  }
227  }
$code
Definition: example_050.php:99
global $ilDB
+ 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 68 of file class.ilRegistrationCode.php.

References $ilDB, $result, and array.

Referenced by ilRegistrationCodesTableGUI\getItems().

69  {
70  global $ilDB;
71 
72  // filter
73  $where = self::filterToSQL($filter_code, $filter_role, $filter_generated, $filter_access_limitation);
74 
75  // count query
76  $set = $ilDB->query("SELECT COUNT(*) AS cnt FROM " . self::DB_TABLE . $where);
77  $cnt = 0;
78  if ($rec = $ilDB->fetchAssoc($set)) {
79  $cnt = $rec["cnt"];
80  }
81 
82  $sql = "SELECT * FROM " . self::DB_TABLE . $where;
83  if ($order_field) {
84  if ($order_field == 'generated') {
85  $order_field = 'generated_on';
86  }
87  $sql .= " ORDER BY " . $order_field . " " . $order_direction;
88  }
89 
90  // set query
91  $ilDB->setLimit((int) $limit, (int) $offset);
92  $set = $ilDB->query($sql);
93  $result = array();
94  while ($rec = $ilDB->fetchAssoc($set)) {
95  $rec['generated'] = $rec['generated_on'];
96  $result[] = $rec;
97  }
98  return array("cnt" => $cnt, "set" => $result);
99  }
$result
Create styles array
The data for the language used.
global $ilDB
+ 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 159 of file class.ilRegistrationCode.php.

References $ilDB, $result, and array.

Referenced by ilRegistrationSettingsGUI\exportCodes().

160  {
161  global $ilDB;
162 
163  // filter
164  $where = self::filterToSQL($filter_code, $filter_role, $filter_generated, $filter_access_limitation);
165 
166  // set query
167  $set = $ilDB->query("SELECT code FROM " . self::DB_TABLE . $where . " ORDER BY code_id");
168  $result = array();
169  while ($rec = $ilDB->fetchAssoc($set)) {
170  $result[] = $rec["code"];
171  }
172  return $result;
173  }
$result
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ getGenerationDates()

static ilRegistrationCode::getGenerationDates ( )
static

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

References $ilDB, $result, and array.

Referenced by ilRegistrationCodesTableGUI\initFilter().

124  {
125  global $ilDB;
126 
127  $set = $ilDB->query("SELECT DISTINCT(generated_on) genr FROM " . self::DB_TABLE . " ORDER BY genr");
128  $result = array();
129  while ($rec = $ilDB->fetchAssoc($set)) {
130  $result[] = $rec["genr"];
131  }
132  return $result;
133  }
$result
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ isUnusedCode()

static ilRegistrationCode::isUnusedCode (   $code)
static

Check if code has been used already type $ilDB.

Parameters
type$code
Returns
boolean

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

References $code, and $ilDB.

Referenced by ilAccountCode\isUnusedCode().

182  {
183  global $ilDB;
184 
185  $set = $ilDB->query("SELECT used FROM " . self::DB_TABLE . " WHERE code = " . $ilDB->quote($code, "text"));
186  $set = $ilDB->fetchAssoc($set);
187  if ($set && !$set["used"]) {
188  return true;
189  }
190  return false;
191  }
$code
Definition: example_050.php:99
global $ilDB
+ 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 198 of file class.ilRegistrationCode.php.

References $ilDB, $query, and $res.

Referenced by ilAccountRegistrationGUI\saveForm().

199  {
200  global $ilDB;
201 
202  $query = 'SELECT code_id FROM reg_registration_codes ' .
203  'WHERE used = ' . $ilDB->quote(0, 'integer') . ' ' .
204  'AND reg_enabled = ' . $ilDB->quote(1, 'integer') . ' ' .
205  'AND code = ' . $ilDB->quote($a_code, 'text');
206  $res = $ilDB->query($query);
207 
208  return $res->numRows() ? true : false;
209  }
foreach($_POST as $key=> $value) $res
$query
global $ilDB
+ Here is the caller graph for this function:

◆ loadCodesByIds()

static ilRegistrationCode::loadCodesByIds ( array  $ids)
static

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

References $ilDB, $result, and array.

Referenced by ilRegistrationSettingsGUI\deleteConfirmation().

102  {
103  global $ilDB;
104 
105  $set = $ilDB->query("SELECT * FROM " . self::DB_TABLE . " WHERE " . $ilDB->in("code_id", $ids, false, "integer"));
106  $result = array();
107  while ($rec = $ilDB->fetchAssoc($set)) {
108  $result[] = $rec;
109  }
110  return $result;
111  }
$result
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ useCode()

static ilRegistrationCode::useCode (   $code)
static

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

References $code, $ilDB, array, and time.

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

212  {
213  global $ilDB;
214 
215  return (bool) $ilDB->update(self::DB_TABLE, array("used"=>array("timestamp", time())), array("code"=>array("text", $code)));
216  }
$code
Definition: example_050.php:99
Create styles array
The data for the language used.
global $ilDB
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
+ 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: