ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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

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

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

References generateRandomCode().

Referenced by ilAccountCodesGUI\createCodes().

{
global $ilDB;
$id = $ilDB->nextId(self::DB_TABLE);
// create unique code
$found = true;
while ($found)
{
$chk = $ilDB->queryF("SELECT code_id FROM ".self::DB_TABLE." WHERE code = %s", array("text"), array($code));
$found = (bool)$ilDB->numRows($chk);
}
$data = array(
'code_id' => array('integer', $id),
'code' => array('text', $code),
'generated' => array('integer', $stamp),
'valid_until' => array('text', $valid_until)
);
$ilDB->insert(self::DB_TABLE, $data);
return $id;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilAccountCode::deleteCodes ( array  $ids)
static

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

{
global $ilDB;
if(sizeof($ids))
{
return $ilDB->manipulate("DELETE FROM ".self::DB_TABLE." WHERE ".$ilDB->in("code_id", $ids, false, "integer"));
}
return false;
}
static ilAccountCode::filterToSQL (   $filter_code,
  $filter_valid_until,
  $filter_generated 
)
staticprotected

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

Referenced by getCodesData(), and getCodesForExport().

{
global $ilDB;
$where = array();
if($filter_code)
{
$where[] = $ilDB->like("code", "text", "%".$filter_code."%");
}
if($filter_valid_until)
{
$where[] ="valid_until = ".$ilDB->quote($filter_valid_until, "text");
}
if($filter_generated)
{
$where[] ="generated = ".$ilDB->quote($filter_generated, "text");
}
if(sizeof($where))
{
return " WHERE ".implode(" AND ", $where);
}
else
{
return "";
}
}

+ Here is the caller graph for this function:

static ilAccountCode::generateRandomCode ( )
staticprotected

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

References CODE_LENGTH.

Referenced by create().

{
// missing : 01iloO
$map = "23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
$code = "";
$max = strlen($map)-1;
for($loop = 1; $loop <= self::CODE_LENGTH; $loop++)
{
$code .= $map[mt_rand(0, $max)];
}
return $code;
}

+ Here is the caller graph for this function:

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, and filterToSQL().

Referenced by ilAccountCodesTableGUI\getItems().

{
global $ilDB;
// filter
$where = self::filterToSQL($filter_code, $filter_valid_until, $filter_generated);
// count query
$set = $ilDB->query("SELECT COUNT(*) AS cnt FROM ".self::DB_TABLE.$where);
$cnt = 0;
if ($rec = $ilDB->fetchAssoc($set))
{
$cnt = $rec["cnt"];
}
$sql = "SELECT * FROM ".self::DB_TABLE.$where;
if($order_field)
{
$sql .= " ORDER BY ".$order_field." ".$order_direction;
}
// set query
$ilDB->setLimit((int)$limit, (int)$offset);
$set = $ilDB->query($sql);
$result = array();
while($rec = $ilDB->fetchAssoc($set))
{
$result[] = $rec;
}
return array("cnt" => $cnt, "set" => $result);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

References $result, and filterToSQL().

Referenced by ilAccountCodesGUI\exportCodes().

{
global $ilDB;
// filter
$where = self::filterToSQL($filter_code, $filter_valid_until, $filter_generated);
// set query
$set = $ilDB->query("SELECT code FROM ".self::DB_TABLE.$where." ORDER BY code_id");
$result = array();
while($rec = $ilDB->fetchAssoc($set))
{
$result[] = $rec["code"];
}
return $result;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilAccountCode::getCodeValidUntil (   $code)
static

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

References $row.

Referenced by ilStartUpGUI\processCode().

{
global $ilDB;
$set = $ilDB->query("SELECT valid_until FROM ".self::DB_TABLE." WHERE code = ".$ilDB->quote($code, "text"));
$row = $ilDB->fetchAssoc($set);
if(isset($row["valid_until"]))
{
return $row["valid_until"];
}
}

+ Here is the caller graph for this function:

static ilAccountCode::getGenerationDates ( )
static

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

References $result.

Referenced by ilAccountCodesTableGUI\initFilter().

{
global $ilDB;
$set = $ilDB->query("SELECT DISTINCT(generated) AS generated FROM ".self::DB_TABLE." ORDER BY generated");
$result = array();
while($rec = $ilDB->fetchAssoc($set))
{
$result[] = $rec["generated"];
}
return $result;
}

+ Here is the caller graph for this function:

static ilAccountCode::isUnusedCode (   $code)
static

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

Referenced by ilStartUpGUI\processCode().

{
global $ilDB;
$set = $ilDB->query("SELECT used FROM ".self::DB_TABLE." WHERE code = ".$ilDB->quote($code, "text"));
$set = $ilDB->fetchAssoc($set);
if($set && !$set["used"])
{
return true;
}
return false;
}

+ Here is the caller graph for this function:

static ilAccountCode::loadCodesByIds ( array  $ids)
static

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

References $result.

Referenced by ilAccountCodesGUI\deleteConfirmation().

{
global $ilDB;
$set = $ilDB->query("SELECT * FROM ".self::DB_TABLE." WHERE ".$ilDB->in("code_id", $ids, false, "integer"));
$result = array();
while($rec = $ilDB->fetchAssoc($set))
{
$result[] = $rec;
}
return $result;
}

+ Here is the caller graph for this function:

static ilAccountCode::useCode (   $code)
static

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

Referenced by ilStartUpGUI\processCode().

{
global $ilDB;
return (bool)$ilDB->update(self::DB_TABLE, array("used"=>array("timestamp", time())), array("code"=>array("text", $code)));
}

+ Here is the caller graph for this function:

Field Documentation

const ilAccountCode::CODE_LENGTH = 10
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: