ILIAS  release_8 Revision v8.24
class.ilTermsOfServiceTableDatabaseDataProvider.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
27 protected ilDBInterface $db;
28
29 public function __construct(ilDBInterface $db)
30 {
31 $this->db = $db;
32 }
33
39 abstract protected function getSelectPart(array $params, array $filter): string;
40
46 abstract protected function getFromPart(array $params, array $filter): string;
47
53 abstract protected function getWherePart(array $params, array $filter): string;
54
60 abstract protected function getGroupByPart(array $params, array $filter): string;
61
68 abstract protected function getHavingPart(array $params, array $filter): string;
69
75 abstract protected function getOrderByPart(array $params, array $filter): string;
76
83 public function getList(array $params, array $filter): array
84 {
85 $data = [
86 'items' => [],
87 'cnt' => 0
88 ];
89
90 $select = $this->getSelectPart($params, $filter);
91 $where = $this->getWherePart($params, $filter);
92 $from = $this->getFromPart($params, $filter);
93 $order = $this->getOrderByPart($params, $filter);
94 $group = $this->getGroupByPart($params, $filter);
95 $having = $this->getHavingPart($params, $filter);
96
97 if (isset($params['limit'])) {
98 if (!is_numeric($params['limit'])) {
99 throw new InvalidArgumentException('Please provide a valid numerical limit.');
100 }
101
102 if (!isset($params['offset'])) {
103 $params['offset'] = 0;
104 } elseif (!is_numeric($params['offset'])) {
105 throw new InvalidArgumentException('Please provide a valid numerical offset.');
106 }
107
108 $this->db->setLimit($params['limit'], $params['offset']);
109 }
110
111 $where = $where !== '' ? 'WHERE ' . $where : '';
112 $query = "SELECT $select FROM $from $where";
113
114 if ($group !== '') {
115 $query .= " GROUP BY $group";
116 }
117
118 if ($having !== '') {
119 $query .= " HAVING $having";
120 }
121
122 if ($order !== '') {
123 $query .= " ORDER BY $order";
124 }
125
126 $res = $this->db->query($query);
127 while ($row = $this->db->fetchAssoc($res)) {
128 $data['items'][] = $row;
129 }
130
131 if (isset($params['limit'])) {
132 $cnt_sql = "SELECT COUNT(*) cnt FROM ($query) subquery";
133 $row_cnt = $this->db->fetchAssoc($this->db->query($cnt_sql));
134 $data['cnt'] = (int) $row_cnt['cnt'];
135 }
136
137 return $data;
138 }
139}
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)
Interface ilDBInterface.
Interface ilTermsOfServiceTableDataProvider.
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
$res
Definition: ltiservices.php:69
$query