ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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
111 if (isset($values[self::F_POLL_INTERVAL])) {
112 $poll_interval = $poll_interval->withValue($values[self::F_POLL_INTERVAL]);
113 }
114
115 $section = $this->ui_factory->input()->field()->section(
116 [self::F_POLL_INTERVAL => $poll_interval],
117 $this->lng->txt("lso_admin_form_title"),
118 $this->lng->txt("lso_admin_form_byline")
119 );
120
121 return $this->ui_factory->input()->container()->form()
122 ->standard($target, [$section])
123 ->withAdditionalTransformation(
124 $this->refinery->custom()->transformation(
125 fn ($data) => array_shift($data)
126 )
127 );
128 }
129
130 protected function show(Input\Container\Form\Form $form): void
131 {
132 $this->tpl->setContent(
133 $this->ui_renderer->render($form)
134 );
135 }
136
137 protected function edit(): void
138 {
139 $values = [
140 self::F_POLL_INTERVAL => $this->settings_db->getSettings()->getPollingIntervalSeconds()
141 ];
142 $form = $this->getForm($values);
143 $this->show($form);
144 }
145
146 protected function save(): void
147 {
148 $form = $this->getForm()->withRequest($this->request);
149 $data = $form->getData();
150 if ($data) {
151 $settings = $this->settings_db->getSettings()
152 ->withPollingIntervalSeconds($data[self::F_POLL_INTERVAL]);
153 $this->settings_db->storeSettings($settings);
154 $this->tpl->setOnScreenMessage('success', $this->lng->txt("settings_saved"), true);
155 }
156 $this->show($form);
157 }
158}
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