ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
JsCollection.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27{
28 protected array $path_storage = [];
29
30
31 public function addItem(Js $item): void
32 {
33 $basename = $this->stripPath($item->getContent());
34 if (!array_key_exists($basename, $this->items)) {
35 $this->storeItem($item);
36 } else {
37 $existing = $this->items[$basename];
38 if (($existing instanceof Js) && $existing->getBatch() > $item->getBatch()) {
39 $this->storeItem($item);
40 }
41 }
42 }
43
44 private function storeItem(
45 js $item
46 ): void {
47 $strip_path = $this->stripPath($item->getContent());
48 $this->items[$strip_path] = $item;
49 $this->path_storage[$strip_path] = $item->getBatch();
50 }
51
52 #[\Override]
53 public function getItemsInOrderOfDelivery(): array
54 {
55 $ordered = [];
56 foreach ($this->getItems() as $js) {
57 $ordered['pos_' . (string) $js->getBatch()][] = $js;
58 }
59 ksort($ordered);
60 $ordered_all = [];
61 foreach ($ordered as $item) {
62 foreach ($item as $js) {
63 $ordered_all[] = $js;
64 }
65 }
66
67 return $ordered_all;
68 }
69}