ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 if (!is_numeric($params['limit'])) {
97 throw new InvalidArgumentException('Please provide a valid numerical limit.');
98 }
99
100 if (!isset($params['offset'])) {
101 $params['offset'] = 0;
102 } elseif (!is_numeric($params['offset'])) {
103 throw new InvalidArgumentException('Please provide a valid numerical offset.');
104 }
105
106 $this->db->setLimit($params['limit'], $params['offset']);
107 }
108
109 $where = strlen($where) ? 'WHERE ' . $where : '';
110 $query = "SELECT {$select} FROM {$from} {$where}";
111
112 if (strlen($group)) {
113 $query .= " GROUP BY {$group}";
114 }
115
116 if (strlen($having)) {
117 $query .= " HAVING {$having}";
118 }
119
120 if (strlen($order)) {
121 $query .= " ORDER BY {$order}";
122 }
123
124 $res = $this->db->query($query);
125 while ($row = $this->db->fetchAssoc($res)) {
126 $data['items'][] = $row;
127 }
128
129 if (isset($params['limit'])) {
130 $cnt_sql = "SELECT COUNT(*) cnt FROM ({$query}) subquery";
131 $row_cnt = $this->db->fetchAssoc($this->db->query($cnt_sql));
132 $data['cnt'] = $row_cnt['cnt'];
133 }
134
135 return $data;
136 }
137}
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)
Interface ilDBInterface.
$query
foreach($_POST as $key=> $value) $res
$from
$params
Definition: disable.php:11