Combu Server  3.1.1
PHP API Documentation
LeaderBoard_User.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Combu;
4 
10 class LeaderBoard_User extends DataClass {
11 
12  const TABLE_NAME = "LeaderBoard_User";
13 
14  public $Id = 0;
15  public $IdLeaderboard = 0;
16  public $IdAccount = 0;
17  public $Username = "";
18  public $ValueInt = 0;
19  public $ValueFloat = 0;
20  public $ValueString = "";
21  public $LastUpdated = "";
22 
26  public function __construct($src = null, $stripSlashes = false) {
27  if ($src == null)
28  return;
29  if (is_array($src)) {
30  // Load by array
31  $this->_loadByRow($src, $stripSlashes);
32  } else if (is_numeric($src) && intval($src) > 0) {
33  // Load by Id
34  $this->_loadFilter(self::GetTableName(__CLASS__), "Id = " . intval($src));
35  }
36  }
37 
46  public static function LoadAccount ($idAccount, $idLeaderboard = 0, $returnArray = false) {
47  $where = sprintf("IdAccount = %d", $idAccount);
48  if ($idLeaderboard > 0)
49  $where .= sprintf(" AND IdLeaderboard = %d", $idLeaderboard);
50  return self::_load(self::GetTableName(__CLASS__), ($returnArray ? "" : __CLASS__), $where);
51  }
52 
64  public static function Load ($idLeaderboard, $order, $limit = null, $offset = null, &$count = null, $returnArray = false) {
65  $where = sprintf("al.IdLeaderboard = %d", $idLeaderboard);
66  return self::_loadEx("al.*", self::GetTableName(__CLASS__) . " al INNER JOIN " . self::GetTableName(Account::class) . " u ON u.Id = al.IdAccount", ($returnArray ? "" : __CLASS__), $where, $order, $limit, $offset, $count);
67  }
68 
74  public function Save() {
75  global $Database;
76  if ($this->Id < 1) {
77  $query = sprintf("INSERT INTO %s (IdLeaderboard, IdAccount, Username, ValueInt, ValueFloat, LastUpdated) VALUES (%d, %d, '%s', %d, %f, '%s')",
78  self::GetTableName(__CLASS__),
79  $this->IdLeaderboard,
80  $this->IdAccount,
81  $Database->Escape($this->Username),
82  $this->ValueInt,
83  $this->ValueFloat,
84  date("Y-m-d H:i:s"));
85  } else {
86  $query = sprintf("UPDATE %s SET Username = '%s', ValueInt = %d, ValueFloat = %f, LastUpdated = '%s' WHERE Id = %d",
87  self::GetTableName(__CLASS__),
88  $Database->Escape($this->Username),
89  $this->ValueInt,
90  $this->ValueFloat,
91  date("Y-m-d H:i:s"),
92  $this->Id);
93  }
94  $saved = $Database->Query($query);
95  if ($saved) {
96  if ($this->Id <= 0)
97  $this->Id = $Database->InsertedId();
98  return TRUE;
99  }
100  return FALSE;
101  }
102 
108  public function Delete() {
109  if ($this->Id < 1)
110  return FALSE;
111  return $this->_Delete(self::GetTableName(__CLASS__), "Id = " . $this->Id);
112  }
113 
118  public static function Prune() {
119  self::TruncateClass(__CLASS__);
120  }
121 }
static LoadAccount($idAccount, $idLeaderboard=0, $returnArray=false)
static Load($idLeaderboard, $order, $limit=null, $offset=null, &$count=null, $returnArray=false)
__construct($src=null, $stripSlashes=false)
Definition: Account.php:3