ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilShopTopic.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
14 {
15  private $id = 0;
16  private $title = '';
17  private $sorting = 0;
18  private $createdate = 0;
19  private $changedate = 0;
20  private $custom_sorting = 0;
21 
22  private $db = null;
23 
24  public function __construct($a_id = 0)
25  {
26  global $ilDB;
27 
28  $this->db = $ilDB;
29 
30  if($a_id)
31  {
32  $this->id = $a_id;
33 
34  $this->read();
35  }
36  }
37 
38  private function read()
39  {
40  global $ilUser;
41 
42  if($this->id)
43  {
44  $result = $this->db->queryf('
45  SELECT * FROM payment_topics
46  LEFT JOIN payment_topic_usr_sort ON ptus_pt_topic_fk = pt_topic_pk
47  AND ptus_usr_id = %s
48  WHERE pt_topic_pk = %s',
49  array('integer', 'integer'),
50  array($ilUser->getId(), $this->id));
51 
52  while($row = $this->db->fetchObject($result))
53  {
54  $this->setTitle($row->pt_topic_title);
55  $this->setSorting($row->pt_topic_sort);
56  $this->setCreateDate($row->pt_topic_created);
57  $this->setChangeDate($row->pt_topic_changed);
58  $this->setCustomSorting($row->ptus_sorting);
59 
60  return true;
61  }
62  }
63 
64  return false;
65  }
66 
67  public function save()
68  {
69  if($this->id)
70  {
71  $this->changedate = time();
72 
73  $statement = $this->db->manipulateF('
74  UPDATE payment_topics
75  SET pt_topic_title = %s,
76  pt_topic_sort = %s,
77  pt_topic_changed = %s
78  WHERE pt_topic_pk = %s',
79  array('text', 'integer', 'integer', 'integer'),
80  array(
81  $this->getTitle(),
82  $this->getSorting(),
83  $this->getChangeDate(),
84  $this->getId()
85  ));
86 
87 
88 
89  return true;
90  }
91  else
92  {
93  $this->createdate = time();
94 
95  $next_id = $this->db->nextId('payment_topics');
96  $statement = $this->db->manipulateF('
97  INSERT INTO payment_topics
98  ( pt_topic_pk,
99  pt_topic_title,
100  pt_topic_sort,
101  pt_topic_created
102  ) VALUES (%s, %s, %s, %s)',
103  array('integer','text', 'integer', 'integer'),
104  array($next_id, $this->getTitle(), $this->getSorting(), $this->getCreateDate()));
105 
106  $this->id = $next_id;
107  if($this->id) return true;
108  }
109 
110  return false;
111  }
112 
113  function delete()
114  {
115  if($this->id)
116  {
117 
118  $result = $this->db->manipulateF('
119  DELETE FROM payment_topics
120  WHERE pt_topic_pk = %s',
121  array('integer'),
122  array($this->getId())
123  );
124 
125  $result = $this->db->manipulateF('
126  DELETE FROM payment_topic_usr_sort
127  WHERE ptus_pt_topic_fk = %s',
128  array('integer'),
129  array($this->getId())
130  );
131 
132  $result = $this->db->manipulateF('
133  UPDATE payment_objects
134  SET pt_topic_fk = %s
135  WHERE pt_topic_fk = %s',
136  array('integer', 'integer'),
137  array(0, $this->getId())
138  );
139 
140  return true;
141  }
142 
143  return false;
144  }
145 
146  public static function _lookupTitle($a_id)
147  {
148  global $ilDB;
149 
150  $result = $ilDB->queryf("SELECT pt_topic_title FROM payment_topics WHERE pt_topic_pk = %s",
151  array('integer'), array($a_id));
152 
153  while($row = $ilDB->fetchObject($result))
154  {
155  return $row->pt_topic_title;
156  }
157 
158  return false;
159  }
160 
161  public function saveCustomSorting()
162  {
163  global $ilUser;
164 
165  if($this->id)
166  {
167  $res = $this->db->queryf('
168  SELECT * FROM payment_topic_usr_sort
169  WHERE ptus_pt_topic_fk = %s
170  AND ptus_usr_id = %s',
171  array('integer', 'integer'),
172  array($this->getId(), $ilUser->getId())
173  );
174 
175  if($this->db->numRows($res) > 0)
176  {
177  $statement = $this->db->manipulateF('
178  UPDATE payment_topic_usr_sort
179  SET ptus_sorting = %s
180  WHERE ptus_usr_id = %s
181  AND ptus_pt_topic_fk = %s',
182  array('integer', 'integer', 'integer'),
183  array( $this->getCustomSorting(),$ilUser->getId(), $this->getId())
184  );
185  }
186  else
187  {
188  $statement = $this->db->manipulateF('
189  INSERT INTO payment_topic_usr_sort
190  ( ptus_pt_topic_fk,
191  ptus_usr_id,
192  ptus_sorting
193  ) VALUES (%s,%s,%s)',
194  array('integer', 'integer', 'integer'),
195  array($this->getId(), $ilUser->getId(), $this->getCustomSorting())
196  );
197  }
198 
199  return true;
200  }
201 
202  return false;
203  }
204 
205  public function setId($a_id)
206  {
207  $this->id = $a_id;
208  }
209  public function getId()
210  {
211  return $this->id;
212  }
213  public function setTitle($a_title)
214  {
215  $this->title = $a_title;
216  }
217  public function getTitle()
218  {
219  return $this->title;
220  }
221  public function setCreateDate($a_createdate)
222  {
223  $this->createdate = $a_createdate;
224  }
225  public function getCreateDate()
226  {
227  return $this->createdate;
228  }
229  public function setChangeDate($a_changedate)
230  {
231  $this->changedate = $a_changedate;
232  }
233  public function getChangeDate()
234  {
235  return $this->changedate;
236  }
237  public function setSorting($a_sorting)
238  {
239  $this->sorting = $a_sorting;
240  }
241  public function getSorting()
242  {
243  return $this->sorting;
244  }
245  public function setCustomSorting($a_custom_sorting)
246  {
247  $this->custom_sorting = $a_custom_sorting;
248  }
249  public function getCustomSorting()
250  {
251  return $this->custom_sorting;
252  }
253 }
254 ?>