ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMMSubItemTableGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
23 
29 {
30  use Hasher;
31 
32  public const IDENTIFIER = 'identifier';
33  public const F_TABLE_SHOW_INACTIVE = 'table_show_inactive';
34  public const F_TABLE_ENTRY_STATUS = 'entry_status';
35  public const F_TABLE_ALL_VALUE = 1;
36  public const F_TABLE_ONLY_ACTIVE_VALUE = 2;
37  public const F_TABLE_ONLY_INACTIVE_VALUE = 3;
38 
40 
41  private array $filter;
43 
49  public function __construct(
50  ilMMSubItemGUI $a_parent_obj,
51  ilMMItemRepository $item_repository,
52  ilObjMainMenuAccess $access
53  ) {
54  $this->access = $access;
55  $this->setId(self::class);
56  $this->setExternalSorting(true);
57  $this->setExternalSegmentation(true);
58  parent::__construct($a_parent_obj);
59  $this->item_repository = $item_repository;
60  $this->lng = $this->parent_obj->lng;
61  $this->addFilterItems();
62  $this->setData($this->resolveData());
63  $this->setFormAction($this->ctrl->getFormAction($this->parent_obj));
64  if ($this->access->hasUserPermissionTo('write')) {
65  $this->addCommandButton(ilMMSubItemGUI::CMD_SAVE_TABLE, $this->lng->txt('button_save'));
66  }
67  $this->initColumns();
68  $this->setRowTemplate('tpl.sub_items.html', 'Services/MainMenu');
69  }
70 
71  protected function addFilterItems(): void
72  {
73  $table_entry_status = new ilSelectInputGUI(
74  $this->lng->txt(self::F_TABLE_ENTRY_STATUS),
75  self::F_TABLE_ENTRY_STATUS
76  );
77  $table_entry_status->setOptions(
78  array(
79  self::F_TABLE_ALL_VALUE => $this->lng->txt("all"),
80  self::F_TABLE_ONLY_ACTIVE_VALUE => $this->lng->txt("only_active"),
81  self::F_TABLE_ONLY_INACTIVE_VALUE => $this->lng->txt("only_inactive"),
82  )
83  );
84  $this->addAndReadFilterItem($table_entry_status);
85  }
86 
87  protected function addAndReadFilterItem(ilFormPropertyGUI $field): void
88  {
89  if (!$field instanceof ilTableFilterItem) {
90  return;
91  }
92  $this->addFilterItem($field);
93  $field->readFromSession();
94  if ($field instanceof ilCheckboxInputGUI) {
95  $this->filter[$field->getPostVar()] = $field->getChecked();
96  } else {
97  $this->filter[$field->getPostVar()] = $field->getValue();
98  }
99  }
100 
101  private function initColumns(): void
102  {
103  $this->addColumn($this->lng->txt('sub_parent'));
104  $this->addColumn($this->lng->txt('sub_position'));
105  $this->addColumn($this->lng->txt('sub_title'));
106  $this->addColumn($this->lng->txt('sub_type'));
107  $this->addColumn($this->lng->txt('sub_active'));
108  $this->addColumn($this->lng->txt('sub_status'));
109  $this->addColumn($this->lng->txt('sub_provider'));
110  $this->addColumn($this->lng->txt('sub_actions'));
111  }
112 
116  protected function fillRow(array $a_set): void
117  {
118  static $position;
119  static $parent_identification_string;
120  $position++;
121  global $DIC;
122 
123  $renderer = $DIC->ui()->renderer();
124  $factory = $DIC->ui()->factory();
128  $item_facade = $a_set['facade'];
129 
130  if ($item_facade->isChild()) {
131  if (!$parent_identification_string ||
132  $parent_identification_string !== $item_facade->getParentIdentificationString()) {
133  $parent_identification_string = $item_facade->getParentIdentificationString();
134  $current_parent_identification = $this->item_repository->resolveIdentificationFromString(
135  $parent_identification_string
136  );
137  $current_parent_item = $this->item_repository->getSingleItem($current_parent_identification);
138  $this->tpl->setVariable(
139  "PARENT_TITLE",
140  $current_parent_item instanceof hasTitle ? $current_parent_item->getTitle() : "-"
141  );
142  $this->tpl->setVariable(
143  "NATIVE_PARENT_ID",
144  $current_parent_item->getProviderIdentification()->serialize()
145  );
146  $this->tpl->setVariable(
147  "PARENT_ID",
148  $this->hash($current_parent_item->getProviderIdentification()->serialize())
149  );
150  $position = 1;
151  }
152  }
153  $this->tpl->setVariable('IDENTIFIER', self::IDENTIFIER);
154  $this->tpl->setVariable('ID', $this->hash($item_facade->getId()));
155  $this->tpl->setVariable('NATIVE_ID', $item_facade->getId());
156  $this->tpl->setVariable('TITLE', $item_facade->getDefaultTitle());
157  $this->tpl->setVariable('PARENT', $this->getSelect($item_facade)->render());
158  $this->tpl->setVariable('STATUS', $item_facade->getStatus());
159  if ($item_facade->isActivated()) {
160  $this->tpl->touchBlock('is_active');
161  }
162  if ($item_facade->getRawItem()->isAlwaysAvailable() || !$item_facade->getRawItem()->isAvailable()) {
163  $this->tpl->touchBlock('is_active_blocked');
164  }
165 
166  $this->tpl->setVariable('POSITION', $position * 10);
167  $this->tpl->setVariable('NATIVE_POSITION', $item_facade->getRawItem()->getPosition());
168  $this->tpl->setVariable('SAVED_POSITION', $item_facade->getFilteredItem()->getPosition());
169  $this->tpl->setVariable('TYPE', $item_facade->getTypeForPresentation());
170  $this->tpl->setVariable('PROVIDER', $item_facade->getProviderNameForPresentation());
171 
172  $this->ctrl->setParameterByClass(
173  ilMMSubItemGUI::class,
175  $this->hash($a_set['identification'])
176  );
177  $this->ctrl->setParameterByClass(
178  ilMMItemTranslationGUI::class,
180  $this->hash($a_set['identification'])
181  );
182 
183  if ($this->access->hasUserPermissionTo('write')) {
184  $items[] = $factory->button()->shy(
185  $this->lng->txt(ilMMSubItemGUI::CMD_EDIT),
186  $this->ctrl->getLinkTargetByClass(ilMMSubItemGUI::class, ilMMSubItemGUI::CMD_EDIT)
187  );
188  $items[] = $factory->button()->shy(
189  $this->lng->txt(ilMMTopItemGUI::CMD_TRANSLATE),
190  $this->ctrl->getLinkTargetByClass(ilMMItemTranslationGUI::class, ilMMItemTranslationGUI::CMD_DEFAULT)
191  );
192 
193  $ditem = $factory->modal()->interruptiveItem(
194  $this->hash($a_set['identification']),
195  $item_facade->getDefaultTitle()
196  );
197 
198  $delete_modal = "";
199  if ($item_facade->isDeletable()) {
200  $action = $this->ctrl->getFormActionByClass(ilMMSubItemGUI::class, ilMMSubItemGUI::CMD_DELETE);
201  $m = $factory->modal()
202  ->interruptive(
203  $this->lng->txt(ilMMSubItemGUI::CMD_DELETE),
205  $action
206  )
207  ->withAffectedItems([$ditem]);
208 
209  $items[] = $factory->button()->shy(
210  $this->lng->txt(ilMMSubItemGUI::CMD_DELETE),
211  ""
212  )->withOnClick($m->getShowSignal());
213  $delete_modal = $renderer->render([$m]);
214  }
215 
216  $move_modal = "";
217  if ($item_facade->isInterchangeable()) {
218  $action = $this->ctrl->getFormActionByClass(ilMMSubItemGUI::class, ilMMSubItemGUI::CMD_MOVE);
219  $m = $factory->modal()
220  ->interruptive(
221  $this->lng->txt(ilMMSubItemGUI::CMD_MOVE),
223  $action
224  )
225  ->withActionButtonLabel(ilMMSubItemGUI::CMD_MOVE)
226  ->withAffectedItems([$ditem]);
227  $items[] = $factory->button()->shy(
228  $this->lng->txt(ilMMSubItemGUI::CMD_MOVE . '_to_top_item'),
229  ""
230  )->withOnClick($m->getShowSignal());
231  $move_modal = $renderer->render([$m]);
232  }
233 
234  $this->tpl->setVariable(
235  'ACTIONS',
236  $move_modal . $delete_modal . $renderer->render([$factory->dropdown()->standard($items)->withLabel($this->lng->txt('sub_actions'))])
237  );
238  }
239  }
240 
246  {
247  $s = new ilSelectInputGUI('', self::IDENTIFIER . "[{$this->hash($child->getId())}][parent]");
248  $s->setOptions($this->getPossibleParentsForFormAndTable());
249  $s->setValue($this->hash($child->getParentIdentificationString()));
250 
251  return $s;
252  }
253 
257  public function getPossibleParentsForFormAndTable(): array
258  {
259  $parents = [];
260  foreach ($this->item_repository->getPossibleParentsForFormAndTable() as $identification => $name) {
261  $parents[$this->hash($identification)] = $name;
262  }
263 
264  return $parents;
265  }
266 
267  private function resolveData(): array
268  {
269  global $DIC;
270  $sub_items_for_table = $this->item_repository->getSubItemsForTable();
271 
272  // populate with facade
273  array_walk($sub_items_for_table, function (&$item) use ($DIC) {
274  $item_ident = $DIC->globalScreen()->identification()->fromSerializedIdentification($item['identification']);
275  $item_facade = $this->item_repository->repository()->getItemFacade($item_ident);
276  $item['facade'] = $item_facade;
277  });
278 
279  // filter active/inactive
280  array_filter($sub_items_for_table, function ($item_facade) {
281  if (!isset($this->filter[self::F_TABLE_ENTRY_STATUS])) {
282  return true;
283  }
284  if ($this->filter[self::F_TABLE_ENTRY_STATUS] !== self::F_TABLE_ALL_VALUE) {
285  return true;
286  }
287  if ($this->filter[self::F_TABLE_ENTRY_STATUS] == self::F_TABLE_ONLY_ACTIVE_VALUE && !$item_facade->isActivated()) {
288  return false;
289  }
290  if ($this->filter[self::F_TABLE_ENTRY_STATUS] == self::F_TABLE_ONLY_INACTIVE_VALUE && $item_facade->isActivated()) {
291  return false;
292  }
293  return true;
294  });
295 
296  return $sub_items_for_table;
297  }
298 }
getSelect(ilMMItemFacadeInterface $child)
setData(array $a_data)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setFormAction(string $a_form_action, bool $a_multipart=false)
addFilterItem(ilTableFilterItem $a_input_item, bool $a_optional=false)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
ilMMItemRepository $item_repository
This class represents a checkbox property in a property form.
Class ilMMSubItemTableGUI.
Class ilMMItemRepository.
setId(string $a_val)
global $DIC
Definition: feed.php:28
if($format !==null) $name
Definition: metadata.php:247
setExternalSorting(bool $a_val)
addAndReadFilterItem(ilFormPropertyGUI $field)
fillRow(array $a_set)
Standard Version of Fill Row.
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
Class ilMMTopItemGUI ilMMSubItemGUI: ilObjMainMenuGUI ilMMSubItemGUI: ilMMItemTranslationGUI.
This class represents a property in a property form.
__construct(Container $dic, ilPlugin $plugin)
__construct(ilMMSubItemGUI $a_parent_obj, ilMMItemRepository $item_repository, ilObjMainMenuAccess $access)
ilMMSubItemTableGUI constructor.
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
Interface ilMMItemFacadeInterface.
$factory
Definition: metadata.php:75
setExternalSegmentation(bool $a_val)