Combu Server  3.1.1
PHP API Documentation
CustomData.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Combu;
4 
10 class CustomData extends DataClass {
11 
12  const TABLE_NAME = "CustomData";
13 
14  public $IdAccount = 0;
15  public $DataKey = "";
16  public $DataValue = "";
17 
21  public function __construct($src = null, $stripSlashes = false) {
22  if ($src == null)
23  return;
24  if (is_array($src)) {
25  // Load by array
26  $this->_loadByRow($src, $stripSlashes);
27  }
28  }
29 
37  public static function Load ($idAccount, $returnArray = false) {
38  $where = sprintf("IdAccount = %d", $idAccount);
39  return self::_load(self::GetTableName(__CLASS__), ($returnArray ? "" : __CLASS__), $where);
40  }
41 
47  public function Save() {
48  global $Database;
49  $query = sprintf("REPLACE INTO %s (IdAccount, DataKey, DataValue) VALUES (%d, '%s', '%s')",
50  self::GetTableName(__CLASS__),
51  $this->IdAccount,
52  $Database->Escape($this->DataKey),
53  $Database->Escape($this->DataValue));
54  return $Database->Query($query);
55  }
56 
62  public function Delete() {
63  global $Database;
64  if ($this->IdAccount > 0 && $this->DataKey) {
65  return $this->_Delete(self::GetTableName(__CLASS__), sprintf("IdAccount = %d AND DataKey = '%s'", $this->IdAccount, $Database->Escape($this->DataKey)));
66  }
67  return FALSE;
68  }
69 
73  public static function Prune() {
74  self::TruncateClass(__CLASS__);
75  }
76 
84  public static function SetCustomData($idAccount, $key, $value) {
85  $data = new self();
86  $data->IdAccount = $idAccount;
87  $data->DataKey = $key;
88  $data->DataValue = $value;
89  return $data->Save();
90  }
91 
98  public static function DeleteCustomData($idAccount, $keys) {
99  if (!is_array($keys)) {
100  $keys = array($keys);
101  }
102  $success = FALSE;
103  foreach ($keys as $key) {
104  $data = new self();
105  $data->IdAccount = $idAccount;
106  $data->DataKey = $key;
107  if ($data->Delete()) {
108  $success = TRUE;
109  }
110  }
111  return $success;
112  }
113 }
static Load($idAccount, $returnArray=false)
Definition: CustomData.php:37
static DeleteCustomData($idAccount, $keys)
Definition: CustomData.php:98
Definition: Account.php:3
__construct($src=null, $stripSlashes=false)
Definition: CustomData.php:21
static SetCustomData($idAccount, $key, $value)
Definition: CustomData.php:84
static Prune()
Definition: CustomData.php:73