ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
class.ItemPresentationManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26
34{
35 protected ?string $lang = null;
36 protected bool $include_empty_blocks;
38 protected ?bool $can_order = null;
39 protected ?bool $can_delete = null;
41 protected ?bool $can_manage = null;
44 protected ?array $type_grps = null;
45 protected ?ItemSetManager $item_set = null;
46 protected \ilContainer $container;
49
50 public function __construct(
55 bool $include_empty_blocks = true,
56 ?string $lang = null
57 ) {
58 $this->container = $container;
59 $this->domain = $domain;
60 $this->container_user_filter = $container_user_filter;
61 $this->repo_clipboard = $repo_clipboard;
62 $this->mode_manager = $domain->content()->mode($container);
63 $this->include_empty_blocks = $include_empty_blocks;
64 $this->lang = $lang;
65
66 // sequence from view manager
67 }
68
69 public function canManageItems(): bool
70 {
71 if (!is_null($this->can_manage)) {
72 return $this->can_manage;
73 }
74 $user = $this->domain->user();
75 $rbacsystem = $this->domain->rbac()->system();
76 if ($user->getId() === ANONYMOUS_USER_ID || !is_object($this->container)) {
77 return false;
78 }
79
80 if ($rbacsystem->checkAccess("write", $this->container->getRefId()) ||
81 $this->container->getHiddenFilesFound() ||
82 $this->repo_clipboard->hasEntries()) {
83 $this->can_manage = true;
84 return true;
85 }
86 $this->init();
87 $this->can_manage = false;
88 /* this is time consuming and probably not necessary
89 foreach ($this->item_set->getAllRefIds() as $ref_id) {
90 if ($this->can_manage === true) {
91 break;
92 }
93 if ($rbacsystem->checkAccess("delete", $ref_id)) {
94 $this->can_manage = true;
95 }
96 }*/
97 return $this->can_manage;
98 }
99
103 public function canOrderItems(): bool
104 {
105 $user = $this->domain->user();
106 $rbacsystem = $this->domain->rbac()->system();
107
108 if (is_null($this->can_order)) {
109 $this->can_order = false;
110 if ($user->getId() !== ANONYMOUS_USER_ID &&
111 is_object($this->container) &&
112 $rbacsystem->checkAccess("write", $this->container->getRefId())) {
113 $this->can_order = (\ilContainerSortingSettings::_lookupSortMode($this->container->getId()) === \ilContainer::SORT_MANUAL);
114 }
115 }
116 return $this->can_order;
117 }
118
119 public function canDeleteItems(): bool
120 {
121 if (!is_null($this->can_delete)) {
122 return $this->can_delete;
123 }
124
125 $access = $this->domain->access();
126 foreach ($this->getAllRefIds() as $ref_id) {
127 if ($access->checkAccess("delete", "", $ref_id)) {
128 return $this->can_delete = true;
129 }
130 }
131
132 return $this->can_delete = false;
133 }
134
138 public function isActiveItemOrdering(string $type): bool
139 {
140 // see #43205
141 if ($this->mode_manager->isActiveItemOrdering()) {
142 if ($type === "sess" && $this->container->getViewMode() === \ilContainer::VIEW_SESSIONS) {
143 return false;
144 }
145 return true;
146 }
147 return false;
148 }
149
150 public function forceSessionOrderingByDate(): bool
151 {
152 // see #43205
153 return ($this->container->getViewMode() === \ilContainer::VIEW_SESSIONS ||
154 $this->container->getOrderType() !== \ilContainer::SORT_MANUAL);
155 }
156
157
162 protected function isClassificationFilterActive(): bool
163 {
164 $ref_id = $this->container->getRefId();
165 // apply container classification filters
166 $classification = $this->domain->classification($ref_id);
168 $this->container->getRefId(),
169 $this->container->getId(),
170 $this->container->getType()
171 ) as $class_provider) {
172 $id = get_class($class_provider);
173 $current = $classification->getSelectionOfProvider($id);
174 if ($current) {
175 return true;
176 }
177 }
178 return false;
179 }
180
184 public function filteredSubtree(): bool
185 {
186 return $this->isClassificationFilterActive() && in_array(
187 $this->container->getType(),
188 ["grp", "crs"]
189 );
190 }
191
192 protected function init(): void
193 {
194 // already initialised?
195 if (!is_null($this->item_set)) {
196 return;
197 }
198
199 // get view
200 $view = $this->domain->content()->view($this->container);
201 // get item set
202 $ref_id = $this->container->getRefId();
203 if ($this->filteredSubtree()) {
204 $this->item_set = $this->domain->content()->itemSetTree($ref_id, $this->container_user_filter);
205 } else {
206 $this->item_set = $this->domain->content()->itemSetFlat(
207 $ref_id,
208 $this->container_user_filter,
210 $view instanceof ObjectiveViewManager
211 );
212 }
213
214 // get item block sequence generator
215 $this->sequence_generator = $this->domain->content()->itemBlockSequenceGenerator(
216 $this->container,
217 $view->getBlockSequence(),
218 $this->item_set,
219 $this->include_empty_blocks,
220 $this->lang
221 );
222 }
223
224 public function hasItems(): bool
225 {
226 $this->init();
227 return $this->item_set->hasItems();
228 }
229
230 public function getItemBlockSequence(
231 array $omit_ref_ids = []
233 $this->init();
234 $this->sequence_generator->setOmitRefIds($omit_ref_ids);
235 return $this->sequence_generator->getSequence();
236 }
237
238 public function getPageEmbeddedBlockIds(): array
239 {
240 $this->init();
241 return $this->sequence_generator->getPageEmbeddedBlockIds();
242 }
243
244 public function getRawDataByRefId(int $ref_id): ?array
245 {
246 $this->init();
247 return $this->item_set->getRawDataByRefId($ref_id);
248 }
249
250 public function getAllRefIds(): ?array
251 {
252 $this->init();
253 return $this->item_set->getAllRefIds();
254 }
255
256 public function getRefIdsOfType(string $type): array
257 {
258 $this->init();
259 return $this->item_set->getRefIdsOfType($type);
260 }
261}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$classification
__construct(InternalDomainService $domain, \ilContainer $container, ?\ilContainerUserFilter $container_user_filter, ClipboardManager $repo_clipboard, bool $include_empty_blocks=true, ?string $lang=null)
isActiveItemOrdering(string $type)
Are we currently in ordering view and the items can be ordered?
init(array|\ArrayAccess &$define, array|\ArrayAccess &$implement, array|\ArrayAccess &$use, array|\ArrayAccess &$contribute, array|\ArrayAccess &$seek, array|\ArrayAccess &$provide, array|\ArrayAccess &$pull, array|\ArrayAccess &$internal,)
Definition: Container.php:28
Manages items in repository clipboard.
static getValidProviders(int $a_parent_ref_id, int $a_parent_obj_id, string $a_parent_obj_type)
Get all valid providers (for parent container)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilContainer.
const ANONYMOUS_USER_ID
Definition: constants.php:27