ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilObjLearningSequenceAdminGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
31{
32 public const CMD_VIEW = 'view';
33 public const CMD_EDIT = 'edit';
34 public const CMD_SAVE = 'save';
35 public const F_POLL_INTERVAL = 'polling';
36
39 protected \ILIAS\Refinery\Factory $refinery;
41
42 public function __construct($data, int $id, bool $call_by_reference = true, bool $prepare_output = true)
43 {
44 $this->type = 'lsos';
45
46 global $DIC;
47 $this->ctrl = $DIC['ilCtrl'];
48
50
51 $this->settings_db = new ilLSGlobalSettingsDB($DIC['ilSetting']);
52 $this->ui_factory = $DIC['ui.factory'];
53 $this->ui_renderer = $DIC['ui.renderer'];
54 $this->refinery = $DIC['refinery'];
55 $this->request = $DIC->http()->request();
56 }
57
58 public function getAdminTabs(): void
59 {
60 $this->tabs_gui->addTarget('settings', $this->ctrl->getLinkTargetByClass(self::class, self::CMD_EDIT));
61 if ($this->rbac_system->checkAccess('edit_permission', $this->object->getRefId())) {
62 $this->tabs_gui->addTarget('perm_settings', $this->ctrl->getLinkTargetByClass('ilpermissiongui', 'perm'), array(), 'ilpermissiongui');
63 }
64 }
65
66 public function executeCommand(): void
67 {
68 $this->checkPermission('read');
69 $next_class = $this->ctrl->getNextClass($this);
70 $cmd = $this->ctrl->getCmd();
71 $this->prepareOutput();
72
73 switch ($next_class) {
74 case 'ilpermissiongui':
75 $this->tabs_gui->setTabActive('perm_settings');
76 $perm_gui = new ilPermissionGUI($this);
77 $this->ctrl->forwardCommand($perm_gui);
78 break;
79
80 default:
81 switch ($cmd) {
82 case self::CMD_VIEW:
83 case self::CMD_EDIT:
84 $this->edit();
85 break;
86 case self::CMD_SAVE:
87 $this->save();
88 break;
89 default:
90 throw new Exception(__METHOD__ . " :: Unknown command " . $cmd);
91 }
92 }
93 }
94
95 protected function getForm(array $values = []): Input\Container\Form\Form
96 {
97 $target = $this->ctrl->getLinkTargetByClass(self::class, self::CMD_SAVE);
98 $poll_interval = $this->ui_factory->input()->field()->numeric(
99 $this->lng->txt("lso_admin_interval_label"),
100 $this->lng->txt("lso_admin_interval_byline")
101 )
102 ->withAdditionalTransformation(
103 $this->refinery->int()->isGreaterThan(0)
104 )
105 ->withAdditionalTransformation(
106 $this->refinery->custom()->transformation(
107 fn($v) => (float) $v
108 )
109 );
110 if (!$this->_checkPermission('edit_permission')) {
111 $poll_interval = $poll_interval->withDisabled(true);
112 }
113
114 if (isset($values[self::F_POLL_INTERVAL])) {
115 $poll_interval = $poll_interval->withValue($values[self::F_POLL_INTERVAL]);
116 }
117
118 $section = $this->ui_factory->input()->field()->section(
119 [self::F_POLL_INTERVAL => $poll_interval],
120 $this->lng->txt("lso_admin_form_title"),
121 $this->lng->txt("lso_admin_form_byline")
122 );
123
124 return $this->ui_factory->input()->container()->form()
125 ->standard($target, [$section])
126 ->withAdditionalTransformation(
127 $this->refinery->custom()->transformation(
128 fn($data) => array_shift($data)
129 )
130 );
131 }
132
133 protected function show(Input\Container\Form\Form $form): void
134 {
135 $this->tpl->setContent(
136 $this->ui_renderer->render($form)
137 );
138 }
139
140 protected function edit(): void
141 {
142 $values = [
143 self::F_POLL_INTERVAL => $this->settings_db->getSettings()->getPollingIntervalSeconds()
144 ];
145 $form = $this->getForm($values);
146 $this->show($form);
147 }
148
149 protected function save(): void
150 {
151 if (!$this->_checkPermission('edit_permission')) {
152 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('no_permission'));
153 $this->edit();
154 return;
155 }
156 $form = $this->getForm()->withRequest($this->request);
157 $data = $form->getData();
158 if ($data) {
159 $settings = $this->settings_db->getSettings()
160 ->withPollingIntervalSeconds($data[self::F_POLL_INTERVAL]);
161 $this->settings_db->storeSettings($settings);
162 $this->tpl->setOnScreenMessage('success', $this->lng->txt("settings_saved"), true);
163 }
164 $this->show($form);
165 }
166 public function _checkPermission(string $permission): bool
167 {
168 return $this->rbac_system->checkAccess($permission, $this->object->getRefId());
169 }
170}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Repository for LSGlobalSettings over ILIAS global settings.
LearningSequence Administration Settings.
__construct($data, int $id, bool $call_by_reference=true, bool $prepare_output=true)
getAdminTabs()
administration tabs show only permissions and trash folder
Class ilObjectGUI Basic methods of all Output classes.
checkPermission(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
ilSetting $settings
prepareOutput(bool $show_sub_objects=true)
This is how a factory for inputs looks like.
Definition: Factory.php:27
This describes commonalities between all inputs.
Definition: Input.php:47
An entity that renders components to a string output.
Definition: Renderer.php:31
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26