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