ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMMSubItemTableGUI.php
Go to the documentation of this file.
1 <?php
2 
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';
17  const F_TABLE_ALL_VALUE = 1;
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(
63  $this->lng->txt(self::F_TABLE_ENTRY_STATUS),
64  self::F_TABLE_ENTRY_STATUS
65  );
66  $table_entry_status->setOptions(
67  array(
68  self::F_TABLE_ALL_VALUE => $this->lng->txt("all"),
69  self::F_TABLE_ONLY_ACTIVE_VALUE => $this->lng->txt("only_active"),
70  self::F_TABLE_ONLY_INACTIVE_VALUE => $this->lng->txt("only_inactive"),
71  )
72  );
73  $this->addAndReadFilterItem($table_entry_status);
74  }
75 
79  protected function addAndReadFilterItem(ilFormPropertyGUI $field)
80  {
81  $this->addFilterItem($field);
82  $field->readFromSession();
83  if ($field instanceof ilCheckboxInputGUI) {
84  $this->filter[$field->getPostVar()] = $field->getChecked();
85  } else {
86  $this->filter[$field->getPostVar()] = $field->getValue();
87  }
88  }
89 
90  private function initColumns()
91  {
92  $this->addColumn($this->lng->txt('sub_parent'));
93  $this->addColumn($this->lng->txt('sub_position'));
94  $this->addColumn($this->lng->txt('sub_title'));
95  $this->addColumn($this->lng->txt('sub_type'));
96  $this->addColumn($this->lng->txt('sub_active'));
97  $this->addColumn($this->lng->txt('sub_status'));
98  $this->addColumn($this->lng->txt('sub_provider'));
99  $this->addColumn($this->lng->txt('sub_actions'));
100  }
101 
105  protected function fillRow($a_set)
106  {
107  static $position;
108  static $parent_identification_string;
109  $position++;
110  global $DIC;
111 
112  $renderer = $DIC->ui()->renderer();
113  $factory = $DIC->ui()->factory();
117  $item_facade = $a_set['facade'];
118 
119  if ($item_facade->isChild()) {
120  if (!$parent_identification_string ||
121  $parent_identification_string !== $item_facade->getParentIdentificationString()) {
122  $parent_identification_string = $item_facade->getParentIdentificationString();
123  $current_parent_identification = $this->item_repository->resolveIdentificationFromString(
124  $parent_identification_string
125  );
126  $current_parent_item = $this->item_repository->getSingleItemFromFilter($current_parent_identification);
127  $this->tpl->setVariable(
128  "PARENT_TITLE",
129  $current_parent_item instanceof hasTitle ? $current_parent_item->getTitle() : "-"
130  );
131  $position = 1;
132  }
133  }
134  $this->tpl->setVariable('IDENTIFIER', self::IDENTIFIER);
135  $this->tpl->setVariable('ID', $this->hash($item_facade->getId()));
136  $this->tpl->setVariable('NATIVE_ID', $item_facade->getId());
137  $this->tpl->setVariable('TITLE', $item_facade->getDefaultTitle());
138  $this->tpl->setVariable('PARENT', $this->getSelect($item_facade)->render());
139  $this->tpl->setVariable('STATUS', $item_facade->getStatus());
140  if ($item_facade->isActivated()) {
141  $this->tpl->touchBlock('is_active');
142  }
143  if ($item_facade->getRawItem()->isAlwaysAvailable() || !$item_facade->getRawItem()->isAvailable()) {
144  $this->tpl->touchBlock('is_active_blocked');
145  }
146 
147  $this->tpl->setVariable('POSITION', $position * 10);
148  $this->tpl->setVariable('NATIVE_POSITION', $item_facade->getRawItem()->getPosition());
149  $this->tpl->setVariable('SAVED_POSITION', $item_facade->getFilteredItem()->getPosition());
150  $this->tpl->setVariable('TYPE', $item_facade->getTypeForPresentation());
151  $this->tpl->setVariable('PROVIDER', $item_facade->getProviderNameForPresentation());
152 
153  $this->ctrl->setParameterByClass(
154  ilMMSubItemGUI::class,
156  $this->hash($a_set['identification'])
157  );
158  $this->ctrl->setParameterByClass(
159  ilMMItemTranslationGUI::class,
161  $this->hash($a_set['identification'])
162  );
163 
164  if ($this->access->hasUserPermissionTo('write')) {
165  $items[] = $factory->button()->shy(
166  $this->lng->txt(ilMMSubItemGUI::CMD_EDIT),
167  $this->ctrl->getLinkTargetByClass(ilMMSubItemGUI::class, ilMMSubItemGUI::CMD_EDIT)
168  );
169  $items[] = $factory->button()->shy(
170  $this->lng->txt(ilMMTopItemGUI::CMD_TRANSLATE),
171  $this->ctrl->getLinkTargetByClass(ilMMItemTranslationGUI::class, ilMMItemTranslationGUI::CMD_DEFAULT)
172  );
173 
174  $ditem = $factory->modal()->interruptiveItem(
175  $this->hash($a_set['identification']),
176  $item_facade->getDefaultTitle()
177  );
178 
179  $delete_modal = "";
180  if ($item_facade->isCustom()) {
181  $action = $this->ctrl->getFormActionByClass(ilMMSubItemGUI::class, ilMMSubItemGUI::CMD_DELETE);
182  $m = $factory->modal()
183  ->interruptive(
184  $this->lng->txt(ilMMSubItemGUI::CMD_DELETE),
185  $this->lng->txt(ilMMSubItemGUI::CMD_CONFIRM_DELETE),
186  $action
187  )
188  ->withAffectedItems([$ditem]);
189 
190  $items[] = $factory->button()->shy(
191  $this->lng->txt(ilMMSubItemGUI::CMD_DELETE),
192  ""
193  )->withOnClick($m->getShowSignal());
194  $delete_modal = $renderer->render([$m]);
195  }
196 
197  $move_modal = "";
198  if ($item_facade->isInterchangeable()) {
199  $action = $this->ctrl->getFormActionByClass(ilMMSubItemGUI::class, ilMMSubItemGUI::CMD_MOVE);
200  $m = $factory->modal()
201  ->interruptive(
202  $this->lng->txt(ilMMSubItemGUI::CMD_MOVE),
203  $this->lng->txt(ilMMSubItemGUI::CMD_CONFIRM_MOVE),
204  $action
205  )
206  ->withActionButtonLabel(ilMMSubItemGUI::CMD_MOVE)
207  ->withAffectedItems([$ditem]);
208  $items[] = $factory->button()->shy(
209  $this->lng->txt(ilMMSubItemGUI::CMD_MOVE . '_to_top_item'),
210  ""
211  )->withOnClick($m->getShowSignal());
212  $move_modal = $renderer->render([$m]);
213  }
214 
215  $this->tpl->setVariable(
216  'ACTIONS',
217  $move_modal . $delete_modal . $renderer->render([$factory->dropdown()->standard($items)->withLabel($this->lng->txt('sub_actions'))])
218  );
219  }
220  }
221 
227  {
228  $s = new ilSelectInputGUI('', self::IDENTIFIER . "[{$this->hash($child->getId())}][parent]");
229  $s->setOptions($this->getPossibleParentsForFormAndTable());
230  $s->setValue($this->hash($child->getParentIdentificationString()));
231 
232  return $s;
233  }
234 
238  public function getPossibleParentsForFormAndTable() : array
239  {
240  $parents = [];
241  foreach ($this->item_repository->getPossibleParentsForFormAndTable() as $identification => $name) {
242  $parents[$this->hash($identification)] = $name;
243  }
244 
245  return $parents;
246  }
247 
248  private function resolveData() : array
249  {
250  global $DIC;
251  $sub_items_for_table = $this->item_repository->getSubItemsForTable();
252 
253  // populate with facade
254  array_walk($sub_items_for_table, function (& $item) use ($DIC) {
255  $item_ident = $DIC->globalScreen()->identification()->fromSerializedIdentification($item['identification']);
256  $item_facade = $this->item_repository->repository()->getItemFacade($item_ident);
257  $item['facade'] = $item_facade;
258  });
259 
260  // filter active/inactive
261  array_filter($sub_items_for_table, function ($item_facade) {
262  if (!isset($this->filter[self::F_TABLE_ENTRY_STATUS])) {
263  return true;
264  }
265  if ($this->filter[self::F_TABLE_ENTRY_STATUS] !== self::F_TABLE_ALL_VALUE) {
266  return true;
267  }
268  if ($this->filter[self::F_TABLE_ENTRY_STATUS] == self::F_TABLE_ONLY_ACTIVE_VALUE && !$item_facade->isActivated()) {
269  return false;
270  }
271  if ($this->filter[self::F_TABLE_ENTRY_STATUS] == self::F_TABLE_ONLY_INACTIVE_VALUE && $item_facade->isActivated()) {
272  return false;
273  }
274  return true;
275  });
276 
277  return $sub_items_for_table;
278  }
279 }
getSelect(ilMMItemFacadeInterface $child)
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
setExternalSorting($a_val)
Set external sorting.
getPostVar()
Get Post Variable.
setExternalSegmentation($a_val)
Set external segmentation.
This class represents a checkbox property in a property form.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
Class ilMMSubItemTableGUI.
Class ilMMItemRepository.
setId($a_val)
Set id.
if($format !==null) $name
Definition: metadata.php:230
addAndReadFilterItem(ilFormPropertyGUI $field)
readFromSession()
Read from session.
global $DIC
Definition: goto.php:24
Class ilMMTopItemGUI ilMMSubItemGUI: ilObjMainMenuGUI ilMMSubItemGUI: ilMMItemTranslationGUI.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
render()
render table public
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
This class represents a property in a property form.
__construct(Container $dic, ilPlugin $plugin)
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.
__construct(ilMMSubItemGUI $a_parent_obj, ilMMItemRepository $item_repository, ilObjMainMenuAccess $access)
ilMMSubItemTableGUI constructor.
fillRow($a_set)
Standard Version of Fill Row.
filter()
Definition: filter.php:2
Interface ilMMItemFacadeInterface.
$factory
Definition: metadata.php:58