Combu Server  3.1.1
PHP API Documentation
Achievement_User.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Combu;
4 
10 class Achievement_User extends DataClass {
11 
12  const TABLE_NAME = "Achievement_User";
13 
14  public $Id = 0;
15  public $IdAchievement = 0;
16  public $IdAccount = 0;
17  public $Progress = 0;
18  public $LastUpdated = "";
19 
23  public function __construct($src = null, $stripSlashes = false) {
24  if ($src == null) {
25  return;
26  }
27  if (is_array($src)) {
28  // Load by array
29  $this->_loadByRow($src, $stripSlashes);
30  } else if (is_numeric($src) && intval($src) > 0) {
31  // Load by Id
32  $this->_loadFilter(self::GetTableName(__CLASS__), "Id = " . intval($src));
33  }
34  }
35 
44  public static function LoadAccount ($idAccount, $idAchievement = 0, $returnArray = false) {
45  $where = sprintf("IdAccount = %d", $idAccount);
46  if ($idAchievement > 0) {
47  $where .= sprintf(" AND IdAchievement = %d", $idAchievement);
48  }
49  return self::_load(self::GetTableName(__CLASS__), ($returnArray ? "" : __CLASS__), $where, "IdAchievement");
50  }
51 
62  public static function Load ($idAchievement, $limit = null, $offset = null, &$count = null, $returnArray = false) {
63  $where = sprintf("au.IdAchievement = %d", $idAchievement);
64  return self::_loadEx("au.*", self::GetTableName(__CLASS__) . " au INNER JOIN " . self::GetTableName(Account::class) . " u ON u.Id = au.IdAccount", ($returnArray ? "" : __CLASS__), $where, "u.Username", $limit, $offset, $count);
65  }
66 
72  public function Save() {
73  global $Database;
74  $this->LastUpdated = date("Y-m-d H:i:s");
75  if ($this->Id < 1) {
76  $query = sprintf("INSERT INTO %s (IdAchievement, IdAccount, Progress, LastUpdated) VALUES (%d, %d, %d, %s)",
77  self::GetTableName(__CLASS__),
78  $this->IdAchievement,
79  $this->IdAccount,
80  $this->Progress,
81  $Database->EscapeDate($this->LastUpdated));
82  } else {
83  $query = sprintf("UPDATE %s SET Progress = %d, LastUpdated = %s WHERE Id = %d",
84  self::GetTableName(__CLASS__),
85  $this->Progress,
86  $Database->EscapeDate($this->LastUpdated),
87  $this->Id);
88  }
89  $saved = $Database->Query($query);
90  if ($saved) {
91  if ($this->Id <= 0) {
92  $this->Id = $Database->InsertedId();
93  }
94  return TRUE;
95  }
96  return FALSE;
97  }
98 
104  public function Delete() {
105  if ($this->Id < 1) {
106  return FALSE;
107  }
108  return $this->_Delete(self::GetTableName(__CLASS__), "Id = " . $this->Id);
109  }
110 
114  public static function Prune() {
115  self::TruncateClass(__CLASS__);
116  }
117 }
__construct($src=null, $stripSlashes=false)
static Load($idAchievement, $limit=null, $offset=null, &$count=null, $returnArray=false)
Definition: Account.php:3
static LoadAccount($idAccount, $idAchievement=0, $returnArray=false)