ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilMMSubItemTableGUI.php
Go to the documentation of this file.
1<?php
2
3use ILIAS\GlobalScreen\Scope\MainMenu\Collector\Renderer\Hasher;
5
11{
12 use Hasher;
13
14 const IDENTIFIER = 'identifier';
15 const F_TABLE_SHOW_INACTIVE = 'table_show_inactive';
16 const F_TABLE_ENTRY_STATUS = 'entry_status';
23 private $access;
27 private $filter;
32
38 public function __construct(
39 ilMMSubItemGUI $a_parent_obj,
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->addFilterItems();
51 $this->setData($this->resolveData());
52 $this->setFormAction($this->ctrl->getFormAction($this->parent_obj));
53 if ($this->access->hasUserPermissionTo('write')) {
54 $this->addCommandButton(ilMMSubItemGUI::CMD_SAVE_TABLE, $this->lng->txt('button_save'));
55 }
56 $this->initColumns();
57 $this->setRowTemplate('tpl.sub_items.html', 'Services/MainMenu');
58 }
59
60 protected function addFilterItems()
61 {
62 $table_entry_status = new ilSelectInputGUI($this->lng->txt(self::F_TABLE_ENTRY_STATUS),
63 self::F_TABLE_ENTRY_STATUS);
64 $table_entry_status->setOptions(
65 array(
66 self::F_TABLE_ALL_VALUE => $this->lng->txt("all"),
67 self::F_TABLE_ONLY_ACTIVE_VALUE => $this->lng->txt("only_active"),
68 self::F_TABLE_ONLY_INACTIVE_VALUE => $this->lng->txt("only_inactive"),
69 )
70 );
71 $this->addAndReadFilterItem($table_entry_status);
72 }
73
77 protected function addAndReadFilterItem(ilFormPropertyGUI $field)
78 {
79 $this->addFilterItem($field);
80 $field->readFromSession();
81 if ($field instanceof ilCheckboxInputGUI) {
82 $this->filter[$field->getPostVar()] = $field->getChecked();
83 } else {
84 $this->filter[$field->getPostVar()] = $field->getValue();
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
103 protected function fillRow($a_set)
104 {
105 static $position;
106 static $parent_identification_string;
107 $position++;
108 global $DIC;
109
110 $renderer = $DIC->ui()->renderer();
111 $factory = $DIC->ui()->factory();
115 $item_facade = $a_set['facade'];
116
117 if ($item_facade->isChild()) {
118 if (!$parent_identification_string ||
119 $parent_identification_string !== $item_facade->getParentIdentificationString()) {
120 $parent_identification_string = $item_facade->getParentIdentificationString();
121 $current_parent_identification = $this->item_repository->resolveIdentificationFromString($parent_identification_string);
122 $current_parent_item = $this->item_repository->getSingleItemFromFilter($current_parent_identification);
123 $this->tpl->setVariable("PARENT_TITLE",
124 $current_parent_item instanceof hasTitle ? $current_parent_item->getTitle() : "-");
125 $position = 1;
126 }
127 }
128 $this->tpl->setVariable('IDENTIFIER', self::IDENTIFIER);
129 $this->tpl->setVariable('ID', $this->hash($item_facade->getId()));
130 $this->tpl->setVariable('NATIVE_ID', $item_facade->getId());
131 $this->tpl->setVariable('TITLE', $item_facade->getDefaultTitle());
132 $this->tpl->setVariable('PARENT', $this->getSelect($item_facade)->render());
133 $this->tpl->setVariable('STATUS', $item_facade->getStatus());
134 if ($item_facade->isActivated()) {
135 $this->tpl->touchBlock('is_active');
136 }
137 if ($item_facade->getRawItem()->isAlwaysAvailable() || !$item_facade->getRawItem()->isAvailable()) {
138 $this->tpl->touchBlock('is_active_blocked');
139 }
140
141 $this->tpl->setVariable('POSITION', $position * 10);
142 $this->tpl->setVariable('NATIVE_POSITION', $item_facade->getRawItem()->getPosition());
143 $this->tpl->setVariable('SAVED_POSITION', $item_facade->getFilteredItem()->getPosition());
144 $this->tpl->setVariable('TYPE', $item_facade->getTypeForPresentation());
145 $this->tpl->setVariable('PROVIDER', $item_facade->getProviderNameForPresentation());
146
147 $this->ctrl->setParameterByClass(ilMMSubItemGUI::class, ilMMSubItemGUI::IDENTIFIER,
148 $this->hash($a_set['identification']));
149 $this->ctrl->setParameterByClass(ilMMItemTranslationGUI::class, ilMMItemTranslationGUI::IDENTIFIER,
150 $this->hash($a_set['identification']));
151
152 if ($this->access->hasUserPermissionTo('write')) {
153 $items[] = $factory->button()->shy($this->lng->txt(ilMMSubItemGUI::CMD_EDIT),
154 $this->ctrl->getLinkTargetByClass(ilMMSubItemGUI::class, ilMMSubItemGUI::CMD_EDIT));
155 $items[] = $factory->button()->shy($this->lng->txt(ilMMTopItemGUI::CMD_TRANSLATE),
156 $this->ctrl->getLinkTargetByClass(ilMMItemTranslationGUI::class, ilMMItemTranslationGUI::CMD_DEFAULT));
157
158 $ditem = $factory->modal()->interruptiveItem($this->hash($a_set['identification']),
159 $item_facade->getDefaultTitle());
160
161 $delete_modal = "";
162 if ($item_facade->isCustom()) {
163 $action = $this->ctrl->getFormActionByClass(ilMMSubItemGUI::class, ilMMSubItemGUI::CMD_DELETE);
164 $m = $factory->modal()
165 ->interruptive($this->lng->txt(ilMMSubItemGUI::CMD_DELETE),
166 $this->lng->txt(ilMMSubItemGUI::CMD_CONFIRM_DELETE), $action)
167 ->withAffectedItems([$ditem]);
168
169 $items[] = $factory->button()->shy($this->lng->txt(ilMMSubItemGUI::CMD_DELETE),
170 "")->withOnClick($m->getShowSignal());
171 $delete_modal = $renderer->render([$m]);
172 }
173
174 $move_modal = "";
175 if ($item_facade->isInterchangeable()) {
176 $action = $this->ctrl->getFormActionByClass(ilMMSubItemGUI::class, ilMMSubItemGUI::CMD_MOVE);
177 $m = $factory->modal()
178 ->interruptive($this->lng->txt(ilMMSubItemGUI::CMD_MOVE),
179 $this->lng->txt(ilMMSubItemGUI::CMD_CONFIRM_MOVE), $action)
180 ->withActionButtonLabel(ilMMSubItemGUI::CMD_MOVE)
181 ->withAffectedItems([$ditem]);
182 $items[] = $factory->button()->shy($this->lng->txt(ilMMSubItemGUI::CMD_MOVE . '_to_top_item'),
183 "")->withOnClick($m->getShowSignal());
184 $move_modal = $renderer->render([$m]);
185 }
186
187 $this->tpl->setVariable('ACTIONS',
188 $move_modal . $delete_modal . $renderer->render([$factory->dropdown()->standard($items)->withLabel($this->lng->txt('sub_actions'))]));
189 }
190 }
191
197 {
198 $s = new ilSelectInputGUI('', self::IDENTIFIER . "[{$this->hash($child->getId())}][parent]");
199 $s->setOptions($this->getPossibleParentsForFormAndTable());
200 $s->setValue($this->hash($child->getParentIdentificationString()));
201
202 return $s;
203 }
204
208 public function getPossibleParentsForFormAndTable() : array
209 {
210 $parents = [];
211 foreach ($this->item_repository->getPossibleParentsForFormAndTable() as $identification => $name) {
212 $parents[$this->hash($identification)] = $name;
213 }
214
215 return $parents;
216 }
217
218 private function resolveData() : array
219 {
220 global $DIC;
221 $sub_items_for_table = $this->item_repository->getSubItemsForTable();
222
223 // populate with facade
224 array_walk($sub_items_for_table, function (&$item) use ($DIC) {
225 $item_ident = $DIC->globalScreen()->identification()->fromSerializedIdentification($item['identification']);
226 $item_facade = $this->item_repository->repository()->getItemFacade($item_ident);
227 $item['facade'] = $item_facade;
228 });
229
230 // filter active/inactive
231 array_filter($sub_items_for_table, function ($item_facade) {
232 if (!isset($this->filter[self::F_TABLE_ENTRY_STATUS])) {
233 return true;
234 }
235 if ($this->filter[self::F_TABLE_ENTRY_STATUS] !== self::F_TABLE_ALL_VALUE) {
236 return true;
237 }
238 if ($this->filter[self::F_TABLE_ENTRY_STATUS] == self::F_TABLE_ONLY_ACTIVE_VALUE && !$item_facade->isActivated()) {
239 return false;
240 }
241 if ($this->filter[self::F_TABLE_ENTRY_STATUS] == self::F_TABLE_ONLY_INACTIVE_VALUE && $item_facade->isActivated()) {
242 return false;
243 }
244 return true;
245 });
246
247 return $sub_items_for_table;
248 }
249}
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.
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
Definition: confirmReg.php:12
Interface ilMMItemFacadeInterface.
$factory
Definition: metadata.php:58
if($format !==null) $name
Definition: metadata.php:230
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$DIC
Definition: xapitoken.php:46