ILIAS  release_4-4 Revision
ilAccountCode Class Reference

Class ilAccountCode. More...

+ Collaboration diagram for ilAccountCode:

Static Public Member Functions

static create ($valid_until, $stamp)
 
static getCodesData ($order_field, $order_direction, $offset, $limit, $filter_code, $filter_valid_until, $filter_generated)
 
static loadCodesByIds (array $ids)
 
static deleteCodes (array $ids)
 
static getGenerationDates ()
 
static getCodesForExport ($filter_code, $filter_valid_until, $filter_generated)
 
static isUnusedCode ($code)
 
static useCode ($code)
 
static getCodeValidUntil ($code)
 

Data Fields

const DB_TABLE = 'usr_account_codes'
 
const CODE_LENGTH = 10
 

Static Protected Member Functions

static generateRandomCode ()
 
static filterToSQL ($filter_code, $filter_valid_until, $filter_generated)
 

Detailed Description

Class ilAccountCode.

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
Id
class.ilRegistrationSettingsGUI.php 23797 2010-05-07 15:54:03Z jluetzen

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

Member Function Documentation

◆ create()

static ilAccountCode::create (   $valid_until,
  $stamp 
)
static

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

References $data.

Referenced by ilAccountCodesGUI\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  $data = array(
34  'code_id' => array('integer', $id),
35  'code' => array('text', $code),
36  'generated' => array('integer', $stamp),
37  'valid_until' => array('text', $valid_until)
38  );
39 
40  $ilDB->insert(self::DB_TABLE, $data);
41  return $id;
42  }
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
+ Here is the caller graph for this function:

◆ deleteCodes()

static ilAccountCode::deleteCodes ( array  $ids)
static

Definition at line 103 of file class.ilAccountCode.php.

Referenced by ilAccountCodesGUI\deleteCodes().

104  {
105  global $ilDB;
106 
107  if(sizeof($ids))
108  {
109  return $ilDB->manipulate("DELETE FROM ".self::DB_TABLE." WHERE ".$ilDB->in("code_id", $ids, false, "integer"));
110  }
111  return false;
112  }
+ Here is the caller graph for this function:

◆ filterToSQL()

static ilAccountCode::filterToSQL (   $filter_code,
  $filter_valid_until,
  $filter_generated 
)
staticprotected

Definition at line 127 of file class.ilAccountCode.php.

128  {
129  global $ilDB;
130 
131  $where = array();
132  if($filter_code)
133  {
134  $where[] = $ilDB->like("code", "text", "%".$filter_code."%");
135  }
136  if($filter_valid_until)
137  {
138  $where[] ="valid_until = ".$ilDB->quote($filter_valid_until, "text");
139  }
140  if($filter_generated)
141  {
142  $where[] ="generated = ".$ilDB->quote($filter_generated, "text");
143  }
144  if(sizeof($where))
145  {
146  return " WHERE ".implode(" AND ", $where);
147  }
148  else
149  {
150  return "";
151  }
152  }

◆ generateRandomCode()

static ilAccountCode::generateRandomCode ( )
staticprotected

Definition at line 44 of file class.ilAccountCode.php.

45  {
46  // missing : 01iloO
47  $map = "23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
48 
49  $code = "";
50  $max = strlen($map)-1;
51  for($loop = 1; $loop <= self::CODE_LENGTH; $loop++)
52  {
53  $code .= $map[mt_rand(0, $max)];
54  }
55  return $code;
56  }

◆ getCodesData()

static ilAccountCode::getCodesData (   $order_field,
  $order_direction,
  $offset,
  $limit,
  $filter_code,
  $filter_valid_until,
  $filter_generated 
)
static

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

References $result.

Referenced by ilAccountCodesTableGUI\getItems().

59  {
60  global $ilDB;
61 
62  // filter
63  $where = self::filterToSQL($filter_code, $filter_valid_until, $filter_generated);
64 
65  // count query
66  $set = $ilDB->query("SELECT COUNT(*) AS cnt FROM ".self::DB_TABLE.$where);
67  $cnt = 0;
68  if ($rec = $ilDB->fetchAssoc($set))
69  {
70  $cnt = $rec["cnt"];
71  }
72 
73  $sql = "SELECT * FROM ".self::DB_TABLE.$where;
74  if($order_field)
75  {
76  $sql .= " ORDER BY ".$order_field." ".$order_direction;
77  }
78 
79  // set query
80  $ilDB->setLimit((int)$limit, (int)$offset);
81  $set = $ilDB->query($sql);
82  $result = array();
83  while($rec = $ilDB->fetchAssoc($set))
84  {
85  $result[] = $rec;
86  }
87  return array("cnt" => $cnt, "set" => $result);
88  }
$result
+ Here is the caller graph for this function:

◆ getCodesForExport()

static ilAccountCode::getCodesForExport (   $filter_code,
  $filter_valid_until,
  $filter_generated 
)
static

Definition at line 154 of file class.ilAccountCode.php.

References $result.

Referenced by ilAccountCodesGUI\exportCodes().

155  {
156  global $ilDB;
157 
158  // filter
159  $where = self::filterToSQL($filter_code, $filter_valid_until, $filter_generated);
160 
161  // set query
162  $set = $ilDB->query("SELECT code FROM ".self::DB_TABLE.$where." ORDER BY code_id");
163  $result = array();
164  while($rec = $ilDB->fetchAssoc($set))
165  {
166  $result[] = $rec["code"];
167  }
168  return $result;
169  }
$result
+ Here is the caller graph for this function:

◆ getCodeValidUntil()

static ilAccountCode::getCodeValidUntil (   $code)
static

Definition at line 191 of file class.ilAccountCode.php.

References $row.

Referenced by ilStartUpGUI\processCode().

192  {
193  global $ilDB;
194 
195  $set = $ilDB->query("SELECT valid_until FROM ".self::DB_TABLE." WHERE code = ".$ilDB->quote($code, "text"));
196  $row = $ilDB->fetchAssoc($set);
197  if(isset($row["valid_until"]))
198  {
199  return $row["valid_until"];
200  }
201  }
+ Here is the caller graph for this function:

◆ getGenerationDates()

static ilAccountCode::getGenerationDates ( )
static

Definition at line 114 of file class.ilAccountCode.php.

References $result.

Referenced by ilAccountCodesTableGUI\initFilter().

115  {
116  global $ilDB;
117 
118  $set = $ilDB->query("SELECT DISTINCT(generated) AS generated FROM ".self::DB_TABLE." ORDER BY generated");
119  $result = array();
120  while($rec = $ilDB->fetchAssoc($set))
121  {
122  $result[] = $rec["generated"];
123  }
124  return $result;
125  }
$result
+ Here is the caller graph for this function:

◆ isUnusedCode()

static ilAccountCode::isUnusedCode (   $code)
static

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

Referenced by ilStartUpGUI\processCode().

172  {
173  global $ilDB;
174 
175  $set = $ilDB->query("SELECT used FROM ".self::DB_TABLE." WHERE code = ".$ilDB->quote($code, "text"));
176  $set = $ilDB->fetchAssoc($set);
177  if($set && !$set["used"])
178  {
179  return true;
180  }
181  return false;
182  }
+ Here is the caller graph for this function:

◆ loadCodesByIds()

static ilAccountCode::loadCodesByIds ( array  $ids)
static

Definition at line 90 of file class.ilAccountCode.php.

References $result.

Referenced by ilAccountCodesGUI\deleteConfirmation().

91  {
92  global $ilDB;
93 
94  $set = $ilDB->query("SELECT * FROM ".self::DB_TABLE." WHERE ".$ilDB->in("code_id", $ids, false, "integer"));
95  $result = array();
96  while($rec = $ilDB->fetchAssoc($set))
97  {
98  $result[] = $rec;
99  }
100  return $result;
101  }
$result
+ Here is the caller graph for this function:

◆ useCode()

static ilAccountCode::useCode (   $code)
static

Definition at line 184 of file class.ilAccountCode.php.

Referenced by ilStartUpGUI\processCode().

185  {
186  global $ilDB;
187 
188  return (bool)$ilDB->update(self::DB_TABLE, array("used"=>array("timestamp", time())), array("code"=>array("text", $code)));
189  }
+ Here is the caller graph for this function:

Field Documentation

◆ CODE_LENGTH

const ilAccountCode::CODE_LENGTH = 10

Definition at line 16 of file class.ilAccountCode.php.

Referenced by ilAccountCodesTableGUI\initFilter().

◆ DB_TABLE

const ilAccountCode::DB_TABLE = 'usr_account_codes'

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


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