Combu Server  3.1.1
PHP API Documentation
UserFileActivity.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Combu;
4 
10 class UserFileActivity extends DataClass {
11 
12  const TABLE_NAME = "UserFilesActivity";
13 
14  public $Id = 0;
15  public $IdFile = 0;
16  public $IdAccount = 0;
17  public $Likes = 0;
18  public $Views = 0;
19  public $LastActivity = "";
20 
24  public function __construct($src = null, $stripSlashes = false) {
25  global $Database;
26  if ($src == null)
27  return;
28  if (is_array($src)) {
29  // Load by array
30  $this->_loadByRow($src, $stripSlashes);
31  } else if (is_numeric($src) && intval($src) > 0) {
32  // Load by Id
33  $this->_loadFilter(self::GetTableName(__CLASS__), "Id = " . intval($src));
34  }
35  }
36 
45  public static function Load ($idFile = 0, $idAccount = 0, $returnArray = false) {
46  $where = "";
47  if ($idFile > 0)
48  $where .= ($where ? " AND " : "") . sprintf("(IdFile = %d)", $idFile);
49  if ($idAccount > 0)
50  $where .= ($where ? " AND " : "") . sprintf("(IdAccount = %d)", $idAccount);
51  return self::_load(self::GetTableName(__CLASS__), ($returnArray ? "" : __CLASS__), $where);
52  }
53 
59  public function Save() {
60  global $Database;
61  $this->LastActivity = date("Y-m-d H:i:s");
62  if ($this->Id > 0) {
63  $query = sprintf("UPDATE %s SET Likes = %d, Views = %d, LastActivity = %s WHERE Id = %d",
64  self::GetTableName(__CLASS__),
65  $this->Likes,
66  $this->Views,
67  $Database->EscapeDate($this->LastActivity),
68  $this->Id);
69  } else {
70  $query = sprintf("INSERT INTO %s (IdFile, IdAccount, LastActivity, Likes, Views) VALUES (%d, %d, %s, %d, %d)",
71  self::GetTableName(__CLASS__),
72  $this->IdFile,
73  $this->IdAccount,
74  $Database->EscapeDate($this->LastActivity),
75  $this->Likes,
76  $this->Views);
77  }
78  if ($Database->Query($query)) {
79  if ($this->Id < 1)
80  $this->Id = $Database->InsertedId();
81  return TRUE;
82  }
83  return FALSE;
84  }
85 
91  public function Delete() {
92  if ($this->Id < 1)
93  return FALSE;
94  return $this->_Delete(self::GetTableName(__CLASS__), "Id = " . $this->Id);
95  }
96 }
static Load($idFile=0, $idAccount=0, $returnArray=false)
Definition: Account.php:3
__construct($src=null, $stripSlashes=false)