ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilShopTopics.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once 'Services/Payment/classes/class.ilShopTopic.php';
5 include_once 'Services/Payment/classes/class.ilGeneralSettings.php';
6 
17 {
18  private static $instance;
19 
20  private $db = null;
22  private $sorting_direction = 'ASC';
23  private $enable_custom_sorting = false;
24  private $id_filter = 0;
25  private $topics = array();
26 
30 
33 
34  private function __construct()
35  {
36  global $ilDB;
37 
38  $this->db = $ilDB;
39  }
40 
41  public static function _getInstance()
42  {
43  if(!isset(self::$instance))
44  {
45  self::$instance = new ilShopTopics();
46  }
47 
48  return self::$instance;
49  }
50 
51  public function read()
52  {
53  global $ilUser;
54 
55  $oSettings = new ilGeneralSettings();
56 
57  $this->topics = array();
58 
59  if(!in_array($this->getSortingType(), array(self::TOPICS_SORT_BY_TITLE, self::TOPICS_SORT_BY_CREATEDATE, self::TOPICS_SORT_MANUALLY)))
60  {
61  $this->setSortingType(self::DEFAULT_SORTING_TYPE);
62  }
63  if(!in_array(strtoupper($this->getSortingDirection()), array('ASC', 'DESC')))
64  {
65  $this->setSortingDirection(self::DEFAULT_SORTING_DIRECTION);
66  }
67 
68  if(!$this->isCustomSortingEnabled())
69  {
70 
71  $data_types = array();
72  $data_values = array();
73 
74  $query = 'SELECT * FROM payment_topics WHERE 1 = 1 ';
75  if((int)$this->getIdFilter() > 0)
76  {
77  $query .= ' AND pt_topic_pk = %s';
78  array_push($data_types, 'integer');
79  array_push($data_values, $this->getIdFilter());
80  }
81 
82  switch($this->getSortingType())
83  {
84  case 3:
85  $query .= ' ORDER BY pt_topic_sort ';
86  break;
87 
88  case 2:
89  $query .= ' ORDER BY pt_topic_created ';
90  break;
91 
92  case 1:
93  default:
94  $query .= ' ORDER BY pt_topic_title ';
95  break;
96  }
97  $query .= ' '.strtoupper($this->getSortingDirection()).' ';
98  $query .= " , pt_topic_title ";
99  $query .= ' '.strtoupper($this->getSortingDirection()).' ';
100 
101 
102  }
103  else
104  {
105 
106  $data_types = array();
107  $data_values = array();
108 
109  $query = 'SELECT * FROM payment_topics ';
110  switch($this->getSortingType())
111  {
112  case 3:
113  $query .= ' LEFT JOIN payment_topic_usr_sort ON
114  ptus_pt_topic_fk = pt_topic_pk AND
115  ptus_usr_id = %s';
116  array_push($data_types, 'integer');
117  array_push($data_values, $ilUser->getId());
118 
119  break;
120  }
121  $query .= ' WHERE 1 = 1 ';
122 
123  if((int)$this->id_filter > 0)
124  {
125  $query .= ' AND pt_topic_pk = %s';
126  array_push($data_types, 'integer');
127  array_push($data_values, $this->getIdFilter());
128  }
129 
130  switch($this->getSortingType())
131  {
132  case 3:
133  $query .= ' ORDER BY ptus_sorting ';
134  break;
135 
136  case 2:
137  $query .= ' ORDER BY pt_topic_created ';
138  break;
139 
140  case 1:
141  default:
142  $query .= ' ORDER BY pt_topic_title ';
143  break;
144  }
145  $query .= ' '.strtoupper($this->getSortingDirection()).' ';
146  $query .= " , pt_topic_sort ";
147  $query .= ' '.strtoupper($this->getSortingDirection()).' ';
148  }
149 
150  if(count($data_types) > 0 && count($data_values > 0))
151  {
152  $res = $this->db->queryf($query, $data_types, $data_values);
153  }
154  else
155  {
156  $res = $this->db->query($query);
157  }
158 
159  $counter = 0;
160  while($row = $this->db->fetchObject($res))
161  {
162  $oTopic = new ilShopTopic();
163  $oTopic->setId($row->pt_topic_pk);
164  $oTopic->setTitle($row->pt_topic_title);
165  $oTopic->setSorting($row->pt_topic_sort);
166  $oTopic->setCustomSorting((int)$row->ptus_sorting);
167  $oTopic->setCreateDate($row->pt_topic_created);
168  $oTopic->setChangeDate($row->pt_topic_changed);
169  $this->topics[$row->pt_topic_pk] = $oTopic;
170 
171  ++$counter;
172  }
173 
174  return $this;
175  }
176 
177  public function getTopics()
178  {
179  return is_array($this->topics) ? $this->topics : array();
180  }
181 
182  public function setIdFilter($a_id_filter)
183  {
184  $this->id_filter = $a_id_filter;
185  }
186  public function getIdFilter()
187  {
188  return $this->id_filter;
189  }
190  public function setSortingType($a_sorting_type)
191  {
192  $this->sorting_type = $a_sorting_type;
193  }
194  public function getSortingType()
195  {
196  return $this->sorting_type;
197  }
198  public function setSortingDirection($a_sorting_direction)
199  {
200  $this->sorting_direction = $a_sorting_direction;
201  }
202  public function getSortingDirection()
203  {
205  }
206  public function enableCustomSorting($a_enable_custom_sorting)
207  {
208  $this->enable_custom_sorting = (bool)$a_enable_custom_sorting;
209  }
210  public function isCustomSortingEnabled()
211  {
212  return (bool)$this->enable_custom_sorting;
213  }
214 }
215 ?>