ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ItemSetManager.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
18 namespace ILIAS\Container\Content;
19 
21 
27 {
28  public const FLAT = 0;
29  public const TREE = 1;
30  public const SINGLE = 2;
32  protected bool $admin_mode;
33  protected bool $hiddenfilesfound = false;
34  protected string $parent_type;
35  protected int $parent_obj_id;
36 
37  protected int $parent_ref_id = 0;
38  protected int $single_ref_id = 0;
40  protected array $raw = [];
41  protected array $raw_by_type = [];
43  protected array $rendered = [];
44  protected int $mode = self::FLAT;
46  protected bool $initialised = false;
47 
51  public function __construct(
52  InternalDomainService $domain,
53  int $mode,
54  int $parent_ref_id,
55  ?\ilContainerUserFilter $user_filter = null,
56  int $single_ref_id = 0,
57  bool $admin_mode = false,
58  bool $force_session_order_by_date = true
59  ) {
60  $this->parent_ref_id = $parent_ref_id;
61  $this->parent_obj_id = \ilObject::_lookupObjId($this->parent_ref_id);
62  $this->parent_type = \ilObject::_lookupType($this->parent_obj_id);
63  $this->user_filter = $user_filter;
64  $this->force_session_order_by_date = $force_session_order_by_date;
65 
66  $this->single_ref_id = $single_ref_id;
67  $this->domain = $domain;
68  $this->mode = $mode; // might be refactored as subclasses
69  $this->admin_mode = $admin_mode;
70  $this->init();
71  }
72 
73  public function setHiddenFilesFound(bool $a_hiddenfilesfound): void
74  {
75  $this->hiddenfilesfound = $a_hiddenfilesfound;
76  }
77 
78  public function getHiddenFilesFound(): bool
79  {
81  }
82 
86  protected function init(): void
87  {
88  if ($this->initialised) {
89  return;
90  }
91  $tree = $this->domain->repositoryTree();
92  if ($this->mode === self::TREE) {
93  $this->raw = $tree->getSubTree($tree->getNodeData($this->parent_ref_id));
94  } elseif ($this->mode === self::FLAT) {
95  $this->raw = $tree->getChilds($this->parent_ref_id, "title");
96  } else {
97  $this->raw[] = $tree->getNodeData($this->single_ref_id);
98  }
99  $this->applyUserFilter();
100  $this->getCompleteDescriptions();
101  $this->applyClassificationFilter();
103  $this->applySorting();
104  $this->groupItems();
105  $this->sortSessions();
106  $this->preloadAdvancedMDValues();
107  $this->initialised = true;
108  }
109 
113  public function hasItems(): bool
114  {
115  $this->init();
116  return count($this->raw) > 0;
117  }
118 
119  public function getRefIdsOfType(string $type): array
120  {
121  $this->init();
122  if (isset($this->raw_by_type[$type])) {
123  return array_map(static function ($item) {
124  return (int) $item["child"];
125  }, $this->raw_by_type[$type]);
126  }
127  return [];
128  }
129 
130  public function getAllRefIds(): array
131  {
132  $this->init();
133  return array_keys($this->raw_by_type["_all"]);
134  }
135 
136  public function getRawDataByRefId(int $ref_id): ?array
137  {
138  $this->init();
139  return $this->raw_by_type["_all"][$ref_id] ?? null;
140  }
141 
142  public function isSideBlockItem(int $ref_id): bool
143  {
144  $this->init();
145  $type = $this->raw_by_type["_all"][$ref_id]["type"] ?? "";
146  $obj_definition = $this->domain->objectDefinition();
147  return $obj_definition->isSideBlock($type);
148  }
149 
150  protected function applySorting(): void
151  {
152  $sort = \ilContainerSorting::_getInstance($this->parent_obj_id);
153  $all = $sort->sortItems(["all" => $this->raw]);
154  $this->raw = $all["all"];
155  //$this->raw_by_type = $sort->sortItems($this->raw_by_type);
156  }
157 
161  protected function groupItems(): void
162  {
163  $obj_definition = $this->domain->objectDefinition();
164  $classification_filter_active = $this->isClassificationFilterActive();
165  $this->raw_by_type["_all"] = [];
166  foreach ($this->raw as $key => $object) {
167 
168  // hide object types in devmode
169  if ($object["type"] === "adm" || $object["type"] === "rolf" ||
170  $obj_definition->getDevMode($object["type"])) {
171  continue;
172  }
173 
174  // remove inactive plugins
175  if ($obj_definition->isInactivePlugin($object["type"])) {
176  continue;
177  }
178 
179  // BEGIN WebDAV: Don't display hidden Files, Folders and Categories
180  if (in_array($object['type'], array('file','fold','cat'))) {
181  if (\ilObjFileAccess::_isFileHidden($object['title'])) {
182  $this->setHiddenFilesFound(true);
183  if (!$this->admin_mode) {
184  continue;
185  }
186  }
187  }
188  // END WebDAV: Don't display hidden Files, Folders and Categories
189 
190  // group object type groups together (e.g. learning resources)
191  $type = $obj_definition->getGroupOfObj($object["type"]);
192  if ($type == "") {
193  $type = $object["type"];
194  }
195 
196  $new_key = (int) $object["child"];
197  $this->rendered[$new_key] = false;
198  $this->raw_by_type[$type][$new_key] = $object;
199 
200  $this->raw_by_type["_all"][$new_key] = $object;
201  if ($object["type"] !== "sess") {
202  $this->raw_by_type["_non_sess"][$new_key] = $object;
203  }
204  }
205  }
206 
207  protected function sortSessions(): void
208  {
209  if (!$this->force_session_order_by_date) {
210  return;
211  }
212  if (isset($this->raw_by_type["sess"]) && count($this->raw_by_type["sess"]) > 0) {
213  $this->raw_by_type["sess"] = \ilArrayUtil::sortArray($this->raw_by_type["sess"], 'start', 'ASC', true, true);
214  }
215  }
216 
217  protected function getAdditionalSubItemInformation(): void
218  {
219  foreach ($this->raw as $key => $object) {
221  }
222  }
223 
224  protected function addAdditionalSubItemInformationToObject(array &$object): void
225  {
227  }
228 
232  public function isClassificationFilterActive(): bool
233  {
234  // apply container classification filters
235  $classification = $this->domain->classification($this->parent_ref_id);
237  $this->parent_ref_id,
238  $this->parent_obj_id,
239  $this->parent_type
240  ) as $class_provider) {
241  $id = get_class($class_provider);
242  $current = $classification->getSelectionOfProvider($id);
243  if ($current) {
244  return true;
245  }
246  }
247  return false;
248  }
249 
250 
255  protected function applyUserFilter(): void
256  {
257  if (is_null($this->user_filter)) {
258  return;
259  }
260  $filter = $this->domain->content()->filter(
261  $this->raw,
262  $this->user_filter,
264  $this->parent_obj_id,
265  "filter_show_empty",
266  "0"
267  )
268  );
269  $this->raw = $filter->apply();
270  }
271 
275  protected function getCompleteDescriptions(): void
276  {
277  $ilSetting = $this->domain->settings();
278  $ilObjDataCache = $this->domain->objectDataCache();
279 
280  // using long descriptions?
281  $short_desc = $ilSetting->get("rep_shorten_description");
282  $short_desc_max_length = (int) $ilSetting->get("rep_shorten_description_length");
283  if (!$short_desc || $short_desc_max_length != \ilObject::DESC_LENGTH) {
284  // using (part of) shortened description
285  if ($short_desc && $short_desc_max_length && $short_desc_max_length < \ilObject::DESC_LENGTH) {
286  foreach ($this->raw as $key => $object) {
287  $this->raw[$key]["description"] = \ilStr::shortenTextExtended(
288  $object["description"],
289  $short_desc_max_length,
290  true
291  );
292  }
293  }
294  // using (part of) long description
295  else {
296  $obj_ids = array();
297  foreach ($this->raw as $key => $object) {
298  $obj_ids[] = $object["obj_id"];
299  }
300  if (count($obj_ids) > 0) {
301  $long_desc = \ilObject::getLongDescriptions($obj_ids);
302  foreach ($this->raw as $key => $object) {
303  // #12166 - keep translation, ignore long description
304  if ($ilObjDataCache->isTranslatedDescription((int) $object["obj_id"])) {
305  $long_desc[$object["obj_id"]] = $object["description"];
306  }
307  if ($short_desc && $short_desc_max_length) {
308  $long_desc[$object["obj_id"]] = \ilStr::shortenTextExtended(
309  (string) ($long_desc[$object["obj_id"]] ?? ""),
310  $short_desc_max_length,
311  true
312  );
313  }
314  $this->raw[$key]["description"] = $long_desc[$object["obj_id"]] ?? '';
315  }
316  }
317  }
318  }
319  }
320 
324  protected function applyClassificationFilter(): void
325  {
326  // apply container classification filters
327  $classification = $this->domain->classification($this->parent_ref_id);
329  $this->parent_ref_id,
330  $this->parent_obj_id,
331  $this->parent_type
332  ) as $class_provider) {
333  $id = get_class($class_provider);
334  $current = $classification->getSelectionOfProvider($id);
335  if ($current) {
336  $class_provider->setSelection($current);
337  $filtered = $class_provider->getFilteredObjects();
338  $this->raw = array_filter($this->raw, static function ($i) use ($filtered) {
339  return (is_array($filtered) && in_array($i["obj_id"], $filtered));
340  });
341  }
342  }
343  }
344 
345  protected function preloadAdvancedMDValues(): void
346  {
347  $obj_ids = [];
348  foreach ($this->raw_by_type["_all"] as $object) {
349  $obj_ids[] = $object["obj_id"];
350  }
352  }
353 }
__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)
applyUserFilter()
Apply container user filter on objects.
Manages container subitems set.
static preloadByObjIds(array $a_obj_ids)
Preload list gui data.
const DESC_LENGTH
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _isFileHidden(string $a_file_name)
Returns true, if a file with the specified name, is usually hidden from the user. ...
setHiddenFilesFound(bool $a_hiddenfilesfound)
static _lookupContainerSetting(int $a_id, string $a_keyword, string $a_default_value=null)
static _lookupObjId(int $ref_id)
static getLongDescriptions(array $obj_ids)
$ref_id
Definition: ltiauth.php:67
groupItems()
Internally group all items.
string $key
Consumer key/client ID value.
Definition: System.php:193
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$classification
static addAdditionalSubItemInformation(array &$item)
Parse item data for list entries.
global $ilSetting
Definition: privfeed.php:18
static shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
static _getInstance(int $a_obj_id)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _lookupType(int $id, bool $reference=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 sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)