ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
4include_once 'Services/Payment/classes/class.ilShopTopic.php';
5//include_once 'Services/Payment/classes/class.ilPaymentSettings.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 $this->topics = array();
56
57 if(!in_array($this->getSortingType(), array(self::TOPICS_SORT_BY_TITLE, self::TOPICS_SORT_BY_CREATEDATE, self::TOPICS_SORT_MANUALLY)))
58 {
59 $this->setSortingType(self::DEFAULT_SORTING_TYPE);
60 }
61 if(!in_array(strtoupper($this->getSortingDirection()), array('ASC', 'DESC')))
62 {
63 $this->setSortingDirection(self::DEFAULT_SORTING_DIRECTION);
64 }
65
66 if(!$this->isCustomSortingEnabled())
67 {
68
69 $data_types = array();
70 $data_values = array();
71
72 $query = 'SELECT * FROM payment_topics WHERE 1 = 1 ';
73 if((int)$this->getIdFilter() > 0)
74 {
75 $query .= ' AND pt_topic_pk = %s';
76 array_push($data_types, 'integer');
77 array_push($data_values, $this->getIdFilter());
78 }
79
80 switch($this->getSortingType())
81 {
82 case 3:
83 $query .= ' ORDER BY pt_topic_sort ';
84 break;
85
86 case 2:
87 $query .= ' ORDER BY pt_topic_created ';
88 break;
89
90 case 1:
91 default:
92 $query .= ' ORDER BY pt_topic_title ';
93 break;
94 }
95 $query .= ' '.strtoupper($this->getSortingDirection()).' ';
96 $query .= " , pt_topic_title ";
97 $query .= ' '.strtoupper($this->getSortingDirection()).' ';
98
99
100 }
101 else
102 {
103
104 $data_types = array();
105 $data_values = array();
106
107 $query = 'SELECT * FROM payment_topics ';
108 switch($this->getSortingType())
109 {
110 case 3:
111 $query .= ' LEFT JOIN payment_topic_usr_sort ON
112 ptus_pt_topic_fk = pt_topic_pk AND
113 ptus_usr_id = %s';
114 array_push($data_types, 'integer');
115 array_push($data_values, $ilUser->getId());
116
117 break;
118 }
119 $query .= ' WHERE 1 = 1 ';
120
121 if((int)$this->id_filter > 0)
122 {
123 $query .= ' AND pt_topic_pk = %s';
124 array_push($data_types, 'integer');
125 array_push($data_values, $this->getIdFilter());
126 }
127
128 switch($this->getSortingType())
129 {
130 case 3:
131 $query .= ' ORDER BY ptus_sorting ';
132 break;
133
134 case 2:
135 $query .= ' ORDER BY pt_topic_created ';
136 break;
137
138 case 1:
139 default:
140 $query .= ' ORDER BY pt_topic_title ';
141 break;
142 }
143 $query .= ' '.strtoupper($this->getSortingDirection()).' ';
144 $query .= " , pt_topic_sort ";
145 $query .= ' '.strtoupper($this->getSortingDirection()).' ';
146 }
147
148 if(count($data_types) > 0 && count($data_values > 0))
149 {
150 $res = $this->db->queryf($query, $data_types, $data_values);
151 }
152 else
153 {
154 $res = $this->db->query($query);
155 }
156
157 $counter = 0;
158 while($row = $this->db->fetchObject($res))
159 {
160 $oTopic = new ilShopTopic();
161 $oTopic->setId($row->pt_topic_pk);
162 $oTopic->setTitle($row->pt_topic_title);
163 $oTopic->setSorting($row->pt_topic_sort);
164 $oTopic->setCustomSorting((int)$row->ptus_sorting);
165 $oTopic->setCreateDate($row->pt_topic_created);
166 $oTopic->setChangeDate($row->pt_topic_changed);
167 $this->topics[$row->pt_topic_pk] = $oTopic;
168
169 ++$counter;
170 }
171
172 return $this;
173 }
174
175 public function getTopics()
176 {
177 return is_array($this->topics) ? $this->topics : array();
178 }
179
180 public function setIdFilter($a_id_filter)
181 {
182 $this->id_filter = $a_id_filter;
183 }
184 public function getIdFilter()
185 {
186 return $this->id_filter;
187 }
188 public function setSortingType($a_sorting_type)
189 {
190 $this->sorting_type = $a_sorting_type;
191 }
192 public function getSortingType()
193 {
194 return $this->sorting_type;
195 }
196 public function setSortingDirection($a_sorting_direction)
197 {
198 $this->sorting_direction = $a_sorting_direction;
199 }
200 public function getSortingDirection()
201 {
203 }
204 public function enableCustomSorting($a_enable_custom_sorting)
205 {
206 $this->enable_custom_sorting = (bool)$a_enable_custom_sorting;
207 }
208 public function isCustomSortingEnabled()
209 {
210 return (bool)$this->enable_custom_sorting;
211 }
212
213 public function getCountAssignedTopics()
214 {
215 global $ilDB;
216
217 $res = $ilDB->query('SELECT pt_topic_fk, count(pt_topic_fk) cnt FROM payment_objects GROUP BY pt_topic_fk');
218
219 $topics_count = array();
220 while($row = $ilDB->fetchAssoc($res))
221 {
222 $topics_count[$row['pt_topic_fk']] = (int)$row['cnt'];
223 }
224
225 return $topics_count;
226 }
227}
228?>
Class ilShopTopic.
Class ilShopTopics.
setIdFilter($a_id_filter)
enableCustomSorting($a_enable_custom_sorting)
const DEFAULT_SORTING_DIRECTION
const TOPICS_SORT_BY_CREATEDATE
setSortingDirection($a_sorting_direction)
setSortingType($a_sorting_type)
global $ilDB
global $ilUser
Definition: imgupload.php:15