ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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  $image = $lso->getObjectProperties()->getPropertyTileImage()->toForm(
183  $this->lng,
184  $if->field(),
186  );
187  $section_common = $if->field()->section(
188  [
189  'icon' => $title_icon,
190  'header_actions' => $header_actions,
191  'image' => $image
192  ],
193  $txt('cont_presentation')
194  );
195  $formElements['common'] = $section_common;
196 
197  return $formElements;
198  }
199 
200  protected function update(): ?string
201  {
202  $form = $this
203  ->buildForm($this->obj, $this->ctrl->getFormAction($this, self::CMD_SAVE))
204  ->withRequest($this->request);
205 
206  $result = $form->getInputGroup()->getContent();
207 
208  if ($result->isOK()) {
209  $values = $result->value();
210  $lso = $this->obj;
211 
212  $lso->setTitle($values['object'][self::PROP_TITLE]);
213  $lso->setDescription($values['object'][self::PROP_DESC]);
214 
215  $settings = $lso->getLSSettings()
216  ->withMembersGallery($values['additional'][self::PROP_GALLERY]);
217  $lso->updateSettings($settings);
218 
219  $activation = $lso->getLSActivation()
220  ->withIsOnline($values['online'][self::PROP_ONLINE])
221  ->withActivationStart(null)
222  ->withActivationEnd(null);
223  if ($values['online'][self::PROP_AVAIL_FROM] !== null) {
224  $activation = $activation
225  ->withActivationStart(
226  DateTime::createFromImmutable($values['online'][self::PROP_AVAIL_FROM])
227  );
228  }
229  if ($values['online'][self::PROP_AVAIL_TO] !== null) {
230  $activation = $activation
231  ->withActivationEnd(
232  DateTime::createFromImmutable($values['online'][self::PROP_AVAIL_TO])
233  );
234  }
235  $lso->updateActivation($activation);
236 
237  $status = ilObjLearningSequenceAccess::isOffline($lso->getRefId());
238  $lso->getObjectProperties()->storePropertyIsOnline(
239  new ilObjectPropertyIsOnline(! $status)
240  );
241 
242  $lso->getObjectProperties()->storePropertyTitleAndIconVisibility($values['common']['icon']);
243  $lso->getObjectProperties()->storePropertyHeaderActionVisibility($values['common']['header_actions']);
244  $lso->getObjectProperties()->storePropertyTileImage($values['common']['image']);
245 
246  $lso->update();
247 
248  $this->tpl->setOnScreenMessage("success", $this->lng->txt("msg_obj_modified"), true);
249  $this->ctrl->redirect($this);
250  return null;
251  } else {
252  $this->tpl->setOnScreenMessage("failure", $this->lng->txt("msg_form_save_error"));
253  return $this->renderer->render($form);
254  }
255  }
256 }
buildForm(ilObjLearningSequence $lso, string $submit_action)
$renderer
Interface Observer Contains several chained tasks and infos about them.
renderer()
__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)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
buildFormElements(ilObjLearningSequence $lso, ILIAS\UI\Component\Input\Factory $if)
$txt
Definition: error.php:31
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
global $lng
Definition: privfeed.php:31
getLongDescription()
get object long description (stored in object_description)