ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
AllResourcesDataSource.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
31 
36 {
37  public function __construct()
38  {
39  global $DIC;
41  $DIC->resourceStorage()->collection()->id() // ad hoc collection
42  );
43  }
44 
45  public function process(): void
46  {
47  $r = $this->db->query($this->getCountQuery());
48  $this->filtered_amount_of_items = (int) $this->db->fetchAssoc($r)['cnt'];
49 
50  $r = $this->db->query($this->getDataQuery());
51 
52  $rid_strings = [];
53  while ($d = $this->db->fetchAssoc($r)) {
54  $rid_strings[] = $d['rid'] ?? '';
55  }
56  $this->irss->preload($rid_strings);
57  foreach ($rid_strings as $rid_string) {
58  $rid_instance = $this->irss->manage()->find($rid_string);
59  if (!$rid_instance instanceof ResourceIdentification) {
60  continue;
61  }
62  $this->collection->add($rid_instance);
63  }
64  }
65 
66  public function getSortationsMapping(): array
67  {
68  return [
69  SortDirection::BY_TITLE_ASC => 'revision_title ASC', // Default
70  SortDirection::BY_TITLE_DESC => 'revision_title DESC',
71  SortDirection::BY_SIZE_ASC => 'file_size ASC',
72  SortDirection::BY_SIZE_DESC => 'file_size DESC',
73  SortDirection::BY_CREATION_DATE_ASC => 'creation_date ASC',
74  SortDirection::BY_CREATION_DATE_DESC => 'creation_date DESC',
75  ];
76  }
77 
81  #[\Override]
82  public function getFilterItems(
83  Factory $ui_factory,
85  ): array {
86  $stakeholders = [];
87  $r = $this->db->query('SELECT DISTINCT * FROM il_resource_stkh');
88  while ($d = $this->db->fetchAssoc($r)) {
89  $class_name = $d['class_name'] ?? '';
90  if (!class_exists($class_name)) {
91  continue;
92  }
94  $stakeholder = new $class_name();
95 
96  $stakeholders[$d['id']] = $stakeholder->getConsumerNameForPresentation();
97  }
98 
99  asort($stakeholders);
100 
101  return [
102  'title' => $ui_factory->input()->field()->text(
103  $lng->txt('title'),
104  ),
105  'size' => $ui_factory->input()->field()->numeric(
106  $lng->txt('file_size_bigger_than')
107  ),
108  'stakeholder' => $ui_factory->input()->field()->select(
109  $lng->txt('stakeholders'),
110  $stakeholders
111  ),
112 // 'revisions' => $ui_factory->input()->field()->numeric(
113 // $lng->txt('revisions_more_than'),
114 // ),
115  ];
116  }
117 
118  private function getCountQuery(): string
119  {
120  return $this->getBaseQuery(true);
121  }
122 
123  private function getDataQuery(): string
124  {
125  return $this->getBaseQuery(false) . " LIMIT " . $this->offset . ", " . $this->limit;
126  }
127 
128 
129 
130  private function getBaseQuery(bool $count_only): string
131  {
132  // SELECT
133  $q = $this->buildSelect($count_only);
134  // FROM AND JOINS
135  $q .= " FROM il_resource_revision
136  JOIN il_resource_info ON il_resource_revision.rid = il_resource_info.rid AND
137  il_resource_info.version_number = il_resource_revision.version_number
138  JOIN il_resource_stkh_u ON il_resource_revision.rid = il_resource_stkh_u.rid";
139 
140  // WHERE
141  $q .= $this->buildQueryFilter();
142 
143  if (!$count_only) {
144  $q .= " GROUP BY il_resource_revision.rid ";
145  }
146 
147  // $q .= $this->buildHaving();
148 
149  if (!$count_only) {
150  $q .= $this->buildSortation();
151  }
152 
153  return $q;
154  }
155 
156 
157  private function buildSortation(): string
158  {
159  return " ORDER BY " . ($this->getSortationsMapping()[$this->sort_direction]
161  }
162 
163  private function buildSelect(bool $count_only): string
164  {
165  if ($count_only) {
166  return "SELECT COUNT(il_resource_revision.rid) AS cnt";
167  }
168 
169  return "SELECT il_resource_revision.rid
170  , MAX(il_resource_revision.version_number) AS max_revision
171  , il_resource_revision.title AS revision_title
172  , il_resource_info.title AS file_title
173  , il_resource_info.size AS file_size
174  , il_resource_info.creation_date AS creation_date
175  , il_resource_stkh_u.stakeholder_id AS stakeholder";
176  }
177 
178  private function buildQueryFilter(): string
179  {
180  $filters = [];
181  $filter_values = [];
182  $query = '';
183  if ($this->filter_values !== null) {
184  if (isset($this->filter_values['title']) && $this->filter_values['title'] !== '') {
185  $filter_values[] = $this->db->quote("%" . $this->filter_values['title'] . "%", 'text');
186  $filters[] = " il_resource_revision.title LIKE %s ";
187  }
188  if (isset($this->filter_values['size']) && $this->filter_values['size'] !== '') {
189  $greater_than = (int) $this->filter_values['size'] * BaseToComponent::SIZE_FACTOR * BaseToComponent::SIZE_FACTOR;
190  $filter_values[] = $this->db->quote($greater_than, 'integer');
191  $filters[] = " il_resource_info.size > %s ";
192  }
193 
194  if (isset($this->filter_values['stakeholder']) && $this->filter_values['stakeholder'] !== '') {
195  $filter_values[] = $this->db->quote("" . $this->filter_values['stakeholder'] . "", 'text');
196  $filters[] = " il_resource_stkh_u.stakeholder_id = %s ";
197  }
198  }
199  if ($filters !== []) {
200  $query = " WHERE " . implode(" AND ", $filters);
201  $query = vsprintf($query, $filter_values);
202  }
203 
204  return $query;
205  }
206  private function buildHaving(): string
207  {
208  $filters = [];
209  $filter_values = [];
210  $query = '';
211  if ($this->filter_values !== null && (isset($this->filter_values['revisions']) && $this->filter_values['revisions'] !== '')) {
212  $filter_values[] = $this->db->quote($this->filter_values['revisions'], 'integer');
213  $filters[] = "MAX(il_resource_revision.version_number) > %s ";
214  }
215  if ($filters !== []) {
216  $query = " HAVING " . implode(" AND ", $filters);
217  $query = vsprintf($query, $filter_values);
218  }
219 
220  return $query;
221  }
222 }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
input()
description: purpose: > In opposite to components with a purely receptive or at most navigational ch...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This is how the factory for UI elements looks.
Definition: Factory.php:37
global $DIC
Definition: shib_login.php:22
__construct(Container $dic, ilPlugin $plugin)
global $lng
Definition: privfeed.php:31
$q
Definition: shib_logout.php:21
$r