ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilShopVats.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.ilGeneralSettings.php';
5 include_once 'Services/Payment/exceptions/class.ilShopException.php';
6 include_once 'Services/Payment/classes/class.ilShopUtils.php';
7 
18 {
19  private $id = 0;
20  private $title = '';
21  private $rate = 0;
22 
30  public function __construct($a_vat_id = 0)
31  {
32  global $ilDB, $lng;
33 
34  $this->db = $ilDB;
35  $this->lng = $lng;
36 
37  if((int)$a_vat_id && $a_vat_id > 0)
38  {
39  $this->id = $a_vat_id;
40  $this->read();
41  }
42  }
43 
50  private function read()
51  {
52  if((int)$this->id)
53  {
54 
55  $res = $this->db->queryf('SELECT * FROM payment_vats
56  WHERE vat_id = %s',
57  array('integer'), array($this->id) );
58 
59  while($row = $this->db->fetchObject($res))
60  {
61  $this->setTitle($row->vat_title);
62  $this->setRate($row->vat_rate);
63 
64  return true;
65  }
66 
67  throw new ilShopException($this->lng->txt('payment_cannot_find_vat'));
68  }
69 
70  throw new ilShopException($this->lng->txt('payment_cannot_read_nonexisting_vat'));
71  }
72 
81  public function reloadFromDatabase()
82  {
83  $this->read();
84 
85  return $this;
86  }
87 
95  public function update()
96  {
97  if((int)$this->id)
98  {
99  if(ilShopVatsList::_isVATAlreadyCreated($this->rate, $this->id))
100  {
101  throw new ilShopException($this->lng->txt('payment_vat_already_created'));
102  }
103 
104 
105  $this->db->manipulatef('
106  UPDATE payment_vats
107  SET vat_title = %s,
108  vat_rate = %s
109  WHERE vat_id = %s',
110  array('text', 'float', 'integer'),
111  array($this->getTitle(),$this->getRate(),$this->getId())
112  );
113 
114  return true;
115  }
116 
117  throw new ilShopException($this->lng->txt('payment_cannot_update_nonexisting_vat'));
118  }
119 
127  public function save()
128  {
129  if(!(int)$this->id)
130  {
131  if(ilShopVatsList::_isVATAlreadyCreated($this->rate))
132  {
133  throw new ilShopException($this->lng->txt('payment_vat_already_created'));
134  }
135 
136  $next_id = $this->db->nextId('payment_vats');
137 
138  $this->db->manipulateF('
139  INSERT INTO payment_vats
140  (vat_id, vat_title, vat_rate)
141  VALUES (%s,%s,%s)',
142  array('integer', 'text', 'float'),
143  array($next_id, $this->getTitle(), $this->getRate())
144  );
145  return true;
146  }
147 
148  throw new ilShopException($this->lng->txt('payment_cannot_save_existing_vat'));
149  }
150 
158  public function delete()
159  {
160  if((int)$this->id)
161  {
162  $result = $this->db->queryF('
163  SELECT * FROM payment_objects
164  WHERE vat_id = %s',
165  array('integer'),
166  array($this->getId())
167  );
168 
169  while($row = $this->db->fetchObject($result))
170  {
171  throw new ilShopException(sprintf($this->lng->txt('paya_vat_not_deleted'), $this->title));
172  }
173 
174  $this->db->manipulateF('
175  DELETE FROM payment_vats
176  WHERE vat_id = %s',
177  array('integer'),
178  array($this->getId())
179 
180  );
181  return true;
182  }
183 
184  throw new ilShopException($this->lng->txt('payment_cannot_delete_nonexisting_vat'));
185  }
186 
194  public function setTitle($a_title)
195  {
196  $this->title = $a_title;
197 
198  return $this;
199  }
200  public function getTitle()
201  {
202  return $this->title;
203  }
211  public function setId($a_id)
212  {
213  $this->id = $a_id;
214 
215  return $this;
216  }
217  public function getId()
218  {
219  return $this->id;
220  }
228  public function setRate($a_rate)
229  {
230  $this->rate = $a_rate;
231 
232  return $this;
233  }
234  public function getRate()
235  {
236  return $this->rate;
237  }
238 }
239 
240 ?>