ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilShopNewsItemList.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
9 class ilShopNewsItemList implements Iterator
10 {
11  const TYPE_NEWS = 1;
12  const TYPE_ARCHIVE = 2;
13 
14  private static $instance = null;
15 
16  private $news = array();
18  private $archive_date = null;
19  private $public_section = false;
20 
21  private function __construct()
22  {
23  }
24 
25  private function __clone()
26  {
27  }
28 
29  public function hasItems()
30  {
31  return (bool)count($this->news);
32  }
33 
34  public function rewind()
35  {
36  return reset($this->news);
37  }
38 
39  public function valid()
40  {
41  return (bool)current($this->news);
42  }
43 
44  public function current()
45  {
46  return current($this->news);
47  }
48 
49  public function key()
50  {
51  return key($this->news);
52  }
53 
54  public function next()
55  {
56  return next($this->news);
57  }
58 
59  public function _getInstance()
60  {
61  if(!isset(self::$instance))
62  {
63  self::$instance = new ilShopNewsItemList();
64  }
65 
66  return self::$instance;
67  }
68 
69  public function read()
70  {
71  global $ilDB;
72 
73  $this->news = array();
74 
75  $types = array();
76  $data = array();
77 
78  $query = 'SELECT * FROM payment_news WHERE 1 = 1 ';
79  if($this->isPublicSection())
80  {
81  $query .= "AND visibility = %s ";
82  $types[] = 'text';
83  $data[] = 'public';
84  }
85  if($this->getArchiveDate() !== null && $this->getArchiveDate() > 0)
86  {
87  switch($this->getMode())
88  {
89  case self::TYPE_NEWS:
90  $query .= "AND creation_date >= %s ";
91  $types[] = 'timestamp';
92  $data[] = date('Y-m-d H:i:s', $this->getArchiveDate());
93  break;
94 
95  case self::TYPE_ARCHIVE:
96  $query .= "AND creation_date < %s ";
97  $types[] = 'timestamp';
98  $data[] = date('Y-m-d H:i:s', $this->getArchiveDate());
99  break;
100  }
101  }
102  $query .= 'ORDER BY update_date DESC ';
103 
104  $result = $ilDB->queryF($query, $types, $data);
105 
106  while($record = $ilDB->fetchAssoc($result))
107  {
108  $oNewsItem = new ilShopNewsItem();
109  $oNewsItem->setId($record['news_id']);
110  $oNewsItem->setCreationDate($record['creation_date']);
111  $oNewsItem->setUpdateDate($record['update_date']);
112  $oNewsItem->setTitle($record['news_title']);
113  $oNewsItem->setContent($record['news_content']);
114  $oNewsItem->setVisibility($record['visibility']);
115  $oNewsItem->setUserId($record['user_id']);
116 
117  $this->news[] = $oNewsItem;
118  }
119 
120  return $this;
121  }
122 
123  public function reload()
124  {
125  $this->read();
126 
127  return $this;
128  }
129 
130  public function setArchiveDate($a_archive_date)
131  {
132  $this->archive_date = $a_archive_date;
133 
134  return $this;
135  }
136  public function getArchiveDate()
137  {
138  return $this->archive_date;
139  }
140  public function setPublicSection($a_public_section)
141  {
142  $this->public_section = $a_public_section;
143 
144  return $this;
145  }
146  public function isPublicSection()
147  {
148  return $this->public_section;
149  }
150  public function setMode($a_mode)
151  {
152  $this->mode = $a_mode;
153 
154  return $this;
155  }
156  public function getMode()
157  {
158  return $this->mode;
159  }
160 }
161 ?>