ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjLearningSequenceSettingsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
25{
26 public const PROP_TITLE = 'title';
27 public const PROP_DESC = 'desc';
28 public const PROP_ONLINE = 'online';
29 public const PROP_AVAIL_FROM = 'start';
30 public const PROP_AVAIL_TO = 'end';
31 public const PROP_GALLERY = 'gallery';
32
33 public const CMD_EDIT = "settings";
34 public const CMD_SAVE = "update";
35 public const CMD_CANCEL = "cancel";
36
37 public function __construct(
38 protected ilObjLearningSequence $obj,
39 protected ilCtrl $ctrl,
40 protected ilLanguage $lng,
41 protected ilGlobalTemplateInterface $tpl,
42 protected ILIAS\Refinery\Factory $refinery,
43 protected ILIAS\UI\Factory $ui_factory,
44 protected ILIAS\UI\Renderer $renderer,
45 protected Psr\Http\Message\ServerRequestInterface $request
46 ) {
47 $this->lng->loadLanguageModule('content');
48 $this->lng->loadLanguageModule('obj');
49 }
50
51 public function executeCommand(): void
52 {
53 $cmd = $this->ctrl->getCmd('settings');
54
55 switch ($cmd) {
56 case self::CMD_EDIT:
57 case self::CMD_SAVE:
59 $content = $this->$cmd();
60 break;
61
62 default:
63 throw new ilException("ilObjLearningSequenceSettingsGUI: Command not supported: $cmd");
64 }
65 $this->tpl->setContent($content);
66 }
67
68 protected function settings(): string
69 {
70 return $this->renderer->render($this->buildForm(
71 $this->obj,
72 $this->ctrl->getFormAction($this, self::CMD_SAVE)
73 ));
74 }
75
76 protected function cancel(): void
77 {
78 $this->ctrl->redirectByClass(ilObjLearningSequenceGUI::class);
79 }
80
81 protected function buildForm(
83 string $submit_action
84 ): ILIAS\UI\Component\Input\Container\Form\Standard {
85 $if = $this->ui_factory->input();
86
87 $form = $if->container()->form()->standard(
88 $submit_action,
89 $this->buildFormElements(
90 $lso,
91 $if
92 )
93 );
94
95 return $form;
96 }
97
98 protected function buildFormElements(
100 ILIAS\UI\Component\Input\Factory $if
101 ) {
102 $txt = fn($id) => $this->lng->txt($id);
103 $settings = $lso->getLSSettings();
104 $activation = $lso->getLSActivation();
105 $formElements = [];
106
107 // Title & Description
108 $title = $if->field()->text($txt("title"))
109 ->withRequired(true)
110 ->withValue($lso->getTitle());
111 $description = $if->field()->text($txt("description"))
112 ->withValue($lso->getLongDescription());
113 $section_object = $if->field()->section(
114 [
115 self::PROP_TITLE => $title,
116 self::PROP_DESC => $description
117 ],
118 $txt('lso_edit')
119 );
120 $formElements['object'] = $section_object;
121
122 // Online status
123 $online = $if->field()->checkbox(
124 $txt('online'),
125 $txt('lso_activation_online_info')
126 )->withValue($activation->getIsOnline());
127 $online_start = $if->field()->dateTime($txt('from'))
128 ->withUseTime(true)
129 ->withValue(($activation->getActivationStart()) ? $activation->getActivationStart()->format('Y-m-d H:i') : '');
130 $online_end = $if->field()->dateTime($txt('to'))
131 ->withUseTime(true)
132 ->withValue(($activation->getActivationEnd()) ? $activation->getActivationEnd()->format('Y-m-d H:i') : '');
133 $section_online = $if->field()->section(
134 [
135 self::PROP_ONLINE => $online,
136 self::PROP_AVAIL_FROM => $online_start,
137 self::PROP_AVAIL_TO => $online_end
138 ],
139 $txt('lso_settings_availability')
140 )->withAdditionalTransformation(
141 $this->refinery->custom()->constraint(
142 function ($values) {
143 $start = $values[self::PROP_AVAIL_FROM] ?? '';
144 $end = $values[self::PROP_AVAIL_TO] ?? '';
145 if (($start !== '' && $end !== '') && ($end < $start)) {
146 return false;
147 }
148 return true;
149 },
150 $txt('lso_settings_availability_error')
151 )
152 );
153 $formElements['online'] = $section_online;
154
155 // Member gallery
156 $gallery = $if->field()->checkbox($txt("members_gallery"), $txt('lso_show_members_info'))
157 ->withValue($settings->getMembersGallery())
159 $this->refinery->byTrying([
160 $this->refinery->kindlyTo()->bool(),
161 $this->refinery->always(false)
162 ])
163 );
164 $section_additional = $if->field()->section(
165 [
166 self::PROP_GALLERY => $gallery
167 ],
168 $txt('obj_features')
169 );
170 $formElements['additional'] = $section_additional;
171
172 // Common properties
173 $title_icon = $lso->getObjectProperties()->getPropertyTitleAndIconVisibility()->toForm(
174 $this->lng,
175 $if->field(),
177 );
178 $header_actions = $lso->getObjectProperties()->getPropertyHeaderActionVisibility()->toForm(
179 $this->lng,
180 $if->field(),
182 );
183 $custom_icon = $lso->getObjectProperties()->getPropertyIcon()->toForm(
184 $this->lng,
185 $if->field(),
187 );
188 $image = $lso->getObjectProperties()->getPropertyTileImage()->toForm(
189 $this->lng,
190 $if->field(),
192 );
193 $section_common = $if->field()->section(
194 array_filter([
195 'icon' => $title_icon,
196 'header_actions' => $header_actions,
197 'custom_icon' => $custom_icon,
198 'image' => $image
199 ]),
200 $txt('cont_presentation')
201 );
202 $formElements['common'] = $section_common;
203
204 return $formElements;
205 }
206
207 protected function update(): ?string
208 {
209 $form = $this
210 ->buildForm($this->obj, $this->ctrl->getFormAction($this, self::CMD_SAVE))
211 ->withRequest($this->request);
212
213 $result = $form->getInputGroup()->getContent();
214
215 if ($result->isOK()) {
216 $values = $result->value();
217 $lso = $this->obj;
218
219 $lso->setTitle($values['object'][self::PROP_TITLE]);
220 $lso->setDescription($values['object'][self::PROP_DESC]);
221
222 $settings = $lso->getLSSettings()
223 ->withMembersGallery($values['additional'][self::PROP_GALLERY]);
224 $lso->updateSettings($settings);
225
226 $activation = $lso->getLSActivation()
227 ->withIsOnline($values['online'][self::PROP_ONLINE])
228 ->withActivationStart(null)
229 ->withActivationEnd(null);
230 if ($values['online'][self::PROP_AVAIL_FROM] !== null) {
231 $activation = $activation
232 ->withActivationStart(
233 DateTime::createFromImmutable($values['online'][self::PROP_AVAIL_FROM])
234 );
235 }
236 if ($values['online'][self::PROP_AVAIL_TO] !== null) {
237 $activation = $activation
238 ->withActivationEnd(
239 DateTime::createFromImmutable($values['online'][self::PROP_AVAIL_TO])
240 );
241 }
242 $lso->updateActivation($activation);
243
245 $lso->getObjectProperties()->storePropertyIsOnline(
246 new Online(! $status)
247 );
248
249 $lso->getObjectProperties()->storePropertyTitleAndIconVisibility($values['common']['icon']);
250 $lso->getObjectProperties()->storePropertyHeaderActionVisibility($values['common']['header_actions']);
251 if (array_key_exists('custom_icon', $values['common'])) {
252 $lso->getObjectProperties()->storePropertyIcon($values['common']['custom_icon']);
253 }
254
255 $lso->getObjectProperties()->storePropertyTileImage($values['common']['image']);
256
257 $lso->update();
258
259 $this->tpl->setOnScreenMessage("success", $this->lng->txt("msg_obj_modified"), true);
260 $this->ctrl->redirect($this);
261 return null;
262 } else {
263 $this->tpl->setOnScreenMessage("failure", $this->lng->txt("msg_form_save_error"));
264 return $this->renderer->render($form);
265 }
266 }
267}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
renderer()
$renderer
Class ilCtrl provides processing control methods.
Base class for ILIAS Exception handling.
language handling
buildFormElements(ilObjLearningSequence $lso, ILIAS\UI\Component\Input\Factory $if)
buildForm(ilObjLearningSequence $lso, string $submit_action)
__construct(protected ilObjLearningSequence $obj, protected ilCtrl $ctrl, protected ilLanguage $lng, protected ilGlobalTemplateInterface $tpl, protected ILIAS\Refinery\Factory $refinery, protected ILIAS\UI\Factory $ui_factory, protected ILIAS\UI\Renderer $renderer, protected Psr\Http\Message\ServerRequestInterface $request)
updateSettings(ilLearningSequenceSettings $settings)
updateActivation(ilLearningSequenceActivation $settings)
setTitle(string $title)
getLongDescription()
get object long description (stored in object_description)
setDescription(string $description)
$txt
Definition: error.php:31
withAdditionalTransformation(Transformation $trafo)
@inheritDoc
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:31