ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
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 $data, and $ilDB.

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  {
28  $code = self::generateRandomCode();
29  $chk = $ilDB->queryF("SELECT code_id FROM ".self::DB_TABLE." WHERE code = %s", array("text"), array($code));
30  $found = (bool)$ilDB->numRows($chk);
31  }
32 
33  if(is_array($local_roles))
34  {
35  $local_roles = implode(";", $local_roles);
36  }
37  if($limit == "relative" && is_array($limit_date))
38  {
39  $limit_date = serialize($limit_date);
40  }
41 
42  $data = array(
43  'code_id' => array('integer', $id),
44  'code' => array('text', $code),
45  'generated' => array('integer', $stamp),
46  'role' => array('integer', $role),
47  'role_local' => array('text', $local_roles),
48  'alimit' => array('text', $limit),
49  'alimitdt' => array('text', $limit_date),
50  'reg_enabled' => array('integer',$reg_type),
51  'ext_enabled' => array('integer',$ext_type)
52  );
53 
54  $ilDB->insert(self::DB_TABLE, $data);
55  return $id;
56  }
global $ilDB
+ Here is the caller graph for this function:

◆ deleteCodes()

static ilRegistrationCode::deleteCodes ( array  $ids)
static

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

References $ilDB.

Referenced by ilRegistrationSettingsGUI\deleteCodes().

118  {
119  global $ilDB;
120 
121  if(sizeof($ids))
122  {
123  return $ilDB->manipulate("DELETE FROM ".self::DB_TABLE." WHERE ".$ilDB->in("code_id", $ids, false, "integer"));
124  }
125  return false;
126  }
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 141 of file class.ilRegistrationCode.php.

References $ilDB.

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

◆ generateRandomCode()

static ilRegistrationCode::generateRandomCode ( )
staticprotected

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

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

◆ getCodeData()

static ilRegistrationCode::getCodeData (   $code)
static

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

References $ilDB, and $row.

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

246  {
247  global $ilDB;
248 
249  $set = $ilDB->query("SELECT role, role_local, alimit, alimitdt, reg_enabled, ext_enabled".
250  " FROM ".self::DB_TABLE.
251  " WHERE code = ".$ilDB->quote($code, "text"));
252  $row = $ilDB->fetchAssoc($set);
253  return $row;
254  }
global $ilDB
+ Here is the caller graph for this function:

◆ getCodeRole()

static ilRegistrationCode::getCodeRole (   $code)
static

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

References $ilDB, and $row.

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

234  {
235  global $ilDB;
236 
237  $set = $ilDB->query("SELECT role FROM ".self::DB_TABLE." WHERE code = ".$ilDB->quote($code, "text"));
238  $row = $ilDB->fetchAssoc($set);
239  if(isset($row["role"]))
240  {
241  return $row["role"];
242  }
243  }
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 72 of file class.ilRegistrationCode.php.

References $ilDB, and $result.

Referenced by ilRegistrationCodesTableGUI\getItems().

73  {
74  global $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  {
84  $cnt = $rec["cnt"];
85  }
86 
87  $sql = "SELECT * FROM ".self::DB_TABLE.$where;
88  if($order_field)
89  {
90  $sql .= " ORDER BY ".$order_field." ".$order_direction;
91  }
92 
93  // set query
94  $ilDB->setLimit((int)$limit, (int)$offset);
95  $set = $ilDB->query($sql);
96  $result = array();
97  while($rec = $ilDB->fetchAssoc($set))
98  {
99  $result[] = $rec;
100  }
101  return array("cnt" => $cnt, "set" => $result);
102  }
$result
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 172 of file class.ilRegistrationCode.php.

References $ilDB, and $result.

Referenced by ilRegistrationSettingsGUI\exportCodes().

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

◆ getGenerationDates()

static ilRegistrationCode::getGenerationDates ( )
static

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

References $ilDB, and $result.

Referenced by ilRegistrationCodesTableGUI\initFilter().

129  {
130  global $ilDB;
131 
132  $set = $ilDB->query("SELECT DISTINCT(generated) AS generated FROM ".self::DB_TABLE." ORDER BY generated");
133  $result = array();
134  while($rec = $ilDB->fetchAssoc($set))
135  {
136  $result[] = $rec["generated"];
137  }
138  return $result;
139  }
$result
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 195 of file class.ilRegistrationCode.php.

References $ilDB.

Referenced by ilAccountCode\isUnusedCode().

196  {
197  global $ilDB;
198 
199  $set = $ilDB->query("SELECT used FROM ".self::DB_TABLE." WHERE code = ".$ilDB->quote($code, "text"));
200  $set = $ilDB->fetchAssoc($set);
201  if($set && !$set["used"])
202  {
203  return true;
204  }
205  return false;
206  }
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 213 of file class.ilRegistrationCode.php.

References $ilDB, $query, and $res.

Referenced by ilAccountRegistrationGUI\saveForm().

214  {
215  global $ilDB;
216 
217  $query = 'SELECT code_id FROM reg_registration_codes '.
218  'WHERE used = '.$ilDB->quote(0,'integer').' '.
219  'AND reg_enabled = '.$ilDB->quote(1,'integer').' '.
220  'AND code = '.$ilDB->quote($a_code,'text');
221  $res = $ilDB->query($query);
222 
223  return $res->numRows() ? true : false;
224  }
global $ilDB
+ Here is the caller graph for this function:

◆ loadCodesByIds()

static ilRegistrationCode::loadCodesByIds ( array  $ids)
static

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

References $ilDB, and $result.

Referenced by ilRegistrationSettingsGUI\deleteConfirmation().

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

◆ useCode()

static ilRegistrationCode::useCode (   $code)
static

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

References $ilDB.

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

227  {
228  global $ilDB;
229 
230  return (bool)$ilDB->update(self::DB_TABLE, array("used"=>array("timestamp", time())), array("code"=>array("text", $code)));
231  }
global $ilDB
+ 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: