ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ItemPresentationManager.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
18 namespace ILIAS\Container\Content;
19 
23 
31 {
32  protected ?string $lang = null;
33  protected bool $include_empty_blocks;
35  protected ?bool $can_order = null;
37  protected ?bool $can_manage = null;
40  protected ?array $type_grps = null;
41  protected ?ItemSetManager $item_set = null;
42  protected \ilContainer $container;
45 
46  public function __construct(
47  InternalDomainService $domain,
48  \ilContainer $container,
49  ?\ilContainerUserFilter $container_user_filter,
50  ClipboardManager $repo_clipboard,
51  bool $include_empty_blocks = true,
52  ?string $lang = null
53  ) {
54  $this->container = $container;
55  $this->domain = $domain;
56  $this->container_user_filter = $container_user_filter;
57  $this->repo_clipboard = $repo_clipboard;
58  $this->mode_manager = $domain->content()->mode($container);
59  $this->include_empty_blocks = $include_empty_blocks;
60  $this->lang = $lang;
61 
62  // sequence from view manager
63  }
64 
65  public function canManageItems(): bool
66  {
67  if (!is_null($this->can_manage)) {
68  return $this->can_manage;
69  }
70  $user = $this->domain->user();
71  $rbacsystem = $this->domain->rbac()->system();
72  if ($user->getId() === ANONYMOUS_USER_ID || !is_object($this->container)) {
73  return false;
74  }
75 
76  if ($rbacsystem->checkAccess("write", $this->container->getRefId()) ||
77  $this->container->getHiddenFilesFound() ||
78  $this->repo_clipboard->hasEntries()) {
79  $this->can_manage = true;
80  return true;
81  }
82  $this->init();
83  $this->can_manage = false;
84  /* this is time consuming and probably not necessary
85  foreach ($this->item_set->getAllRefIds() as $ref_id) {
86  if ($this->can_manage === true) {
87  break;
88  }
89  if ($rbacsystem->checkAccess("delete", $ref_id)) {
90  $this->can_manage = true;
91  }
92  }*/
93  return $this->can_manage;
94  }
95 
99  public function canOrderItems(): bool
100  {
101  $user = $this->domain->user();
102  $rbacsystem = $this->domain->rbac()->system();
103 
104  if (is_null($this->can_order)) {
105  $this->can_order = false;
106  if ($user->getId() !== ANONYMOUS_USER_ID &&
107  is_object($this->container) &&
108  $rbacsystem->checkAccess("write", $this->container->getRefId())) {
109  $this->can_order = (\ilContainerSortingSettings::_lookupSortMode($this->container->getId()) === \ilContainer::SORT_MANUAL);
110  }
111  }
112  return $this->can_order;
113  }
114 
118  public function isActiveItemOrdering(string $type): bool
119  {
120  // see #43205
121  if ($this->mode_manager->isActiveItemOrdering()) {
122  if ($type === "sess" && $this->container->getViewMode() === \ilContainer::VIEW_SESSIONS) {
123  return false;
124  }
125  return true;
126  }
127  return false;
128  }
129 
130  public function forceSessionOrderingByDate(): bool
131  {
132  // see #43205
133  return ($this->container->getViewMode() === \ilContainer::VIEW_SESSIONS ||
134  $this->container->getOrderType() !== \ilContainer::SORT_MANUAL);
135  }
136 
137 
142  protected function isClassificationFilterActive(): bool
143  {
144  $ref_id = $this->container->getRefId();
145  // apply container classification filters
146  $classification = $this->domain->classification($ref_id);
148  $this->container->getRefId(),
149  $this->container->getId(),
150  $this->container->getType()
151  ) as $class_provider) {
152  $id = get_class($class_provider);
153  $current = $classification->getSelectionOfProvider($id);
154  if ($current) {
155  return true;
156  }
157  }
158  return false;
159  }
160 
164  public function filteredSubtree(): bool
165  {
166  return $this->isClassificationFilterActive() && in_array(
167  $this->container->getType(),
168  ["grp", "crs"]
169  );
170  }
171 
172  protected function init(): void
173  {
174  // already initialised?
175  if (!is_null($this->item_set)) {
176  return;
177  }
178 
179  // get item set
180  $ref_id = $this->container->getRefId();
181  if ($this->filteredSubtree()) {
182  $this->item_set = $this->domain->content()->itemSetTree($ref_id, $this->container_user_filter);
183  } else {
184  $this->item_set = $this->domain->content()->itemSetFlat(
185  $ref_id,
186  $this->container_user_filter,
188  );
189  }
190 
191  // get view
192  $view = $this->domain->content()->view($this->container);
193  // get item block sequence generator
194  $this->sequence_generator = $this->domain->content()->itemBlockSequenceGenerator(
195  $this->container,
196  $view->getBlockSequence(),
200  );
201  }
202 
203  public function hasItems(): bool
204  {
205  $this->init();
206  return $this->item_set->hasItems();
207  }
208 
210  {
211  $this->init();
212  return $this->sequence_generator->getSequence();
213  }
214 
215  public function getPageEmbeddedBlockIds(): array
216  {
217  $this->init();
218  return $this->sequence_generator->getPageEmbeddedBlockIds();
219  }
220 
221  public function getRawDataByRefId(int $ref_id): ?array
222  {
223  $this->init();
224  return $this->item_set->getRawDataByRefId($ref_id);
225  }
226 
227  public function getAllRefIds(): ?array
228  {
229  $this->init();
230  return $this->item_set->getAllRefIds();
231  }
232 
233  public function getRefIdsOfType(string $type): array
234  {
235  $this->init();
236  return $this->item_set->getRefIdsOfType($type);
237  }
238 }
Manages container subitems set.
const ANONYMOUS_USER_ID
Definition: constants.php:27
__construct(InternalDomainService $domain, \ilContainer $container, ?\ilContainerUserFilter $container_user_filter, ClipboardManager $repo_clipboard, bool $include_empty_blocks=true, ?string $lang=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:67
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Manages items in repository clipboard.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$classification
isActiveItemOrdering(string $type)
Are we currently in ordering view and the items can be ordered?
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static getValidProviders(int $a_parent_ref_id, int $a_parent_obj_id, string $a_parent_obj_type)
Get all valid providers (for parent container)