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