ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ItemPresentationManager.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Container\Content;
22 
26 
34 {
35  protected ?string $lang = null;
36  protected bool $include_empty_blocks;
38  protected ?bool $can_order = null;
39  protected ClipboardManager $repo_clipboard;
40  protected ?bool $can_manage = null;
43  protected ?array $type_grps = null;
45  protected \ilContainer $container;
48 
49  public function __construct(
50  InternalDomainService $domain,
51  \ilContainer $container,
52  ?\ilContainerUserFilter $container_user_filter,
53  ClipboardManager $repo_clipboard,
54  bool $include_empty_blocks = true,
55  ?string $lang = null
56  ) {
57  $this->container = $container;
58  $this->domain = $domain;
59  $this->container_user_filter = $container_user_filter;
60  $this->repo_clipboard = $repo_clipboard;
61  $this->mode_manager = $domain->content()->mode($container);
62  $this->include_empty_blocks = $include_empty_blocks;
63  $this->lang = $lang;
64 
65  // sequence from view manager
66  }
67 
68  public function canManageItems(): bool
69  {
70  if (!is_null($this->can_manage)) {
71  return $this->can_manage;
72  }
73  $user = $this->domain->user();
74  $rbacsystem = $this->domain->rbac()->system();
75  if ($user->getId() === ANONYMOUS_USER_ID || !is_object($this->container)) {
76  return false;
77  }
78 
79  if ($rbacsystem->checkAccess("write", $this->container->getRefId()) ||
80  $this->container->getHiddenFilesFound() ||
81  $this->repo_clipboard->hasEntries()) {
82  $this->can_manage = true;
83  return true;
84  }
85  $this->init();
86  $this->can_manage = false;
87  /* this is time consuming and probably not necessary
88  foreach ($this->item_set->getAllRefIds() as $ref_id) {
89  if ($this->can_manage === true) {
90  break;
91  }
92  if ($rbacsystem->checkAccess("delete", $ref_id)) {
93  $this->can_manage = true;
94  }
95  }*/
96  return $this->can_manage;
97  }
98 
102  public function canOrderItems(): bool
103  {
104  $user = $this->domain->user();
105  $rbacsystem = $this->domain->rbac()->system();
106 
107  if (is_null($this->can_order)) {
108  $this->can_order = false;
109  if ($user->getId() !== ANONYMOUS_USER_ID &&
110  is_object($this->container) &&
111  $rbacsystem->checkAccess("write", $this->container->getRefId())) {
112  $this->can_order = (\ilContainerSortingSettings::_lookupSortMode($this->container->getId()) === \ilContainer::SORT_MANUAL);
113  }
114  }
115  return $this->can_order;
116  }
117 
121  public function isActiveItemOrdering(string $type): bool
122  {
123  // see #43205
124  if ($this->mode_manager->isActiveItemOrdering()) {
125  if ($type === "sess" && $this->container->getViewMode() === \ilContainer::VIEW_SESSIONS) {
126  return false;
127  }
128  return true;
129  }
130  return false;
131  }
132 
133  public function forceSessionOrderingByDate(): bool
134  {
135  // see #43205
136  return ($this->container->getViewMode() === \ilContainer::VIEW_SESSIONS ||
137  $this->container->getOrderType() !== \ilContainer::SORT_MANUAL);
138  }
139 
140 
145  protected function isClassificationFilterActive(): bool
146  {
147  $ref_id = $this->container->getRefId();
148  // apply container classification filters
149  $classification = $this->domain->classification($ref_id);
151  $this->container->getRefId(),
152  $this->container->getId(),
153  $this->container->getType()
154  ) as $class_provider) {
155  $id = get_class($class_provider);
156  $current = $classification->getSelectionOfProvider($id);
157  if ($current) {
158  return true;
159  }
160  }
161  return false;
162  }
163 
167  public function filteredSubtree(): bool
168  {
169  return $this->isClassificationFilterActive() && in_array(
170  $this->container->getType(),
171  ["grp", "crs"]
172  );
173  }
174 
175  protected function init(): void
176  {
177  // already initialised?
178  if (!is_null($this->item_set)) {
179  return;
180  }
181 
182  // get item set
183  $ref_id = $this->container->getRefId();
184  if ($this->filteredSubtree()) {
185  $this->item_set = $this->domain->content()->itemSetTree($ref_id, $this->container_user_filter);
186  } else {
187  $this->item_set = $this->domain->content()->itemSetFlat(
188  $ref_id,
189  $this->container_user_filter,
191  );
192  }
193 
194  // get view
195  $view = $this->domain->content()->view($this->container);
196  // get item block sequence generator
197  $this->sequence_generator = $this->domain->content()->itemBlockSequenceGenerator(
198  $this->container,
199  $view->getBlockSequence(),
203  );
204  }
205 
206  public function hasItems(): bool
207  {
208  $this->init();
209  return $this->item_set->hasItems();
210  }
211 
212  public function getItemBlockSequence(): ItemBlockSequence
213  {
214  $this->init();
215  return $this->sequence_generator->getSequence();
216  }
217 
218  public function getPageEmbeddedBlockIds(): array
219  {
220  $this->init();
221  return $this->sequence_generator->getPageEmbeddedBlockIds();
222  }
223 
224  public function getRawDataByRefId(int $ref_id): ?array
225  {
226  $this->init();
227  return $this->item_set->getRawDataByRefId($ref_id);
228  }
229 
230  public function getAllRefIds(): ?array
231  {
232  $this->init();
233  return $this->item_set->getAllRefIds();
234  }
235 
236  public function getRefIdsOfType(string $type): array
237  {
238  $this->init();
239  return $this->item_set->getRefIdsOfType($type);
240  }
241 }
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...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$ref_id
Definition: ltiauth.php:65
Class ilContainer.
$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)