ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilTermsOfServiceTableDatabaseDataProvider.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/TermsOfService/interfaces/interface.ilTermsOfServiceTableDataProvider.php';
5
12{
16 protected $db;
17
21 public function __construct(ilDB $db)
22 {
23 $this->db = $db;
24 }
25
32 abstract protected function getSelectPart(array $params, array $filter);
33
40 abstract protected function getFromPart(array $params, array $filter);
41
48 abstract protected function getWherePart(array $params, array $filter);
49
56 abstract protected function getGroupByPart(array $params, array $filter);
57
64 abstract protected function getHavingPart(array $params, array $filter);
65
72 abstract protected function getOrderByPart(array $params, array $filter);
73
80 public function getList(array $params, array $filter)
81 {
82 $data = array(
83 'items' => array(),
84 'cnt' => 0
85 );
86
87 $select = $this->getSelectPart($params, $filter);
88 $where = $this->getWherePart($params, $filter);
89 $from = $this->getFromPart($params, $filter);
90 $order = $this->getOrderByPart($params, $filter);
91 $group = $this->getGroupByPart($params, $filter);
92 $having = $this->getHavingPart($params, $filter);
93
94 if(isset($params['limit']))
95 {
96 if(!is_numeric($params['limit']))
97 {
98 throw new InvalidArgumentException('Please provide a valid numerical limit.');
99 }
100
101 if(!isset($params['offset']))
102 {
103 $params['offset'] = 0;
104 }
105 else if(!is_numeric($params['offset']))
106 {
107 throw new InvalidArgumentException('Please provide a valid numerical offset.');
108 }
109
110 $this->db->setLimit($params['limit'], $params['offset']);
111 }
112
113 $where = strlen($where) ? 'WHERE ' . $where : '';
114 $query = "SELECT {$select} FROM {$from} {$where}";
115
116 if(strlen($group))
117 {
118 $query .= " GROUP BY {$group}";
119 }
120
121 if(strlen($having))
122 {
123 $query .= " HAVING {$having}";
124 }
125
126 if(strlen($order))
127 {
128 $query .= " ORDER BY {$order}";
129 }
130
131 $res = $this->db->query($query);
132 while($row = $this->db->fetchAssoc($res))
133 {
134 $data['items'][] = $row;
135 }
136
137 if(isset($params['limit']))
138 {
139 $cnt_sql = "SELECT COUNT(*) cnt FROM ({$query}) subquery";
140 $row_cnt = $this->db->fetchAssoc($this->db->query($cnt_sql));
141 $data['cnt'] = $row_cnt['cnt'];
142 }
143
144 return $data;
145 }
146}
Database Wrapper.
Definition: class.ilDB.php:29
getWherePart(array $params, array $filter)
getOrderByPart(array $params, array $filter)
getSelectPart(array $params, array $filter)
getGroupByPart(array $params, array $filter)
getFromPart(array $params, array $filter)
getHavingPart(array $params, array $filter)
$data
$params
Definition: example_049.php:96