ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ItemSetManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
30{
31 public const FLAT = 0;
32 public const TREE = 1;
33 public const SINGLE = 2;
35 protected bool $admin_mode;
36 protected bool $hiddenfilesfound = false;
37 protected string $parent_type;
38 protected int $parent_obj_id;
39
40 protected int $parent_ref_id = 0;
41 protected int $single_ref_id = 0;
43 protected array $raw = [];
44 protected array $raw_by_type = [];
46 protected array $rendered = [];
47 protected int $mode = self::FLAT;
49 protected bool $initialised = false;
50
54 public function __construct(
56 int $mode,
59 int $single_ref_id = 0,
60 bool $admin_mode = false,
62 protected bool $include_objective_items = false
63 ) {
64 $this->parent_ref_id = $parent_ref_id;
65 $this->parent_obj_id = \ilObject::_lookupObjId($this->parent_ref_id);
66 $this->parent_type = \ilObject::_lookupType($this->parent_obj_id);
67 $this->user_filter = $user_filter;
68 $this->force_session_order_by_date = $force_session_order_by_date;
69
70 $this->single_ref_id = $single_ref_id;
71 $this->domain = $domain;
72 $this->mode = $mode; // might be refactored as subclasses
73 $this->admin_mode = $admin_mode;
74 $this->init();
75 }
76
77 public function setHiddenFilesFound(bool $a_hiddenfilesfound): void
78 {
79 $this->hiddenfilesfound = $a_hiddenfilesfound;
80 }
81
82 public function getHiddenFilesFound(): bool
83 {
85 }
86
90 protected function init(): void
91 {
92 if ($this->initialised) {
93 return;
94 }
95 $tree = $this->domain->repositoryTree();
96 if ($this->mode === self::TREE) {
97 $this->raw = $tree->getSubTree($tree->getNodeData($this->parent_ref_id));
98 } elseif ($this->mode === self::FLAT) {
99 $this->raw = $tree->getChilds($this->parent_ref_id, "title");
100 } else {
101 $this->raw[] = $tree->getNodeData($this->single_ref_id);
102 }
103 if ($this->include_objective_items) {
104 $this->addObjectiveItems();
105 }
106 $this->applyUserFilter();
110 $this->applySorting();
111 $this->groupItems();
112 $this->sortSessions();
114 $this->initialised = true;
115 }
116
117 protected function addObjectiveItems(): void
118 {
119 if (count($objective_ids = \ilCourseObjective::_getObjectiveIds(\ilObject::_lookupObjId($this->parent_ref_id), true)) > 0) {
120 foreach ($objective_ids as $objective_id) {
121 foreach (\ilObjectActivation::getItemsByObjective($objective_id) as $item) {
122 $this->addToItems($item);
123 }
124 }
125 }
126 }
127
128 protected function addToItems(array $item): void
129 {
130 if (($ref_id = $item["ref_id"] ?? 0) > 0) {
131 foreach ($this->raw as $raw_item) {
132 if ($raw_item["ref_id"] == $ref_id) {
133 return;
134 }
135 }
136 $this->raw[] = $item;
137 }
138 }
139
143 public function hasItems(): bool
144 {
145 $this->init();
146 return count($this->raw) > 0;
147 }
148
149 public function getRefIdsOfType(string $type): array
150 {
151 $this->init();
152 if (isset($this->raw_by_type[$type])) {
153 return array_map(static function ($item) {
154 return (int) $item["child"];
155 }, $this->raw_by_type[$type]);
156 }
157 return [];
158 }
159
160 public function getAllRefIds(): array
161 {
162 $this->init();
163 return array_keys($this->raw_by_type["_all"]);
164 }
165
166 public function getRawDataByRefId(int $ref_id): ?array
167 {
168 $this->init();
169 return $this->raw_by_type["_all"][$ref_id] ?? null;
170 }
171
172 public function isSideBlockItem(int $ref_id): bool
173 {
174 $this->init();
175 $type = $this->raw_by_type["_all"][$ref_id]["type"] ?? "";
176 $obj_definition = $this->domain->objectDefinition();
177 return $obj_definition->isSideBlock($type);
178 }
179
180 protected function applySorting(): void
181 {
182 $sort = \ilContainerSorting::_getInstance($this->parent_obj_id);
183 $all = $sort->sortItems(["all" => $this->raw]);
184 $this->raw = $all["all"];
185 //$this->raw_by_type = $sort->sortItems($this->raw_by_type);
186 }
187
191 protected function groupItems(): void
192 {
193 $obj_definition = $this->domain->objectDefinition();
194 $classification_filter_active = $this->isClassificationFilterActive();
195 $this->raw_by_type["_all"] = [];
196 foreach ($this->raw as $key => $object) {
197
198 // hide object types in devmode
199 if ($object["type"] === "adm" || $object["type"] === "rolf" ||
200 $obj_definition->getDevMode($object["type"])) {
201 continue;
202 }
203
204 // remove inactive plugins
205 if ($obj_definition->isInactivePlugin($object["type"])) {
206 continue;
207 }
208
209 // BEGIN WebDAV: Don't display hidden Files, Folders and Categories
210 /* this is an old webdav hack, which leads to issues in item groups
211 these objects would be "invisible" but accessible (via url) which makes the behaviour very strange.
212 They are hidden here, but shown in explorer trees and other places...
213 if (in_array($object['type'], array('file','fold','cat'))) {
214 if (\ilObjFileAccess::_isFileHidden($object['title'])) {
215 $this->setHiddenFilesFound(true);
216 if (!$this->admin_mode) {
217 continue;
218 }
219 }
220 }*/
221 // END WebDAV: Don't display hidden Files, Folders and Categories
222
223 // group object type groups together (e.g. learning resources)
224 $type = $obj_definition->getGroupOfObj($object["type"]);
225 if ($type == "") {
226 $type = $object["type"];
227 }
228
229 $new_key = (int) $object["child"];
230 $this->rendered[$new_key] = false;
231 $this->raw_by_type[$type][$new_key] = $object;
232
233 $this->raw_by_type["_all"][$new_key] = $object;
234 if ($object["type"] !== "sess") {
235 $this->raw_by_type["_non_sess"][$new_key] = $object;
236 }
237 }
238 }
239
240 protected function sortSessions(): void
241 {
242 if (!$this->force_session_order_by_date) {
243 return;
244 }
245 if (isset($this->raw_by_type["sess"]) && count($this->raw_by_type["sess"]) > 0) {
246 $this->raw_by_type["sess"] = \ilArrayUtil::sortArray($this->raw_by_type["sess"], 'start', 'ASC', true, true);
247 }
248 }
249
250 protected function getAdditionalSubItemInformation(): void
251 {
252 foreach ($this->raw as $key => $object) {
253 $this->addAdditionalSubItemInformationToObject($this->raw[$key]);
254 }
255 }
256
257 protected function addAdditionalSubItemInformationToObject(array &$object): void
258 {
260 }
261
265 public function isClassificationFilterActive(): bool
266 {
267 // apply container classification filters
268 $classification = $this->domain->classification($this->parent_ref_id);
270 $this->parent_ref_id,
271 $this->parent_obj_id,
272 $this->parent_type
273 ) as $class_provider) {
274 $id = get_class($class_provider);
275 $current = $classification->getSelectionOfProvider($id);
276 if ($current) {
277 return true;
278 }
279 }
280 return false;
281 }
282
283
288 protected function applyUserFilter(): void
289 {
290 if (is_null($this->user_filter)) {
291 return;
292 }
293 $filter = $this->domain->content()->filter(
294 $this->raw,
295 $this->user_filter,
297 $this->parent_obj_id,
298 "filter_show_empty",
299 "0"
300 )
301 );
302 $this->raw = $filter->apply();
303 }
304
308 protected function getCompleteDescriptions(): void
309 {
310 $ilSetting = $this->domain->settings();
311 $ilObjDataCache = $this->domain->objectDataCache();
312
313 // using long descriptions?
314 $short_desc = $ilSetting->get("rep_shorten_description");
315 $short_desc_max_length = (int) $ilSetting->get("rep_shorten_description_length");
316 // using (part of) shortened description
317 if ($short_desc && $short_desc_max_length && $short_desc_max_length < \ilObject::DESC_LENGTH) {
318 foreach ($this->raw as $key => $object) {
319 $this->raw[$key]["description"] = \ilStr::shortenTextExtended(
320 $object["description"],
321 $short_desc_max_length,
322 true
323 );
324 }
325 }
326 // using (part of) long description
327 else {
328 $obj_ids = array();
329 foreach ($this->raw as $key => $object) {
330 $obj_ids[] = $object["obj_id"];
331 }
332 if (count($obj_ids) > 0) {
333 $long_desc = \ilObject::getLongDescriptions($obj_ids);
334 foreach ($this->raw as $key => $object) {
335 // #12166 - keep translation, ignore long description
336 if ($ilObjDataCache->isTranslatedDescription((int) $object["obj_id"])) {
337 $long_desc[$object["obj_id"]] = $object["description"];
338 }
339 if ($short_desc && $short_desc_max_length) {
340 $long_desc[$object["obj_id"]] = \ilStr::shortenTextExtended(
341 (string) ($long_desc[$object["obj_id"]] ?? ""),
342 $short_desc_max_length,
343 true
344 );
345 }
346 $this->raw[$key]["description"] = $long_desc[$object["obj_id"]] ?? '';
347 }
348 }
349 }
350 }
351
355 protected function applyClassificationFilter(): void
356 {
357 // apply container classification filters
358 $classification = $this->domain->classification($this->parent_ref_id);
360 $this->parent_ref_id,
361 $this->parent_obj_id,
362 $this->parent_type
363 ) as $class_provider) {
364 $id = get_class($class_provider);
365 $current = $classification->getSelectionOfProvider($id);
366 if ($current) {
367 $class_provider->setSelection($current);
368 $filtered = $class_provider->getFilteredObjects();
369 $this->raw = array_filter($this->raw, static function ($i) use ($filtered) {
370 return (is_array($filtered) && in_array($i["obj_id"], $filtered));
371 });
372 }
373 }
374 }
375
376 protected function preloadAdvancedMDValues(): void
377 {
378 $obj_ids = [];
379 foreach ($this->raw_by_type["_all"] as $object) {
380 $obj_ids[] = $object["obj_id"];
381 }
383 }
384}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$classification
__construct(InternalDomainService $domain, int $mode, int $parent_ref_id, ?\ilContainerUserFilter $user_filter=null, int $single_ref_id=0, bool $admin_mode=false, bool $force_session_order_by_date=true, protected bool $include_objective_items=false)
applyUserFilter()
Apply container user filter on objects.
setHiddenFilesFound(bool $a_hiddenfilesfound)
static preloadByObjIds(array $a_obj_ids)
Preload list gui data.
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
static getValidProviders(int $a_parent_ref_id, int $a_parent_obj_id, string $a_parent_obj_type)
Get all valid providers (for parent container)
static _getInstance(int $a_obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
static _getObjectiveIds(int $course_id, bool $a_activated_only=false)
static getItemsByObjective(int $objective_id)
Get objective items.
static addAdditionalSubItemInformation(array &$item)
Parse item data for list entries.
static _lookupType(int $id, bool $reference=false)
const DESC_LENGTH
static getLongDescriptions(array $obj_ids)
static _lookupObjId(int $ref_id)
static shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
$ref_id
Definition: ltiauth.php:66
global $ilSetting
Definition: privfeed.php:31