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