ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjLearningSequenceSettingsGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
9{
10 const PROP_TITLE = 'title';
11 const PROP_DESC = 'desc';
12 const PROP_ABSTRACT = 'abstract';
13 const PROP_ABSTRACT_IMAGE = 'abstract_img';
14 const PROP_EXTRO = 'extro';
15 const PROP_EXTRO_IMAGE = 'extro_img';
16 const PROP_ONLINE = 'online';
17 const PROP_AVAIL_PERIOD = 'online_period';
18 const PROP_GALLERY = 'gallery';
19
20 const CMD_SAVE = "update";
21 const CMD_CANCEL = "cancel";
22
24 'br',
25 'em',
26 'h1',
27 'h2',
28 'h3',
29 'li',
30 'ol',
31 'p',
32 'strong',
33 'u',
34 'ul',
35 'a'
36 ];
37
39 'png',
40 'jpg',
41 'jpeg',
42 'gif'
43 ];
44
45 public function __construct(
47 ilCtrl $il_ctrl,
48 ilLanguage $il_language,
49 ilGlobalTemplateInterface $il_template,
50 ilObjectService $obj_service
51 ) {
52 $this->obj = $obj;
53 $this->settings = $obj->getLSSettings();
54 $this->activation = $obj->getLSActivation();
55 $this->obj_title = $obj->getTitle();
56 $this->obj_description = $obj->getDescription();
57 $this->ctrl = $il_ctrl;
58 $this->lng = $il_language;
59 $this->tpl = $il_template;
60 $this->object_service = $object_service;
61 $this->obj_service = $obj_service;
62
63 $this->lng->loadLanguageModule('content');
64 $this->lng->loadLanguageModule('obj');
65 }
66
67 public function executeCommand()
68 {
69 $cmd = $this->ctrl->getCmd('settings');
70
71 switch ($cmd) {
72 case "settings":
73 case self::CMD_SAVE:
75 $content = $this->$cmd();
76 break;
77 default:
78 throw new ilException("ilObjLearningSequenceSettingsGUI: " .
79 "Command not supported: $cmd");
80
81 }
82 $this->tpl->setContent($content);
83 }
84
85 protected function settings()
86 {
87 $form = $this->buildForm();
88 $this->fillForm($form);
89 $this->addCommonFieldsToForm($form);
90 return $form->getHTML();
91 }
92
93 protected function cancel()
94 {
95 $this->ctrl->returnToParent($this);
96 }
97
99 {
100 $inpt->setSuffixes($this->img_allowed_suffixes);
101 $inpt->setALlowDeletion(true);
102 return $inpt;
103 }
104
106 {
107 $inpt->setUseRte(true);
109 $inpt->setRteTags($this->rte_allowed_tags);
110 //$inpt->setRTESupport($obj_id, "lso", "learningsequence");
111 return $inpt;
112 }
113
114
115 protected function buildForm()
116 {
117 $txt = function ($id) {
118 return $this->lng->txt($id);
119 };
120 $settings = $this->settings;
121 $activation = $this->activation;
122 $obj_id = $settings->getObjId();
123
124 $form = new ilPropertyFormGUI();
125 $form->setFormAction($this->ctrl->getFormAction($this, self::CMD_SAVE));
126 $form->setTitle($this->lng->txt('lso_edit'));
127
128 $title = new ilTextInputGUI($txt("title"), self::PROP_TITLE);
129 $title->setRequired(true);
130 $desc = new ilTextAreaInputGUI($txt("description"), self::PROP_DESC);
131
132 $section_avail = new ilFormSectionHeaderGUI();
133 $section_avail->setTitle($txt('lso_settings_availability'));
134 $online = new ilCheckboxInputGUI($txt("online"), self::PROP_ONLINE);
135 $online->setInfo($this->lng->txt('lso_activation_online_info'));
136 $duration = new ilDateDurationInputGUI($txt('avail_time_period'), self::PROP_AVAIL_PERIOD);
137 $duration->setShowTime(true);
138 if ($activation->getActivationStart() !== null) {
139 $duration->setStart(
140 new ilDateTime(
141 (string) $activation->getActivationStart()->format('Y-m-d H:i:s'),
143 )
144 );
145 }
146 if ($activation->getActivationEnd() !== null) {
147 $duration->setEnd(
148 new ilDateTime(
149 (string) $activation->getActivationEnd()->format('Y-m-d H:i:s'),
151 )
152 );
153 }
154
155 $section_misc = new ilFormSectionHeaderGUI();
156 $section_misc->setTitle($txt('lso_settings_misc'));
157 $show_members_gallery = new ilCheckboxInputGUI($txt("members_gallery"), self::PROP_GALLERY);
158 $show_members_gallery->setInfo($txt('lso_show_members_info'));
159
160 $abstract = $this->initRTEInput(
161 new ilTextAreaInputGUI($txt("abstract"), self::PROP_ABSTRACT)
162 );
163 $abstract_img = $this->initImgInput(
164 new ilImageFileInputGUI($txt("abstract_img"), self::PROP_ABSTRACT_IMAGE)
165 );
166 $abstract_img->setImage($settings->getAbstractImage());
167
168 $extro = $this->initRTEInput(
169 new ilTextAreaInputGUI($txt("extro"), self::PROP_EXTRO)
170 );
171 $extro_img = $this->initImgInput(
172 new ilImageFileInputGUI($txt("extro_img"), self::PROP_EXTRO_IMAGE)
173 );
174 $extro_img->setImage($settings->getExtroImage());
175
176 $section_intro = new ilFormSectionHeaderGUI();
177 $section_intro->setTitle($txt('lso_settings_intro'));
178 $section_extro = new ilFormSectionHeaderGUI();
179 $section_extro->setTitle($txt('lso_settings_extro'));
180
181 $section_misc = new ilFormSectionHeaderGUI();
182 $section_misc->setTitle($txt('obj_features'));
183 $show_members_gallery = new ilCheckboxInputGUI($txt("members_gallery"), self::PROP_GALLERY);
184 $show_members_gallery->setInfo($txt('lso_show_members_info'));
185
186 $form->addItem($title);
187 $form->addItem($desc);
188
189 $form->addItem($section_avail);
190 $form->addItem($online);
191 $form->addItem($duration);
192
193 $form->addItem($section_intro);
194 $form->addItem($abstract);
195 $form->addItem($abstract_img, true);
196
197 $form->addItem($section_extro);
198 $form->addItem($extro);
199 $form->addItem($extro_img, true);
200
201 $form->addItem($section_misc);
202 $form->addItem($show_members_gallery);
203
204 $form->addCommandButton(self::CMD_SAVE, $txt("save"));
205 $form->addCommandButton(self::CMD_CANCEL, $txt("cancel"));
206
207 return $form;
208 }
209
210 protected function fillForm(\ilPropertyFormGUI $form) : \ilPropertyFormGUI
211 {
212 $settings = $this->settings;
213 $activation = $this->activation;
214 $values = [
215 self::PROP_TITLE => $this->obj_title,
216 self::PROP_DESC => $this->obj_description,
217 self::PROP_ABSTRACT => $settings->getAbstract(),
218 self::PROP_EXTRO => $settings->getExtro(),
219 self::PROP_ABSTRACT_IMAGE => $settings->getAbstractImage(),
220 self::PROP_EXTRO_IMAGE => $settings->getExtroImage(),
221 self::PROP_ONLINE => $activation->getIsOnline(),
222 self::PROP_GALLERY => $settings->getMembersGallery()
223 ];
224 $form->setValuesByArray($values);
225 return $form;
226 }
227
228 protected function addCommonFieldsToForm(\ilPropertyFormGUI $form)
229 {
230 $txt = function ($id) {
231 return $this->lng->txt($id);
232 };
233 $section_appearance = new ilFormSectionHeaderGUI();
234 $section_appearance->setTitle($txt('cont_presentation'));
235 $form->addItem($section_appearance);
236 $form_service = $this->obj_service->commonSettings()->legacyForm($form, $this->obj);
237 $form = $form_service->addTitleIconVisibility();
238 $form = $form_service->addTopActionsVisibility();
239 $form = $form_service->addIcon();
240 $form = $form_service->addTileImage();
241 }
242
243
244 protected function update()
245 {
246 $form = $this->buildForm();
247 $this->addCommonFieldsToForm($form);
248 if (!$form->checkInput()) {
249 $form->setValuesByPost();
250 ilUtil::sendFailure($this->lng->txt("msg_form_save_error"));
251 return $form->getHTML();
252 }
253
254 $post = $_POST;
255 $lso = $this->obj;
256
257 $lso->setTitle($post[self::PROP_TITLE]);
258 $lso->setDescription($post[self::PROP_DESC]);
259
260 $settings = $this->settings
261 ->withAbstract($post[self::PROP_ABSTRACT])
262 ->withExtro($post[self::PROP_EXTRO])
263 ->withMembersGallery((bool) $post[self::PROP_GALLERY])
264 ;
265
266 $inpt = $form->getItemByPostVar(self::PROP_AVAIL_PERIOD);
267 $start = $inpt->getStart();
268 $end = $inpt->getEnd();
269 $activation = $this->activation
270 ->withIsOnline((bool) $post[self::PROP_ONLINE]);
271
272 if ($start) {
273 $activation = $activation
274 ->withActivationStart(
275 \DateTime::createFromFormat(
276 'Y-m-d H:i:s',
277 (string) $start->get(IL_CAL_DATETIME)
278 )
279 );
280 } else {
281 $activation = $activation->withActivationStart();
282 }
283 if ($end) {
284 $activation = $activation
285 ->withActivationEnd(
286 \DateTime::createFromFormat(
287 'Y-m-d H:i:s',
288 (string) $end->get(IL_CAL_DATETIME)
289 )
290 );
291 } else {
292 $activation = $activation->withActivationEnd();
293 }
294
295 $inpt = $form->getItemByPostVar(self::PROP_ABSTRACT_IMAGE);
296 if ($inpt->getDeletionFlag()) {
297 $settings = $settings->withDeletion(ilLearningSequenceFilesystem::IMG_ABSTRACT);
298 } else {
300 if ($img['size'] > 0) {
301 $settings = $settings->withUpload($img, ilLearningSequenceFilesystem::IMG_ABSTRACT);
302 }
303 }
304
305 $inpt = $form->getItemByPostVar(self::PROP_EXTRO_IMAGE);
306 if ($inpt->getDeletionFlag()) {
307 $settings = $settings->withDeletion(ilLearningSequenceFilesystem::IMG_EXTRO);
308 } else {
310 if ($img['size'] > 0) {
311 $settings = $settings->withUpload($img, ilLearningSequenceFilesystem::IMG_EXTRO);
312 }
313 }
314
315 $form_service = $this->obj_service->commonSettings()->legacyForm($form, $this->obj);
316 $form_service->saveTitleIconVisibility();
317 $form_service->saveTopActionsVisibility();
318 $form_service->saveIcon();
319 $form_service->saveTileImage();
320
321 $lso->updateSettings($settings);
322 $lso->updateActivation($activation);
323 $lso->update();
324
325 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
326 $this->ctrl->redirect($this);
327 }
328}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
This class represents a checkbox property in a property form.
This class provides processing control methods.
input GUI for a time span (start and end date)
@classDescription Date and time handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setSuffixes($a_suffixes)
Set Accepted Suffixes.
This class represents a section header in a property form.
This class represents an image file property in a property form.
setALlowDeletion($a_val)
Set allow deletion.
language handling
Class ilObjLearningSequenceSettingsGUI.
__construct(ilObjLearningSequence $obj, ilCtrl $il_ctrl, ilLanguage $il_language, ilGlobalTemplateInterface $il_template, ilObjectService $obj_service)
Class ilObjLearningSequence.
getDescription()
get object description
getTitle()
get object title @access public
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
setValuesByArray($a_values, $a_restrict_to_value_keys=false)
Set form values from an array.
const ILIAS_IMG_MANAGER_PLUGIN
Definition: class.ilRTE.php:14
This class represents a text area property in a property form.
setUseRte($a_usert, $version='')
Set Use Rich Text Editing.
removePlugin($a_plugin)
Remove RTE plugin.
setRteTags($a_rtetags)
Set Valid RTE Tags.
This class represents a text property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$txt
Definition: error.php:13
$img
Definition: imgupload.php:57