ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMMSubItemTableGUI.php
Go to the documentation of this file.
1<?php
2
3use ILIAS\GlobalScreen\Scope\MainMenu\Collector\Renderer\Hasher;
4
11{
12 use Hasher;
13 const IDENTIFIER = 'identifier';
14 const F_TABLE_SHOW_INACTIVE = 'table_show_inactive';
15 const F_TABLE_ENTRY_STATUS = 'entry_status';
22 private $access;
26 private $filter;
31
32
40 {
41 $this->access = $access;
42 $this->setId(self::class);
43 $this->setExternalSorting(true);
44 $this->setExternalSegmentation(true);
45 parent::__construct($a_parent_obj);
46 $this->item_repository = $item_repository;
47 $this->lng = $this->parent_obj->lng;
48 $this->addFilterItems();
49 $this->setData($this->resolveData());
50 $this->setFormAction($this->ctrl->getFormAction($this->parent_obj));
51 if ($this->access->hasUserPermissionTo('write')) {
52 $this->addCommandButton(ilMMSubItemGUI::CMD_SAVE_TABLE, $this->lng->txt('button_save'));
53 }
54 $this->initColumns();
55 $this->setRowTemplate('tpl.sub_items.html', 'Services/MainMenu');
56 }
57
58
59 protected function addFilterItems()
60 {
61 $table_entry_status = new ilSelectInputGUI($this->lng->txt(self::F_TABLE_ENTRY_STATUS), self::F_TABLE_ENTRY_STATUS);
62 $table_entry_status->setOptions(
63 array(
64 self::F_TABLE_ALL_VALUE => $this->lng->txt("all"),
65 self::F_TABLE_ONLY_ACTIVE_VALUE => $this->lng->txt("only_active"),
66 self::F_TABLE_ONLY_INACTIVE_VALUE => $this->lng->txt("only_inactive"),
67 )
68 );
69 $this->addAndReadFilterItem($table_entry_status);
70 }
71
72
76 protected function addAndReadFilterItem(ilFormPropertyGUI $field)
77 {
78 $this->addFilterItem($field);
79 $field->readFromSession();
80 if ($field instanceof ilCheckboxInputGUI) {
81 $this->filter[$field->getPostVar()] = $field->getChecked();
82 } else {
83 $this->filter[$field->getPostVar()] = $field->getValue();
84 }
85 }
86
87
88 private function initColumns()
89 {
90 $this->addColumn($this->lng->txt('sub_parent'));
91 $this->addColumn($this->lng->txt('sub_position'));
92 $this->addColumn($this->lng->txt('sub_title'));
93 $this->addColumn($this->lng->txt('sub_type'));
94 $this->addColumn($this->lng->txt('sub_active'));
95 $this->addColumn($this->lng->txt('sub_status'));
96 $this->addColumn($this->lng->txt('sub_provider'));
97 $this->addColumn($this->lng->txt('sub_actions'));
98 }
99
100
104 protected function fillRow($a_set)
105 {
106 static $position;
107 static $current_parent;
108 $position++;
109 global $DIC;
110
111 $renderer = $DIC->ui()->renderer();
112 $factory = $DIC->ui()->factory();
116 $item_facade = $a_set['facade'];
117
118 if (!$current_parent || $current_parent->getProviderIdentification() !== $item_facade->item()->getParent()) {
119 $current_parent = $this->item_repository->getSingleItem($item_facade->item()->getParent());
120 $this->tpl->setVariable("PARENT_TITLE", $current_parent->getTitle());
121 $position = 1;
122 }
123 $this->tpl->setVariable('IDENTIFIER', self::IDENTIFIER);
124 $this->tpl->setVariable('ID', $this->hash($item_facade->getId()));
125 $this->tpl->setVariable('TITLE', $item_facade->getDefaultTitle());
126 $this->tpl->setVariable('PARENT', $this->getSelect($item_facade)->render());
127 $this->tpl->setVariable('STATUS', $item_facade->getStatus());
128 if ($item_facade->isActivated()) {
129 $this->tpl->touchBlock('is_active');
130 }
131 if ($item_facade->item()->isAlwaysAvailable() || !$item_facade->item()->isAvailable()) {
132 $this->tpl->touchBlock('is_active_blocked');
133 }
134
135 $this->tpl->setVariable('POSITION', $position * 10);
136 $this->tpl->setVariable('TYPE', $item_facade->getTypeForPresentation());
137 $this->tpl->setVariable('PROVIDER', $item_facade->getProviderNameForPresentation());
138
139 $this->ctrl->setParameterByClass(ilMMSubItemGUI::class, ilMMSubItemGUI::IDENTIFIER, $this->hash($a_set['identification']));
140 $this->ctrl->setParameterByClass(ilMMItemTranslationGUI::class, ilMMItemTranslationGUI::IDENTIFIER, $this->hash($a_set['identification']));
141
142 if ($this->access->hasUserPermissionTo('write')) {
143 $items[] = $factory->button()->shy($this->lng->txt(ilMMSubItemGUI::CMD_EDIT), $this->ctrl->getLinkTargetByClass(ilMMSubItemGUI::class, ilMMSubItemGUI::CMD_EDIT));
144 $items[] = $factory->button()->shy($this->lng->txt(ilMMTopItemGUI::CMD_TRANSLATE), $this->ctrl->getLinkTargetByClass(ilMMItemTranslationGUI::class, ilMMItemTranslationGUI::CMD_DEFAULT));
145
146 $rendered_modal = "";
147 if ($item_facade->isDeletable()) {
148 $ditem = $factory->modal()->interruptiveItem($this->hash($a_set['identification']), $item_facade->getDefaultTitle());
149 $action = $this->ctrl->getFormActionByClass(ilMMSubItemGUI::class, ilMMSubItemGUI::CMD_DELETE);
150 $m = $factory->modal()
151 ->interruptive($this->lng->txt(ilMMSubItemGUI::CMD_DELETE), $this->lng->txt(ilMMSubItemGUI::CMD_CONFIRM_DELETE), $action)
152 ->withAffectedItems([$ditem]);
153
154 $items[] = $shy = $factory->button()->shy($this->lng->txt(ilMMSubItemGUI::CMD_DELETE), "")->withOnClick($m->getShowSignal());
155 // $items[] = $factory->button()->shy($this->lng->txt(ilMMSubItemGUI::CMD_DELETE), $this->ctrl->getLinkTargetByClass(ilMMSubItemGUI::class, ilMMSubItemGUI::CMD_CONFIRM_DELETE));
156 $rendered_modal = $renderer->render([$m]);
157 }
158
159 $this->tpl->setVariable('ACTIONS', $rendered_modal . $renderer->render([$factory->dropdown()->standard($items)->withLabel($this->lng->txt('sub_actions'))]));
160 }
161 }
162
163
170 {
171 $s = new ilSelectInputGUI('', self::IDENTIFIER . "[{$this->hash($child->getId())}][parent]");
172 $s->setOptions($this->getPossibleParentsForFormAndTable());
173 $s->setValue($this->hash($child->getParentIdentificationString()));
174
175 return $s;
176 }
177
178
182 public function getPossibleParentsForFormAndTable() : array
183 {
184 $parents = [];
185 foreach ($this->item_repository->getPossibleParentsForFormAndTable() as $identification => $name) {
186 $parents[$this->hash($identification)] = $name;
187 }
188
189 return $parents;
190 }
191
192
193 private function resolveData() : array
194 {
195 global $DIC;
196 $sub_items_for_table = $this->item_repository->getSubItemsForTable();
197
198 foreach ($sub_items_for_table as $k => $item) {
199 $item_facade = $this->item_repository->repository()->getItemFacade($DIC->globalScreen()->identification()->fromSerializedIdentification($item['identification']));
200 $sub_items_for_table[$k]['facade'] = $item_facade;
201 if (isset($this->filter[self::F_TABLE_ENTRY_STATUS]) && $this->filter[self::F_TABLE_ENTRY_STATUS] !== self::F_TABLE_ALL_VALUE) {
202 if (($this->filter[self::F_TABLE_ENTRY_STATUS] == self::F_TABLE_ONLY_ACTIVE_VALUE && !$item_facade->isActivated())
203 || ($this->filter[self::F_TABLE_ENTRY_STATUS] == self::F_TABLE_ONLY_INACTIVE_VALUE && $item_facade->isActivated())
204 ) {
205 unset($sub_items_for_table[$k]);
206 }
207 }
208 }
209
210 return $sub_items_for_table;
211 }
212}
$factory
Definition: metadata.php:43
An exception for terminatinating execution or to throw for unit testing.
This class represents a checkbox property in a property form.
This class represents a property in a property form.
readFromSession()
Read from session.
getPostVar()
Get Post Variable.
Class ilMMItemRepository.
Class ilMMTopItemGUI @ilCtrl_IsCalledBy ilMMSubItemGUI: ilObjMainMenuGUI @ilCtrl_Calls ilMMSubItemGUI...
Class ilMMSubItemTableGUI.
getSelect(ilMMItemFacadeInterface $child)
__construct(ilMMSubItemGUI $a_parent_obj, ilMMItemRepository $item_repository, ilObjMainMenuAccess $access)
ilMMSubItemTableGUI constructor.
addAndReadFilterItem(ilFormPropertyGUI $field)
Class ilObjMainMenuAccess.
This class represents a selection list property in a property form.
Class ilTable2GUI.
setExternalSorting($a_val)
Set external sorting.
fillRow($a_set)
Standard Version of Fill Row.
render()
render table @access public
setData($a_data)
set table data @access public
setRowTemplate($a_template, $a_template_dir="")
Set row template.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
setExternalSegmentation($a_val)
Set external segmentation.
setId($a_val)
Set id.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
$action
Interface ilMMItemFacadeInterface.
hash(StreamInterface $stream, $algo, $rawOutput=false)
Calculate a hash of a Stream.
Definition: functions.php:406
$s
Definition: pwgen.php:45
global $DIC
Definition: saml.php:7