12 const TABLE_NAME =
"Inventory";
15 public $IdAccount = 0;
19 public $CustomData =
"";
24 public function __construct($src = null, $stripSlashes =
false) {
30 $this->_loadByRow($src, $stripSlashes);
31 }
else if (is_numeric($src) && intval($src) > 0) {
33 $this->_loadFilter(self::GetTableName(__CLASS__),
"Id = " . intval($src));
36 $this->_loadFilter(self::GetTableName(__CLASS__),
"Name = '" . $Database->Escape($src) .
"' ORDER BY Id");
48 public static function Load ($idAccount, $returnArray =
false) {
50 $where = sprintf(
"IdAccount = %d", $idAccount);
51 if ($AppId->IsValid()) {
52 $where .= sprintf(
" AND IdApp = %d", $AppId->Id);
54 return self::_load(self::GetTableName(__CLASS__), ($returnArray ?
"" : __CLASS__), $where);
66 public static function LoadOrCreate ($idAccount, $itemName, $returnArray =
false) {
67 global $Database, $AppId;
69 $where = sprintf(
"IdAccount = %d AND Name = '%s'", $idAccount, $Database->Escape($itemName));
70 if ($AppId->IsValid()) {
71 $where .= sprintf(
" AND IdApp = %d", $AppId->Id);
73 $recs = self::_load(self::GetTableName(__CLASS__), ($returnArray ?
"" : __CLASS__), $where);
74 if (count($recs) > 0) {
79 $rec->IdAccount = $idAccount;
80 $rec->Name = $itemName;
91 global $Database, $AppId;
93 $query = sprintf(
"UPDATE %s SET Quantity = %d, CustomData = '%s' WHERE Id = %d",
94 self::GetTableName(__CLASS__),
96 $Database->Escape($this->CustomData),
99 $query = sprintf(
"INSERT INTO %s (IdAccount, IdApp, Name, Quantity, CustomData) VALUES (%d, %d, '%s', %d, '%s')",
100 self::GetTableName(__CLASS__),
103 $Database->Escape($this->Name),
107 if ($Database->Query($query)) {
109 $this->Id = $Database->InsertedId();
123 return $this->_Delete(self::GetTableName(__CLASS__),
"Id = " . $this->Id);
132 self::TruncateClass(__CLASS__);
__construct($src=null, $stripSlashes=false)
static LoadOrCreate($idAccount, $itemName, $returnArray=false)
static Load($idAccount, $returnArray=false)