ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
TableDataProvider.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
32{
33 private Services $irss;
34
35 public function __construct(
36 private Request $view_request,
37 ) {
38 global $DIC;
39 $this->irss = $DIC->resourceStorage();
40 }
41
42 public function getViewRequest(): Request
43 {
44 return $this->view_request;
45 }
46
50 public function getEntries(): array
51 {
52 static $entries_at_current_level;
53 static $current_level;
54
55 if ($current_level !== $this->view_request->getPath()) {
56 unset($entries_at_current_level);
57 }
58 if (isset($entries_at_current_level)) {
59 return $entries_at_current_level;
60 }
61
62 $current_level = $this->view_request->getPath();
63
64 $entries_at_current_level = iterator_to_array(
65 $this->view_request->getWrapper()->getEntries()
66 );
67
69 usort($entries_at_current_level, function (File|Dir $a, File|Dir $b): int {
70 $size_a = $a instanceof Dir ? 0 : $a->getSize();
71 $size_b = $b instanceof Dir ? 0 : $b->getSize();
72 $type_a = $a instanceof Dir ? '' : $a->getMimeType();
73 $type_b = $b instanceof Dir ? '' : $b->getMimeType();
74 return match ($this->view_request->getSortation()) {
75 Request::BY_CREATION_DATE_DESC => $b->getModificationDate()->getTimestamp() <=> $a->getModificationDate()->getTimestamp(),
76 Request::BY_CREATION_DATE_ASC => $b->getModificationDate()->getTimestamp() <=> $a->getModificationDate()->getTimestamp(),
77 Request::BY_SIZE_DESC => $size_a - $size_b,
78 Request::BY_SIZE_ASC => $size_b - $size_a,
79 Request::BY_TITLE_DESC => strcasecmp($b->getTitle(), $a->getTitle()),
80 Request::BY_TITLE_ASC => strcasecmp($a->getTitle(), $b->getTitle()),
81 Request::BY_TYPE_DESC => strcasecmp($type_a, $type_b),
82 Request::BY_TYPE_ASC => strcasecmp($type_b, $type_a),
83 default => strcasecmp($a->getTitle(), $b->getTitle()),
84 };
85 });
86
87 return $entries_at_current_level;
88 }
89
90 public function getTotal(): int
91 {
92 return count($this->getEntries());
93 }
94}
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
global $DIC
Definition: shib_login.php:26