-
Notifications
You must be signed in to change notification settings - Fork 0
/
News.php
128 lines (107 loc) · 3.23 KB
/
News.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/**
* @file library/Zwe/Model/News.php
* Il modello delle news.
*
* @category Zwe
* @package Zwe_Model
* @version $Id: News.php 158 2011-09-01 16:09:08Z flicofloc@gmail.com $
*/
/**
* Il modello delle news.
*
* @uses Zwe_Model
* @category Zwe
* @package Zwe_Model
*/
class Zwe_Model_News extends Zwe_Model
{
protected $_name = 'news';
protected $_primary = 'IDNews';
protected $_author = null;
/**
* Ritorna le news di una determinata pagina.
* Se non sono presenti ritorna un array vuoto.
*
* @static
* @param int $IDPage L'identificativo della pagina di cui si vogliono estrarre le news
* @param int $Count
* @param int $Offset
*
* @return array
*/
public static function getPageNews($IDPage, $Count = null, $Offset = null)
{
$Ret = array();
$N = new self();
$News = $N->fetchAll("IDPage = '$IDPage' AND IsComment = '0'", 'Date DESC', $Count, $Offset);
if($News)
{
foreach($News as $New)
{
$N = new self();
$N->copyFromDb($New);
$N->Author = Zwe_Model_User::getUserById($N->IDAuthor);
$Ret[] = $N;
}
}
return $Ret;
}
public static function getNewsByID($IDNews)
{
$News = new self();
$News->fetchRowAndSet("IDNews = '$IDNews'");
$News->Author = Zwe_Model_User::getUserById($News->IDAuthor);
return $News;
}
public static function addNews($Title, $IDPage, $Text)
{
$News = new self();
$Data = array('Title' => $Title, 'IDPage' => $IDPage, 'Text' => $Text, 'IDAuthor' => Zend_Auth::getInstance()->getIdentity()->IDUser, 'Date' => new Zend_Db_Expr('NOW()'));
return $News->insert($Data);
}
public static function editNews($IDNews, $Title, $IDPage, $Text)
{
$News = new self();
$Data = array('Title' => $Title, 'IDPage' => $IDPage, 'Text' => $Text);
return $News->update($Data, "IDNews = '$IDNews'");
}
public static function deleteNews($IDNews)
{
$News = new self();
return $News->delete("IDNews = '$IDNews'");
}
public static function parentNews($IDNews, $IDPage)
{
$News = new self();
$Data = array('IDPage' => $IDPage);
return $News->update($Data, "IDNews = '$IDNews'");
}
public function toForm()
{
return array('title' => $this->Title,
'page' => $this->IDPage,
'text' => $this->Text,
'id' => $this->IDNews);
}
public function __get($Name)
{
if('Author' == $Name)
return $this->_author;
else
return parent::__get($Name);
}
public function __set($Name, $Value)
{
if('Author' == $Name)
{
if($Value instanceof Zwe_Model_User)
$this->_author = $Value;
else
throw new Exception('$value is not the expected value');
}
else
parent::__set($Name, $Value);
}
}
?>