ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAccessibilityTableDatabaseDataProvider.php
Go to the documentation of this file.
1<?php
2
23{
24 protected ilDBInterface $db;
25
26 public function __construct(ilDBInterface $db)
27 {
28 $this->db = $db;
29 }
30
31 abstract protected function getSelectPart(array $params, array $filter): string;
32
33 abstract protected function getFromPart(array $params, array $filter): string;
34
35 abstract protected function getWherePart(array $params, array $filter): string;
36
37 abstract protected function getGroupByPart(array $params, array $filter): string;
38
39 abstract protected function getHavingPart(array $params, array $filter): string;
40
41 abstract protected function getOrderByPart(array $params, array $filter): string;
42
46 public function getList(array $params, array $filter): array
47 {
48 $data = [
49 'items' => [],
50 'cnt' => 0
51 ];
52
53 $select = $this->getSelectPart($params, $filter);
54 $where = $this->getWherePart($params, $filter);
55 $from = $this->getFromPart($params, $filter);
56 $order = $this->getOrderByPart($params, $filter);
57 $group = $this->getGroupByPart($params, $filter);
58 $having = $this->getHavingPart($params, $filter);
59
60 if (isset($params['limit'])) {
61 if (!is_numeric($params['limit'])) {
62 throw new InvalidArgumentException('Please provide a valid numerical limit.');
63 }
64
65 if (!isset($params['offset'])) {
66 $params['offset'] = 0;
67 } else {
68 if (!is_numeric($params['offset'])) {
69 throw new InvalidArgumentException('Please provide a valid numerical offset.');
70 }
71 }
72
73 $this->db->setLimit($params['limit'], $params['offset']);
74 }
75
76 $where = strlen($where) ? 'WHERE ' . $where : '';
77 $query = "SELECT {$select} FROM {$from} {$where}";
78
79 if (strlen($group)) {
80 $query .= " GROUP BY {$group}";
81 }
82
83 if (strlen($having)) {
84 $query .= " HAVING {$having}";
85 }
86
87 if (strlen($order)) {
88 $query .= " ORDER BY {$order}";
89 }
90
91 $res = $this->db->query($query);
92 while ($row = $this->db->fetchAssoc($res)) {
93 $data['items'][] = $row;
94 }
95
96 if (isset($params['limit'])) {
97 $cnt_sql = "SELECT COUNT(*) cnt FROM ({$query}) subquery";
98 $row_cnt = $this->db->fetchAssoc($this->db->query($cnt_sql));
99 $data['cnt'] = $row_cnt['cnt'];
100 }
101
102 return $data;
103 }
104}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getFromPart(array $params, array $filter)
getGroupByPart(array $params, array $filter)
getWherePart(array $params, array $filter)
getHavingPart(array $params, array $filter)
getSelectPart(array $params, array $filter)
getOrderByPart(array $params, array $filter)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilDBInterface.
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
$res
Definition: ltiservices.php:69