ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilShopNewsItem.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
10 {
11  private $id = 0;
12  private $title = '';
13  private $content = '';
14  private $creation_date = null;
15  private $update_date = null;
16  private $user_id = 0;
17  private $visibility = 'users';
18 
24  public function __construct($a_id = 0)
25  {
26  if((int)$a_id > 0)
27  {
28  $this->setId((int)$a_id);
29  $this->read();
30  }
31  }
32 
38  public function setId($a_id)
39  {
40  $this->id = $a_id;
41  }
42 
48  public function getId()
49  {
50  return $this->id;
51  }
52 
58  public function setTitle($a_title)
59  {
60  $this->title = $a_title;
61  }
62 
68  public function getTitle()
69  {
70  return $this->title;
71  }
72 
78  public function setContent($a_content)
79  {
80  $this->content = $a_content;
81  }
82 
88  public function getContent()
89  {
90  return $this->content;
91  }
92 
93 
99  public function setCreationDate($a_creation_date)
100  {
101  $this->creation_date = $a_creation_date;
102  }
103 
109  public function getCreationDate()
110  {
111  return $this->creation_date;
112  }
113 
119  public function setUpdateDate($a_update_date)
120  {
121  $this->update_date = $a_update_date;
122  }
123 
129  public function getUpdateDate()
130  {
131  return $this->update_date;
132  }
133 
139  public function setVisibility($a_visibility = 'users')
140  {
141  $this->visibility = $a_visibility;
142  }
143 
149  public function getVisibility()
150  {
151  return $this->visibility;
152  }
153 
159  public function setUserId($a_user_id)
160  {
161  $this->user_id = $a_user_id;
162  }
163 
169  public function getUserId()
170  {
171  return $this->user_id;
172  }
173 
178  public function create()
179  {
180  global $ilDB;
181 
182  $createdate = new ilDateTime(time(), IL_CAL_UNIX);
183 
184  $next_id = $ilDB->nextId('payment_news');
185  if((int)$next_id)
186  {
187  $ilDB->insert('payment_news', array(
188  'news_id' => array('integer', $next_id),
189  'news_title' => array('text', $this->getTitle()),
190  'news_content' => array('clob', $this->getContent()),
191  'visibility' => array('text', $this->getVisibility()),
192  'creation_date' => array('timestamp', $createdate->get(IL_CAL_DATETIME)),
193  'update_date' => array('timestamp', $createdate->get(IL_CAL_DATETIME)),
194  'user_id' => array('integer', $this->getUserId())
195  ));
196  $this->id = $next_id;
197  return true;
198  }
199 
200  return false;
201  }
202 
207  private function read()
208  {
209  global $ilDB;
210 
211  $result = $ilDB->queryf('SELECT * FROM payment_news WHERE news_id = %s',
212  array('integer'),
213  array($this->getId())
214  );
215 
216  while($record = $ilDB->fetchAssoc($result))
217  {
218  $this->setTitle($record['news_title']);
219  $this->setCreationDate($record['creation_date']);
220  $this->setVisibility($record['visibility']);
221  $this->setContent($record['news_content']);
222  $this->setUpdateDate($record['update_date']);
223  $this->setUserId($record['user_id']);
224  break;
225  }
226  }
227 
232  public function update()
233  {
234  global $ilDB;
235 
236  $updatedate = new ilDateTime(time(), IL_CAL_UNIX);
237 
238  if((int)$this->getId())
239  {
240  $ilDB->update('payment_news',
241  array(
242  'news_title' => array('text', $this->getTitle()),
243  'news_content' => array('clob', $this->getContent()),
244  'visibility' => array('text', $this->getVisibility()),
245  'update_date' => array('timestamp', $updatedate->get(IL_CAL_DATETIME)),
246  'user_id' => array('integer', $this->getUserId())
247  ),
248  array(
249  'news_id' => array('integer', $this->getId())
250  )
251  );
252 
253  return true;
254  }
255 
256  return false;
257  }
258 
263  public function delete()
264  {
265  global $ilDB;
266 
267  if((int)$this->getId())
268  {
269  $query = 'DELETE FROM payment_news WHERE news_id = %s';
270  $statement = $ilDB->manipulateF($query, array('integer'),array($this->getId()));
271 
272  return true;
273  }
274 
275  return false;
276  }
277 }
278 ?>