Combu Server  3.1.1
PHP API Documentation
News.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Combu;
4 
10 class News extends DataClass {
11 
12  const TABLE_NAME = "News";
13 
14  public $Id = 0;
15  public $IdApp = 0;
16  public $IdAdminAccount = 0;
17  public $PublishDate = "";
18  public $Subject = "";
19  public $Message = "";
20  public $Url = "";
21 
25  public function __construct($src = null, $stripSlashes = false) {
26  global $Database;
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 
48  public static function Load ($idApp = 0, $limit = null, $offset = null, &$count = null, $returnArray = false) {
49  global $AppId;
50  $where = "";
51  if ($AppId->IsValid()) {
52  $where = sprintf("(IdApp = 0 OR IdApp = %d)", $AppId->Id);
53  }
54  if ($idApp > 0) {
55  $where = sprintf("(IdApp = %d)", $idApp);
56  }
57  return self::_load(self::GetTableName(__CLASS__), ($returnArray ? "" : __CLASS__), $where, "PublishDate DESC", $limit, $offset, $count);
58  }
59 
65  public function Save() {
66  global $Database;
67  if ($this->Id > 0) {
68  $query = sprintf("UPDATE %s SET Subject = '%s', Message = '%s', Url = '%s' WHERE Id = %d",
69  self::GetTableName(__CLASS__),
70  $Database->Escape($this->Subject),
71  $Database->Escape($this->Message),
72  $Database->Escape($this->Url),
73  $this->Id);
74  } else {
75  $this->PublishDate = Utils::GetCurrentDateTimeFormat();
76  $query = sprintf("INSERT INTO %s (IdApp, PublishDate, IdAdminAccount, Subject, Message, Url) VALUES (%d, %s, %d, '%s', '%s', '%s')",
77  self::GetTableName(__CLASS__),
78  $this->IdApp,
79  $Database->EscapeDate($this->PublishDate),
80  $this->IdAdminAccount,
81  $Database->Escape($this->Subject),
82  $Database->Escape($this->Message),
83  $Database->Escape($this->Url));
84  }
85  if ($Database->Query($query)) {
86  if ($this->Id < 1) {
87  $this->Id = $Database->InsertedId();
88  }
89  return TRUE;
90  }
91  return FALSE;
92  }
93 
99  public function Delete() {
100  if ($this->Id > 0) {
101  return $this->_Delete(self::GetTableName(__CLASS__), "Id = " . $this->Id);
102  }
103  return FALSE;
104  }
105 }
Delete()
Definition: News.php:99
__construct($src=null, $stripSlashes=false)
Definition: News.php:25
static Load($idApp=0, $limit=null, $offset=null, &$count=null, $returnArray=false)
Definition: News.php:48
Definition: Account.php:3
Save()
Definition: News.php:65