ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilTermsOfServiceTableDatabaseDataProvider.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
9{
11 protected $db;
12
17 public function __construct(ilDBInterface $db)
18 {
19 $this->db = $db;
20 }
21
27 abstract protected function getSelectPart(array $params, array $filter) : string;
28
34 abstract protected function getFromPart(array $params, array $filter) : string;
35
41 abstract protected function getWherePart(array $params, array $filter) : string;
42
48 abstract protected function getGroupByPart(array $params, array $filter) : string;
49
56 abstract protected function getHavingPart(array $params, array $filter) : string;
57
63 abstract protected function getOrderByPart(array $params, array $filter) : string;
64
71 public function getList(array $params, array $filter) : array
72 {
73 $data = [
74 'items' => [],
75 'cnt' => 0
76 ];
77
78 $select = $this->getSelectPart($params, $filter);
79 $where = $this->getWherePart($params, $filter);
80 $from = $this->getFromPart($params, $filter);
81 $order = $this->getOrderByPart($params, $filter);
82 $group = $this->getGroupByPart($params, $filter);
83 $having = $this->getHavingPart($params, $filter);
84
85 if (isset($params['limit'])) {
86 if (!is_numeric($params['limit'])) {
87 throw new InvalidArgumentException('Please provide a valid numerical limit.');
88 }
89
90 if (!isset($params['offset'])) {
91 $params['offset'] = 0;
92 } else {
93 if (!is_numeric($params['offset'])) {
94 throw new InvalidArgumentException('Please provide a valid numerical offset.');
95 }
96 }
97
98 $this->db->setLimit($params['limit'], $params['offset']);
99 }
100
101 $where = strlen($where) ? 'WHERE ' . $where : '';
102 $query = "SELECT {$select} FROM {$from} {$where}";
103
104 if (strlen($group)) {
105 $query .= " GROUP BY {$group}";
106 }
107
108 if (strlen($having)) {
109 $query .= " HAVING {$having}";
110 }
111
112 if (strlen($order)) {
113 $query .= " ORDER BY {$order}";
114 }
115
116 $res = $this->db->query($query);
117 while ($row = $this->db->fetchAssoc($res)) {
118 $data['items'][] = $row;
119 }
120
121 if (isset($params['limit'])) {
122 $cnt_sql = "SELECT COUNT(*) cnt FROM ({$query}) subquery";
123 $row_cnt = $this->db->fetchAssoc($this->db->query($cnt_sql));
124 $data['cnt'] = $row_cnt['cnt'];
125 }
126
127 return $data;
128 }
129}
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilTermsOfServiceTableDataProvider.
$query
foreach($_POST as $key=> $value) $res
$data
Definition: storeScorm.php:23