ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilLSItemsDB.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 protected ilTree $tree;
30
31 public function __construct(
36 ) {
37 $this->tree = $tree;
38 $this->container_sorting = $container_sorting;
39 $this->post_conditions_db = $post_conditions_db;
40 $this->ls_item_online_status = $ls_item_online_status;
41 }
42
46 public function getLSItems(int $ref_id): array
47 {
48 $children = $this->tree->getChilds($ref_id);
49
50 $sorting_settings = $this->container_sorting->getSortingSettings();
51 $sorting_settings->setSortMode(ilContainer::SORT_MANUAL);
52 $sorted = $this->container_sorting->sortItems(['lsitems' => $children]);
53 $children = $sorted['lsitems'];
54
55 $conditions = $this->getConditionsForChildren($children);
56
57 $items = [];
58 foreach ($children as $position => $child) {
59 $ref_id = (int) $child['child'];
60 $obj_id = (int) $child['obj_id'];
61 $lp_mode = $this->getCurrentLPMode($obj_id);
62
63 $items[] = new LSItem(
64 $child['type'],
65 $child['title'],
66 $child['description'] ?? "",
67 $this->getIconPathForType($child['type']),
68 $this->ls_item_online_status->getOnlineStatus($ref_id),
69 $position,
70 $conditions[$ref_id],
71 $ref_id,
72 $lp_mode
73 );
74 }
75
76 return $items;
77 }
78
79 protected function getCurrentLPMode(int $obj_id): int
80 {
81 $obj_lp = ilObjectLP::getInstance($obj_id);
82 return $obj_lp->getCurrentMode();
83 }
84
85 protected function getIconPathForType(string $type): string
86 {
87 return ilObject2::_getIcon(0, "big", $type);
88 }
89
94 protected function getConditionsForChildren(array $children): array
95 {
96 $ref_ids = array_map(
97 fn ($i) => (int) $i['child'],
98 $children
99 );
100
101 $conditions = [];
102 foreach ($this->post_conditions_db->select($ref_ids) as $condition) {
103 $conditions[$condition->getRefId()] = $condition;
104 }
105
106 return $conditions;
107 }
108
109 protected function storeItemsOrder(array $ls_items): void
110 {
111 $type_positions = [];
112 foreach ($ls_items as $item) {
113 $type_positions[$item->getRefId()] = $item->getOrderNumber();
114 }
115 $this->container_sorting->savePost($type_positions);
116 }
117
118 protected function storeOnlineStatus(array $ls_items): void
119 {
120 foreach ($ls_items as $item) {
121 $this->ls_item_online_status->setOnlineStatus(
122 $item->getRefId(),
123 $item->isOnline()
124 );
125 }
126 }
127
128 protected function storePostconditions(array $ls_items): void
129 {
130 $conditions = [];
131 foreach ($ls_items as $item) {
132 $conditions[] = $item->getPostCondition();
133 }
134 $this->post_conditions_db->upsert($conditions);
135 }
136
140 public function storeItems(array $ls_items): void
141 {
142 $this->storeOnlineStatus($ls_items);
143 $this->storeItemsOrder($ls_items);
144 $this->storePostconditions($ls_items);
145 }
146
147 // The typehint on ilObject is intentional, we expect this to return some object
148 // or need to error instead.
149 protected function getObjectFor(int $ref_id): \ilObject
150 {
152 }
153}
Data holding class LSItem .
Definition: LSItem.php:25
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilLSItemsDB.
Definition: ilLSItemsDB.php:25
storePostconditions(array $ls_items)
__construct(ilTree $tree, ilContainerSorting $container_sorting, ilLSPostConditionDB $post_conditions_db, LSItemOnlineStatus $ls_item_online_status)
Definition: ilLSItemsDB.php:31
getLSItems(int $ref_id)
Definition: ilLSItemsDB.php:46
getIconPathForType(string $type)
Definition: ilLSItemsDB.php:85
storeItems(array $ls_items)
Use this to apply settings made in ContentGUI.
storeOnlineStatus(array $ls_items)
ilLSPostConditionDB $post_conditions_db
Definition: ilLSItemsDB.php:28
getObjectFor(int $ref_id)
getConditionsForChildren(array $children)
Collect all conditions at once.
Definition: ilLSItemsDB.php:94
getCurrentLPMode(int $obj_id)
Definition: ilLSItemsDB.php:79
ilContainerSorting $container_sorting
Definition: ilLSItemsDB.php:27
ilTree $tree
Definition: ilLSItemsDB.php:26
storeItemsOrder(array $ls_items)
LSItemOnlineStatus $ls_item_online_status
Definition: ilLSItemsDB.php:29
Storage for ilLSPostConditions.
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static getInstance(int $obj_id)
Class ilObject Basic functions for all objects.
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
$ref_id
Definition: ltiauth.php:66