ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilWebLinkItemsContainer.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
27 protected int $webr_id;
31 protected array $items;
32
37 public function __construct(int $webr_id, array $items = [])
38 {
39 $this->webr_id = $webr_id;
41 }
42
47 public function sort(): self
48 {
49 $mode = $this->lookupSortMode($this->getWebrId());
50
51 if ($mode == ilContainer::SORT_TITLE) {
52 $items_arr = [];
53
54 foreach ($this->getItems() as $item) {
55 $link_id = $item->getLinkId();
56 $items_arr[$link_id]['title'] = $item->getTitle();
57 $items_arr[$link_id]['item'] = $item;
58 }
59
60 $items_arr = $this->sortArray(
61 $items_arr,
62 'title',
63 false
64 );
65
66 $result = [];
67 foreach ($items_arr as $value) {
68 $result[] = $value['item'];
69 }
70 $this->items = $result;
71 }
72
73 $sorted = $unsorted = [];
74 if ($mode == ilContainer::SORT_MANUAL) {
75 $pos = $this->lookupManualPositions($this->getWebrId());
76 foreach ($this->getItems() as $item) {
77 $link_id = $item->getLinkId();
78 if (isset($pos[$link_id])) {
79 $sorted[$link_id]['title'] = $item->getTitle();
80 $sorted[$link_id]['position'] = (int) $pos[$link_id];
81 $sorted[$link_id]['item'] = $item;
82 } else {
83 $unsorted[$link_id]['title'] = $item->getTitle();
84 $unsorted[$link_id]['item'] = $item;
85 }
86 }
87 $sorted = $this->sortArray(
88 $sorted,
89 'position',
90 true
91 );
92 $unsorted = $this->sortArray(
93 $unsorted,
94 'title',
95 false
96 );
97
98 $result = [];
99 foreach ($sorted + $unsorted as $value) {
100 $result[] = $value['item'];
101 }
102 $this->items = $result;
103 }
104
105 return $this;
106 }
107
108 protected function lookupSortMode(int $webr_id): int
109 {
111 }
112
116 protected function lookupManualPositions(int $webr_id): array
117 {
119 }
120
121 protected function sortArray(array $array, string $sort_by_key, bool $numeric): array
122 {
124 $array,
125 $sort_by_key,
126 'asc',
127 $numeric,
128 true
129 );
130 }
131
135 public function getItems(): array
136 {
137 return $this->items;
138 }
139
140 public function getFirstItem(): ?ilWebLinkItem
141 {
142 return $this->items[0] ?? null;
143 }
144
145 public function getWebrId(): int
146 {
147 return $this->webr_id;
148 }
149}
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
static lookupPositions(int $a_obj_id)
Base container class for Web Link items.
Immutable class for Web Link items.
Immutable container class for Web Link items.
sortArray(array $array, string $sort_by_key, bool $numeric)
sort()
Sorts the items in this container according to the settings of this web link object.
__construct(int $webr_id, array $items=[])
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc