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