ILIAS  release_8 Revision v8.24
class.ilObjLearningSequenceSettingsGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
24{
25 public const PROP_TITLE = 'title';
26 public const PROP_DESC = 'desc';
27 public const PROP_ONLINE = 'online';
28 public const PROP_AVAIL_PERIOD = 'online_period';
29 public const PROP_GALLERY = 'gallery';
30
31 public const CMD_EDIT = "settings";
32 public const CMD_SAVE = "update";
33 public const CMD_CANCEL = "cancel";
34
35 public const CMD_OLD_INTRO = "viewlegacyi";
36 public const CMD_OLD_EXTRO = "viewlegacye";
37
38 public function __construct(
40 ilCtrl $ctrl,
43 ilObjectService $obj_service,
44 ArrayBasedRequestWrapper $post_wrapper,
45 ILIAS\Refinery\Factory $refinery,
46 ilToolbarGUI $toolbar
47 ) {
48 $this->obj = $obj;
49 $this->ctrl = $ctrl;
50 $this->lng = $lng;
51 $this->tpl = $tpl;
52 $this->obj_service = $obj_service;
53 $this->post_wrapper = $post_wrapper;
54 $this->refinery = $refinery;
55
56 $this->settings = $obj->getLSSettings();
57 $this->activation = $obj->getLSActivation();
58 $this->obj_title = $obj->getTitle();
59 $this->obj_description = $obj->getLongDescription();
60
61 $this->lng->loadLanguageModule('content');
62 $this->lng->loadLanguageModule('obj');
63 $this->toolbar = $toolbar;
64 }
65
66 public function executeCommand(): void
67 {
68 $cmd = $this->ctrl->getCmd('settings');
69
70 switch ($cmd) {
71 case self::CMD_EDIT:
72 case self::CMD_SAVE:
74 $content = $this->$cmd();
75 break;
78 $content = $this->showLegacyPage($cmd);
79 break;
80
81 default:
82 throw new ilException("ilObjLearningSequenceSettingsGUI: Command not supported: $cmd");
83
84 }
85 $this->tpl->setContent($content);
86 }
87
88 protected function settings(): string
89 {
91 $this->tpl->setOnScreenMessage("info", $this->lng->txt("lso_intropages_deprecationhint"));
92
93 $form = $this->buildForm();
94 $this->fillForm($form);
95 $this->addCommonFieldsToForm($form);
96 return $form->getHTML();
97 }
98
99 protected function cancel(): void
100 {
101 $this->ctrl->redirectByClass(ilObjLearningSequenceGUI::class);
102 }
103
104
105 //TODO: remove in release 9
106 public function addLegacypagesToToolbar(): void
107 {
108 $this->toolbar->addButton(
109 $this->lng->txt("lso_settings_old_intro"),
110 $this->ctrl->getLinkTarget($this, self::CMD_OLD_INTRO)
111 );
112
113 $this->toolbar->addButton(
114 $this->lng->txt("lso_settings_old_extro"),
115 $this->ctrl->getLinkTarget($this, self::CMD_OLD_EXTRO)
116 );
117 }
118
119 protected function showLegacyPage(string $cmd): string
120 {
121 $this->toolbar->addButton(
122 $this->lng->txt('back'),
123 $this->ctrl->getLinkTarget($this, self::CMD_EDIT)
124 );
125
126 $out = [];
128 if ($cmd === self::CMD_OLD_INTRO) {
129 $out[] = $settings->getAbstract();
130 $img = $settings->getAbstractImage();
131 if ($img) {
132 $out[] = '<img src="' . $img . '"/>';
133 }
134 }
135 if ($cmd === self::CMD_OLD_EXTRO) {
136 $out[] = $settings->getExtro();
137 $img = $settings->getExtroImage();
138 if ($img) {
139 $out[] = '<img src="' . $img . '"/>';
140 }
141 }
142
143 return implode('<hr>', $out);
144 }
145
146 protected function buildForm(): ilPropertyFormGUI
147 {
148 $txt = fn ($id) => $this->lng->txt($id);
150 $activation = $this->activation;
151
152 $form = new ilPropertyFormGUI();
153 $form->setFormAction($this->ctrl->getFormAction($this, self::CMD_SAVE));
154 $form->setTitle($this->lng->txt('lso_edit'));
155
156 $title = new ilTextInputGUI($txt("title"), self::PROP_TITLE);
157 $title->setRequired(true);
158 $desc = new ilTextAreaInputGUI($txt("description"), self::PROP_DESC);
159
160 $section_avail = new ilFormSectionHeaderGUI();
161 $section_avail->setTitle($txt('lso_settings_availability'));
162 $online = new ilCheckboxInputGUI($txt("online"), self::PROP_ONLINE);
163 $online->setInfo($this->lng->txt('lso_activation_online_info'));
164 $duration = new ilDateDurationInputGUI($txt('avail_time_period'), self::PROP_AVAIL_PERIOD);
165 $duration->setShowTime(true);
166 if ($activation->getActivationStart() !== null) {
167 $duration->setStart(
168 new ilDateTime(
169 $activation->getActivationStart()->format('Y-m-d H:i:s'),
171 )
172 );
173 }
174 if ($activation->getActivationEnd() !== null) {
175 $duration->setEnd(
176 new ilDateTime(
177 $activation->getActivationEnd()->format('Y-m-d H:i:s'),
179 )
180 );
181 }
182
183 $section_misc = new ilFormSectionHeaderGUI();
184 $section_misc->setTitle($txt('obj_features'));
185 $show_members_gallery = new ilCheckboxInputGUI($txt("members_gallery"), self::PROP_GALLERY);
186 $show_members_gallery->setInfo($txt('lso_show_members_info'));
187
188 $form->addItem($title);
189 $form->addItem($desc);
190
191 $form->addItem($section_avail);
192 $form->addItem($online);
193 $form->addItem($duration);
194 $form->addItem($section_misc);
195 $form->addItem($show_members_gallery);
196
197 $form->addCommandButton(self::CMD_SAVE, $txt("save"));
198 $form->addCommandButton(self::CMD_CANCEL, $txt("cancel"));
199
200 return $form;
201 }
202
204 {
206 $activation = $this->activation;
207 $values = [
208 self::PROP_TITLE => $this->obj_title,
209 self::PROP_DESC => $this->obj_description,
210 self::PROP_ONLINE => $activation->getIsOnline(),
211 self::PROP_GALLERY => $settings->getMembersGallery()
212 ];
213 $form->setValuesByArray($values);
214 return $form;
215 }
216
217 protected function addCommonFieldsToForm(ilPropertyFormGUI $form): void
218 {
219 $txt = fn ($id) => $this->lng->txt($id);
220 $section_appearance = new ilFormSectionHeaderGUI();
221 $section_appearance->setTitle($txt('cont_presentation'));
222 $form->addItem($section_appearance);
223 $form_service = $this->obj_service->commonSettings()->legacyForm($form, $this->obj);
224 $form_service->addTitleIconVisibility();
225 $form_service->addTopActionsVisibility();
226 $form_service->addIcon();
227 $form_service->addTileImage();
228 }
229
230 protected function update(): ?string
231 {
232 $form = $this->buildForm();
233 $this->addCommonFieldsToForm($form);
234 if (!$form->checkInput()) {
235 $form->setValuesByPost();
236 $this->tpl->setOnScreenMessage("failure", $this->lng->txt("msg_form_save_error"));
237 return $form->getHTML();
238 }
239
240 $lso = $this->obj;
241
242 $lso->setTitle($this->post_wrapper->retrieve(self::PROP_TITLE, $this->refinery->kindlyTo()->string()));
243 $lso->setDescription($this->post_wrapper->retrieve(self::PROP_DESC, $this->refinery->kindlyTo()->string()));
244
245 $settings = $this->settings
246 ->withMembersGallery(
247 $this->post_wrapper->retrieve(
248 self::PROP_GALLERY,
249 $this->refinery->byTrying([
250 $this->refinery->kindlyTo()->bool(),
251 $this->refinery->always(false)
252 ])
253 )
254 );
255
256 $inpt = $form->getItemByPostVar(self::PROP_AVAIL_PERIOD);
257 $start = $inpt->getStart();
258 $end = $inpt->getEnd();
259 $activation = $this->activation
260 ->withIsOnline(
261 $this->post_wrapper->retrieve(
262 self::PROP_ONLINE,
263 $this->refinery->byTrying([
264 $this->refinery->kindlyTo()->bool(),
265 $this->refinery->always(false)
266 ])
267 )
268 );
269
270 if ($start) {
271 $activation = $activation
272 ->withActivationStart(DateTime::createFromFormat('Y-m-d H:i:s', (string) $start->get(IL_CAL_DATETIME)));
273 } else {
274 $activation = $activation->withActivationStart();
275 }
276 if ($end) {
277 $activation = $activation
278 ->withActivationEnd(DateTime::createFromFormat('Y-m-d H:i:s', (string) $end->get(IL_CAL_DATETIME)));
279 } else {
280 $activation = $activation->withActivationEnd();
281 }
282
283 $form_service = $this->obj_service->commonSettings()->legacyForm($form, $this->obj);
284 $form_service->saveTitleIconVisibility();
285 $form_service->saveTopActionsVisibility();
286 $form_service->saveIcon();
287 $form_service->saveTileImage();
288
289 $lso->updateSettings($settings);
290 $lso->updateActivation($activation);
291 $lso->update();
292
293 $this->tpl->setOnScreenMessage("success", $this->lng->txt("msg_obj_modified"), true);
294 $this->ctrl->redirect($this);
295 return null;
296 }
297}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$out
Definition: buildRTE.php:24
const IL_CAL_DATETIME
This class represents a checkbox property in a property form.
Class ilCtrl provides processing control methods.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
@classDescription Date and time handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
__construct(ilObjLearningSequence $obj, ilCtrl $ctrl, ilLanguage $lng, ilGlobalTemplateInterface $tpl, ilObjectService $obj_service, ArrayBasedRequestWrapper $post_wrapper, ILIAS\Refinery\Factory $refinery, ilToolbarGUI $toolbar)
getLongDescription()
get object long description (stored in object_description)
This class represents a property form user interface.
setValuesByArray(array $a_values, bool $a_restrict_to_value_keys=false)
This class represents a text area property in a property form.
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$txt
Definition: error.php:13
$img
Definition: imgupload.php:83
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
Refinery Factory $refinery
Class ChatMainBarProvider \MainMenu\Provider.
$lng