Typo
[AOOS.git] / modules / News / NewsHandler.php
blob3873a2e3625b568710dba8e6045a2864e36cd7d5
1 <?php
3 /**
4 * NewsHandler
5 * @author Sebastian Skejø
6 */
8 class NewsHandler {
9 private $_storageObj = null;
10 private $_sort = null;
12 private function _restore() {
13 $this->_storageObj->setTable("News");
14 $this->_storageObj->setSort($this->_sort);
17 public function __construct($core) {
18 parent::__construct($core);
20 $this->_storageObj = $this->core()->newStorageDevice();
21 $this->_storageObj->setTable("News");
22 $this->_storageObj->setSort("DESC");
25 public function getNewsList($fields = "*", $where = null, $limit = null, $order = "TIMESTAMP") {
26 return $this->_storageObj()->selectModel($fields, $where, $limit, $order);
29 /**
30 * Returns a model containing the data of the current piece of news
32 public function getNews($newsID) {
33 $where = array(
34 "NEWSID" => $newsID
37 $m = $this->getNewsList("*", $where);
39 return $m;
42 /**
43 * Returns an AOOSModel containing all data for comments to $newsID
44 * @return AOOSModel
46 public function getCommentList($newsID, $limit = null) {
47 $this->_storageObj->setTable("News_comments");
48 $this->_storageObj->setSort("ASC"); // We want comments to be in ascending order
50 $where = array(
51 "NEWSID" => $newsID
54 $model = $this->_storageObj->selectModel("*", $where, $limit, "TIMESTAMP");
56 $this->_restore();
58 return $model;
61 public function setSort($sort) {
62 if ($this->_storageObj->setSort($sort)) {
63 $this->_sort = $sort;
65 return true;
68 /**
69 * Deletes a piece of news and all related comments
70 * @param int $newsID The piece of news to be deleted
72 public function deleteNews($newsID) {
73 if (!$this->core()->getModule("User")->checkLevel("admin")) {
74 throw new AOOSException($this->core(), $this->tr("access_denied", "User"), "", true, 1);
75 return false;
78 $where = array(
79 "NEWSID" => $newsID
82 $this->_storageObj->deleteFromArray($where);
84 // Delete comments
85 $this->_storageObj->setTable("News_comments");
86 $this->_storageObj->deleteFromArray($where);
87 $this->_restore();
89 return true;
92 /**
93 * Updates a piece of news
95 public function updateNews(AOOSModel $news) {
96 return true;
99 /**
100 * Creates a new piece of news in the database
102 public function createNews(AOOSModel $news) {
103 return true;
106 // vim: number