ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilDclSwitcher.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
24 protected \ILIAS\UI\Factory $ui_factory;
25 protected ilLanguage $lng;
26 protected ilCtrl $ctrl;
27
29 {
30 $this->toolbar = $toolbar;
31 $this->ui_factory = $ui_factory;
32 $this->ctrl = $ctrl;
33 $this->lng = $lng;
34 }
35
39 public function addTableSwitcherToToolbar(array $tables, string $target_class, string $target_cmd, int $table_id = 0): void
40 {
41 $this->ctrl->clearParameterByClass($target_class, 'tableview_id');
42 $links = [];
43 $current = '';
44 foreach ($tables as $table) {
45 $title = $table->getTitle();
46 if ($table->getId() == $table_id) {
47 $current = $title;
48 }
49 $title = ($current === $title ? '✓ ' : '⠀ ') . $title;
50 $this->ctrl->setParameterByClass($target_class, 'table_id', $table->getId());
51 $links[] = $this->ui_factory->link()->standard($title, $this->ctrl->getLinkTargetByClass($target_class, $target_cmd));
52 }
53 $this->ctrl->clearParameterByClass($target_class, 'table_id');
54
55 $this->addSwitcherToToolbar($links, $this->lng->txt('dcl_table') . ': ' . $current);
56 }
57
61 public function addViewSwitcherToToolbar(array $views, int $table_id, string $target_class, string $target_cmd, int $tableview_id = 0): void
62 {
63 $this->ctrl->setParameterByClass($target_class, 'table_id', $table_id);
64 $links = [];
65 $current = '';
66 foreach ($views as $view) {
67 $title = $view->getTitle();
68 if ($view->getId() == $tableview_id) {
69 $current = $title;
70 }
71 $title = ($current === $title ? '✓⠀' : '⠀⠀') . $title;
72 $this->ctrl->setParameterByClass($target_class, 'tableview_id', $view->getId());
73 $links[] = $this->ui_factory->link()->standard($title, $this->ctrl->getLinkTargetByClass($target_class, $target_cmd));
74 }
75 $this->ctrl->clearParameterByClass($target_class, 'tableview_id');
76 $this->ctrl->clearParameterByClass($target_class, 'table_id');
77
78 $this->addSwitcherToToolbar($links, $this->lng->txt('dcl_tableview') . ': ' . $current);
79 }
80
86 protected function addSwitcherToToolbar(array $links, string $label): void
87 {
88 if (count($links) > 1) {
89 $this->toolbar->addComponent(
90 $this->ui_factory->dropdown()->standard($links)->withLabel($label)
91 );
92 }
93 }
94}
Class ilCtrl provides processing control methods.
ILIAS UI Factory $ui_factory
addTableSwitcherToToolbar(array $tables, string $target_class, string $target_cmd, int $table_id=0)
addViewSwitcherToToolbar(array $views, int $table_id, string $target_class, string $target_cmd, int $tableview_id=0)
ilToolbarGUI $toolbar
addSwitcherToToolbar(array $links, string $label)
__construct(ilToolbarGUI $toolbar, \ILIAS\UI\Factory $ui_factory, ilCtrl $ctrl, ilLanguage $lng)
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.