ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilShopVatsList.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 require_once 'Services/Payment/classes/class.ilShopVats.php';
5 require_once 'Services/Payment/classes/class.ilShopUtils.php';
6 
16 class ilShopVatsList implements Iterator
17 {
18  private $db = null;
19  private $num_vat_list = 0;
20  private $vat_list = array();
21 
32  public static function _isVATAlreadyCreated($a_vat_rate, $a_vat_id = null)
33  {
34  global $ilDB;
35 
36  $types = array();
37  $data = array();
38 
39  $query = "SELECT * FROM payment_vats "
40  . "WHERE vat_rate = ? ";
41  $types[] = 'float';
42  $data[] = (float)$a_vat_rate;
43 
44  if((int)$a_vat_id)
45  {
46  $query .= "AND vat_id != ? ";
47  $types[] = 'integer';
48  $data[] = $a_vat_id;
49  }
50 
51  $statement = $ilDB->prepare(trim($query), $types);
52  $result = $ilDB->execute($statement, $data);
53  while($row = $ilDB->fetchObject($result))
54  {
55  return true;
56  }
57 
58  return false;
59  }
60 
67  public function __construct()
68  {
69  global $ilDB;
70 
71  $this->db = $ilDB;
72  }
73 
81  public function read()
82  {
83  $this->vat_list = array();
84 
85  $query = "SELECT * FROM payment_vats ";
86  $query.= "WHERE 1 = 1 ";
87  if(!in_array($this->getOrderColumn(), array('vat_title', 'vat_rate')))
88  {
89  $this->setOrderColumn('vat_rate');
90  $this->setOrderDirection('ASC');
91  }
92 
93  $order_limit = " ORDER BY ".$this->getOrderColumn()." ".strtoupper($this->getOrderDirection())." ";
94  if((int)$this->getListMax())
95  {
96  $order_limit .= "LIMIT ".$this->getListStart().", ".$this->getListMax();
97  }
98 
99  $res = $this->db->query($query.$order_limit);
100  while($row = $this->db->fetchObject($res))
101  {
102  $oVAT = new ilShopVats();
103  $oVAT->setId($row->vat_id);
104  $oVAT->setTitle($row->vat_title);
105  $oVAT->setRate($row->vat_rate);
106 
107  $this->vat_list[$oVAT->getId()] = $oVAT;
108  }
109 
110  $res = $this->db->query(str_replace('*', 'COUNT(vat_id) AS num_vat_list', $query));
111  while($row = $this->db->fetchObject($res))
112  {
113  $this->num_vat_list = $row->num_vat_list;
114  break;
115  }
116 
117  return $this;
118  }
119 
120  public function getNumItems()
121  {
122  return $this->num_vat_list;
123  }
124  public function hasItems()
125  {
126  return (bool)count($this->vat_list);
127  }
128  public function getItems()
129  {
130  return is_array($this->vat_list) ? $this->vat_list : array();
131  }
132  public function rewind()
133  {
134  return reset($this->vat_list);
135  }
136  public function valid()
137  {
138  return (bool)current($this->vat_list);
139  }
140  public function current()
141  {
142  return current($this->vat_list);
143  }
144  public function key()
145  {
146  return key($this->vat_list);
147  }
148  public function next()
149  {
150  return next($this->vat_list);
151  }
152 
161  public function setOrderColumn($a_order_column)
162  {
163  $this->order_column = $a_order_column;
164 
165  return $this;
166  }
174  public function getOrderColumn()
175  {
176  return $this->order_column;
177  }
186  public function setOrderDirection($a_order_column)
187  {
188  $this->order_direction = $a_order_column;
189 
190  return $this;
191  }
199  public function getOrderDirection()
200  {
201  return $this->order_direction;
202  }
211  public function setListStart($a_list_start)
212  {
213  $this->list_start = $a_list_start;
214 
215  return $this;
216  }
224  public function getListStart()
225  {
226  return $this->list_start;
227  }
236  public function setListMax($a_list_max)
237  {
238  $this->list_max = $a_list_max;
239 
240  return $this;
241  }
249  public function getListMax()
250  {
251  return $this->list_max;
252  }
253 }
254 ?>