ILIAS  release_8 Revision v8.24
class.ilWebLinkItemsContainer.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
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 {
50 $this->getWebrId()
51 );
52
53 if ($mode == ilContainer::SORT_TITLE) {
54 $items_arr = [];
55
56 foreach ($this->getItems() as $item) {
57 $link_id = $item->getLinkId();
58 $items_arr[$link_id]['title'] = $item->getTitle();
59 $items_arr[$link_id]['item'] = $item;
60 }
61
62 $items_arr = ilArrayUtil::sortArray(
63 $items_arr,
64 'title',
65 'asc',
66 false,
67 true
68 );
69
70 $result = [];
71 foreach ($items_arr as $value) {
72 $result[] = $value['item'];
73 }
74 $this->items = $result;
75 }
76
77 $sorted = $unsorted = [];
78 if ($mode == ilContainer::SORT_MANUAL) {
80 $this->getWebrId()
81 );
82 foreach ($this->getItems() as $item) {
83 $link_id = $item->getLinkId();
84 if (isset($pos[$link_id])) {
85 $sorted[$link_id]['title'] = $item->getTitle();
86 $sorted[$link_id]['position'] = (int) $pos[$link_id];
87 $sorted[$link_id]['item'] = $item;
88 } else {
89 $unsorted[$link_id]['title'] = $item->getTitle();
90 $unsorted[$link_id]['item'] = $item;
91 }
92 }
93 $sorted = ilArrayUtil::sortArray(
94 $sorted,
95 'position',
96 'asc',
97 true,
98 true
99 );
100 $unsorted = ilArrayUtil::sortArray(
101 $unsorted,
102 'title',
103 'asc',
104 false,
105 true
106 );
107
108 $result = [];
109 foreach ($sorted + $unsorted as $value) {
110 $result[] = $value['item'];
111 }
112 $this->items = $result;
113 }
114
115 return $this;
116 }
117
121 public function getItems(): array
122 {
123 return $this->items;
124 }
125
126 public function getFirstItem(): ?ilWebLinkItem
127 {
128 return $this->items[0] ?? null;
129 }
130
131 public function getWebrId(): int
132 {
133 return $this->webr_id;
134 }
135}
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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