ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
22 public function __construct(ilDBInterface $db)
23 {
24 $this->db = $db;
25 }
26
33 abstract protected function getSelectPart(array $params, array $filter);
34
41 abstract protected function getFromPart(array $params, array $filter);
42
49 abstract protected function getWherePart(array $params, array $filter);
50
57 abstract protected function getGroupByPart(array $params, array $filter);
58
65 abstract protected function getHavingPart(array $params, array $filter);
66
73 abstract protected function getOrderByPart(array $params, array $filter);
74
81 public function getList(array $params, array $filter)
82 {
83 $data = array(
84 'items' => array(),
85 'cnt' => 0
86 );
87
88 $select = $this->getSelectPart($params, $filter);
89 $where = $this->getWherePart($params, $filter);
90 $from = $this->getFromPart($params, $filter);
91 $order = $this->getOrderByPart($params, $filter);
92 $group = $this->getGroupByPart($params, $filter);
93 $having = $this->getHavingPart($params, $filter);
94
95 if(isset($params['limit']))
96 {
97 if(!is_numeric($params['limit']))
98 {
99 throw new InvalidArgumentException('Please provide a valid numerical limit.');
100 }
101
102 if(!isset($params['offset']))
103 {
104 $params['offset'] = 0;
105 }
106 else if(!is_numeric($params['offset']))
107 {
108 throw new InvalidArgumentException('Please provide a valid numerical offset.');
109 }
110
111 $this->db->setLimit($params['limit'], $params['offset']);
112 }
113
114 $where = strlen($where) ? 'WHERE ' . $where : '';
115 $query = "SELECT {$select} FROM {$from} {$where}";
116
117 if(strlen($group))
118 {
119 $query .= " GROUP BY {$group}";
120 }
121
122 if(strlen($having))
123 {
124 $query .= " HAVING {$having}";
125 }
126
127 if(strlen($order))
128 {
129 $query .= " ORDER BY {$order}";
130 }
131
132 $res = $this->db->query($query);
133 while($row = $this->db->fetchAssoc($res))
134 {
135 $data['items'][] = $row;
136 }
137
138 if(isset($params['limit']))
139 {
140 $cnt_sql = "SELECT COUNT(*) cnt FROM ({$query}) subquery";
141 $row_cnt = $this->db->fetchAssoc($this->db->query($cnt_sql));
142 $data['cnt'] = $row_cnt['cnt'];
143 }
144
145 return $data;
146 }
147}
An exception for terminatinating execution or to throw for unit testing.
getWherePart(array $params, array $filter)
getOrderByPart(array $params, array $filter)
getSelectPart(array $params, array $filter)
getGroupByPart(array $params, array $filter)
__construct(ilDBInterface $db)
ilTermsOfServiceTableDatabaseDataProvider constructor.
getFromPart(array $params, array $filter)
getHavingPart(array $params, array $filter)
$params
Definition: example_049.php:96
Interface ilDBInterface.