ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilMMTopItemTableGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
28 {
29  use Hasher;
30 
32 
34 
41  public function __construct(ilMMTopItemGUI $a_parent_obj, ilMMItemRepository $item_repository, ilObjMainMenuAccess $access)
42  {
43  $this->access = $access;
44  $this->setId(self::class);
45  $this->setExternalSorting(true);
46  $this->setExternalSegmentation(true);
47  parent::__construct($a_parent_obj);
48  $this->item_repository = $item_repository;
49  $this->lng = $this->parent_obj->lng;
50  $this->setData($this->resolveData());
51  $this->setFormAction($this->ctrl->getFormAction($this->parent_obj));
52  if ($this->access->hasUserPermissionTo('write')) {
53  $this->addCommandButton(ilMMTopItemGUI::CMD_SAVE_TABLE, $this->lng->txt('button_save'));
54  }
55  $this->initColumns();
56  $this->setRowTemplate('tpl.top_items.html', 'Services/MainMenu');
57  }
58 
59  private function initColumns(): void
60  {
61  $this->addColumn($this->lng->txt('topitem_position'), '', '30px');
62  $this->addColumn($this->lng->txt('topitem_title'));
63  $this->addColumn($this->lng->txt('topitem_active'));
64  $this->addColumn($this->lng->txt('topitem_subentries'));
65  $this->addColumn($this->lng->txt('topitem_css_id'));
66  $this->addColumn($this->lng->txt('topitem_type'));
67  $this->addColumn($this->lng->txt('topitem_provider'));
68  $this->addColumn($this->lng->txt('topitem_actions'));
69  }
70 
74  protected function fillRow(array $a_set): void
75  {
76  static $position;
77  $position++;
78  global $DIC;
79  $renderer = $DIC->ui()->renderer();
80  $factory = $DIC->ui()->factory();
81 
82  $item_facade = $this->item_repository->repository()->getItemFacade($DIC->globalScreen()->identification()->fromSerializedIdentification($a_set['identification']));
83 
84  $this->tpl->setVariable('IDENTIFIER', ilMMAbstractItemGUI::IDENTIFIER);
85  $this->tpl->setVariable('ID', $this->hash($item_facade->getId()));
86  $this->tpl->setVariable('NATIVE_ID', $item_facade->getId());
87  $this->tpl->setVariable('TITLE', $item_facade->getDefaultTitle());
88  $this->tpl->setVariable('SUBENTRIES', $item_facade->getAmountOfChildren());
89  $this->tpl->setVariable('TYPE', $item_facade->getTypeForPresentation());
90  $this->tpl->setVariable('CSS_ID', "mm_" . $item_facade->identification()->getInternalIdentifier());
91  $this->tpl->setVariable('POSITION', $position * 10);
92  $this->tpl->setVariable('NATIVE_POSITION', $item_facade->getRawItem()->getPosition());
93  $this->tpl->setVariable('SAVED_POSITION', $item_facade->getFilteredItem()->getPosition());
94  if ($item_facade->isActivated()) {
95  $this->tpl->touchBlock('is_active');
96  }
97  if ($item_facade->isAlwaysAvailable() || !$item_facade->isAvailable()) {
98  $this->tpl->touchBlock('is_active_blocked');
99  }
100  $this->tpl->setVariable('PROVIDER', $item_facade->getProviderNameForPresentation());
101 
102  $this->ctrl->setParameterByClass(ilMMTopItemGUI::class, ilMMAbstractItemGUI::IDENTIFIER, $this->hash($a_set['identification']));
103  $this->ctrl->setParameterByClass(ilMMItemTranslationGUI::class, ilMMItemTranslationGUI::IDENTIFIER, $this->hash($a_set['identification']));
104 
105  if ($this->access->hasUserPermissionTo('write')) {
106  $items = [];
107  if ($item_facade->isEditable()) {
108  $items[] = $factory->button()->shy($this->lng->txt(ilMMTopItemGUI::CMD_EDIT), $this->ctrl->getLinkTargetByClass(ilMMTopItemGUI::class, ilMMTopItemGUI::CMD_EDIT));
109  $items[] = $factory->button()
110  ->shy($this->lng->txt(ilMMTopItemGUI::CMD_TRANSLATE), $this->ctrl->getLinkTargetByClass(ilMMItemTranslationGUI::class, ilMMItemTranslationGUI::CMD_DEFAULT));
111  }
112 
113  $rendered_modal = "";
114  if ($item_facade->isDeletable()) {
115  $ditem = $factory->modal()->interruptiveItem()->standard($this->hash($a_set['identification']), $item_facade->getDefaultTitle());
116  $action = $this->ctrl->getFormActionByClass(ilMMTopItemGUI::class, ilMMTopItemGUI::CMD_DELETE);
117  $m = $factory->modal()
118  ->interruptive($this->lng->txt(ilMMTopItemGUI::CMD_DELETE), $this->lng->txt(ilMMTopItemGUI::CMD_CONFIRM_DELETE), $action)
119  ->withAffectedItems([$ditem]);
120 
121  $items[] = $shy = $factory->button()->shy($this->lng->txt(ilMMTopItemGUI::CMD_DELETE), "")->withOnClick($m->getShowSignal());
122  // $items[] = $factory->button()->shy($this->lng->txt(ilMMSubItemGUI::CMD_DELETE), $this->ctrl->getLinkTargetByClass(ilMMSubItemGUI::class, ilMMSubItemGUI::CMD_CONFIRM_DELETE));
123  $rendered_modal = $renderer->render([$m]);
124  }
125  if ($item_facade->isInterchangeable()) {
126  $items[] = $factory->button()->shy($this->lng->txt(ilMMTopItemGUI::CMD_MOVE . '_to_item'), $this->ctrl->getLinkTargetByClass(ilMMTopItemGUI::class, ilMMTopItemGUI::CMD_SELECT_PARENT));
127  }
128  $this->tpl->setVariable('ACTIONS', $rendered_modal . $renderer->render([$factory->dropdown()->standard($items)->withLabel($this->lng->txt('sub_actions'))]));
129  }
130  }
131 
135  private function resolveData(): array
136  {
137  return $this->item_repository->getTopItems();
138  }
139 }
setData(array $a_data)
ilMMItemRepository $item_repository
setFormAction(string $a_form_action, bool $a_multipart=false)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
Class ilMMItemRepository.
setId(string $a_val)
global $DIC
Definition: feed.php:28
setExternalSorting(bool $a_val)
__construct(VocabulariesInterface $vocabularies)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
Class ilMMTopItemGUI ilMMTopItemGUI: ilObjMainMenuGUI ilMMTopItemGUI: ilMMItemTranslationGUI.
__construct(ilMMTopItemGUI $a_parent_obj, ilMMItemRepository $item_repository, ilObjMainMenuAccess $access)
ilMMTopItemTableGUI 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)
Class ilMMTopItemTableGUI.
setExternalSegmentation(bool $a_val)