ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
TableDataProvider.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 
31 final class TableDataProvider
32 {
33  private \ILIAS\ResourceStorage\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  $current_level
67  )
68  );
69 
71  usort($entries_at_current_level, function (File|Dir $a, File|Dir $b) {
72  $size_a = $a instanceof Dir ? 0 : $a->getSize();
73  $size_b = $b instanceof Dir ? 0 : $b->getSize();
74  $type_a = $a instanceof Dir ? '' : $a->getMimeType();
75  $type_b = $b instanceof Dir ? '' : $b->getMimeType();
76  switch ($this->view_request->getSortation()) {
78  return $b->getModificationDate()->getTimestamp() <=> $a->getModificationDate()->getTimestamp();
80  return $b->getModificationDate()->getTimestamp() <=> $a->getModificationDate()->getTimestamp();
82  return $size_a - $size_b;
84  return $size_b - $size_a;
86  return strcasecmp($b->getTitle(), $a->getTitle());
88  return strcasecmp($a->getTitle(), $b->getTitle());
90  return strcasecmp($type_a, $type_b);
92  return strcasecmp($type_b, $type_a);
93  default:
94  return strcasecmp($a->getTitle(), $b->getTitle());
95  }
96  });
97 
98  return $entries_at_current_level;
99  }
100 
101  public function getTotal(): int
102  {
103  return count($this->getEntries());
104  }
105 }
global $DIC
Definition: shib_login.php:25
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples