Combu Server  3.1.1
PHP API Documentation
AppCustomData.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Combu;
4 
10 class AppCustomData extends DataClass {
11 
12  const TABLE_NAME = "AppCustomData";
13 
14  public $IdAccount = 0;
15  public $IdApp = 0;
16  public $DataKey = "";
17  public $DataValue = "";
18 
22  public function __construct($src = null, $stripSlashes = false) {
23  if (!empty($src) && is_array($src)) {
24  // Load by array
25  $this->_loadByRow($src, $stripSlashes);
26  }
27  }
28 
37  public static function Load ($idApp, $idAccount, $returnArray = false) {
38  $where = sprintf("IdApp = %d AND IdAccount = %d", $idApp, $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, IdApp, DataKey, DataValue) VALUES (%d, %d, '%s', '%s')",
50  self::GetTableName(__CLASS__),
51  $this->IdAccount,
52  $this->IdApp,
53  $Database->Escape($this->DataKey),
54  $Database->Escape($this->DataValue));
55  return $Database->Query($query);
56  }
57 
63  public function Delete() {
64  global $Database;
65  if ($this->IdApp > 0 && $this->IdAccount > 0 && !empty($this->DataKey)) {
66  return $this->_Delete(self::GetTableName(__CLASS__), sprintf("IdApp = %d AND IdAccount = %d AND DataKey = '%s'", $this->IdApp, $this->IdAccount, $Database->Escape($this->DataKey)));
67  }
68  return FALSE;
69  }
70 
74  public static function Prune() {
75  self::TruncateClass(__CLASS__);
76  }
77 
86  public static function SetCustomData($idApp, $idAccount, $key, $value) {
87  $data = new self();
88  $data->IdApp = $idApp;
89  $data->IdAccount = $idAccount;
90  $data->DataKey = $key;
91  $data->DataValue = $value;
92  return $data->Save();
93  }
94 
102  public static function DeleteCustomData($idApp, $idAccount, $keys) {
103  if (!is_array($keys)) {
104  $keys = array($keys);
105  }
106  $success = FALSE;
107  foreach ($keys as $key) {
108  $data = new self();
109  $data->IdApp = $idApp;
110  $data->IdAccount = $idAccount;
111  $data->DataKey = $key;
112  if ($data->Delete()) {
113  $success = TRUE;
114  }
115  }
116  return $success;
117  }
118 }
static Load($idApp, $idAccount, $returnArray=false)
static DeleteCustomData($idApp, $idAccount, $keys)
static SetCustomData($idApp, $idAccount, $key, $value)
Definition: Account.php:3
__construct($src=null, $stripSlashes=false)