ILIAS  trunk Revision v12.0_alpha-1329-g1094ddb0c33
class.SettingsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27use ILIAS\Repository\Form\FormAdapterGUI as RepositoryFormAdapterGUI;
28
33{
34 public function __construct(
35 protected InternalDataService $data,
36 protected InternalDomainService $domain,
37 protected InternalGUIService $gui,
38 protected int $obj_id,
39 protected int $ref_id,
40 protected bool $creation_mode,
41 protected object $parent_gui
42 ) {
43 }
44
45 public function executeCommand(): void
46 {
47 $ctrl = $this->gui->ctrl();
48 $next_class = $ctrl->getNextClass($this);
49 $cmd = $ctrl->getCmd("edit");
50
51 switch ($next_class) {
52 case strtolower(ilDidacticTemplateGUI::class):
53 $ctrl->setReturn($this, 'edit');
54 $did = new ilDidacticTemplateGUI(
55 $this->parent_gui,
57 );
58 $ctrl->forwardCommand($did);
59 break;
60
61 default:
62 if (in_array($cmd, ["edit", "save"])) {
63 $this->$cmd();
64 }
65 }
66 }
67
68 protected function edit(): void
69 {
70 $mt = $this->gui->ui()->mainTemplate();
71 $form = $this->getEditForm();
72 $mt->setContent($form->render());
73 }
74
75 protected function getEditForm(): RepositoryFormAdapterGUI
76 {
77 $lng = $this->domain->lng();
78 $settings = $this->domain->bookingSettings()->getByObjId($this->obj_id);
79 $form = (new RepositoryFormAdapterGUI([self::class], 'save'))
80 ->section("general", $lng->txt("book_edit"))
82 $this->obj_id,
83 "book"
84 );
85 $form = $form->addDidacticTemplates(
86 "book",
87 $this->ref_id,
88 $this->creation_mode
89 );
90
91 // #14478
92 $mode_disabled = (bool) count(\ilBookingObject::getList($this->obj_id));
93
94 $schedule_type = $settings?->getScheduleType();
95 $form = $form
96 ->switch(
97 "stype",
98 $lng->txt("book_schedule_type"),
99 "",
100 (string) $schedule_type
101 );
102 $form = $form
103 ->group(
105 $lng->txt("book_schedule_type_fixed"),
106 $lng->txt("book_schedule_type_fixed_info"),
107 $mode_disabled && $schedule_type !== \ilObjBookingPool::TYPE_FIX_SCHEDULE
108 )
109 ->number(
110 "period",
111 $lng->txt("book_reservation_filter_period"),
112 $lng->txt("days") . " - " .
113 $lng->txt("book_reservation_filter_period_info"),
114 $settings->getReservationPeriod()
115 )
116 ->checkbox(
117 "rmd",
118 $lng->txt("book_reminder_setting"),
119 "",
120 (bool) $settings->getReminderStatus()
121 )
122 ->number(
123 "rmd_day",
124 $lng->txt("book_reminder_day"),
125 "",
126 max($settings->getReminderDay(), 1)
127 )
128 ->group(
130 $lng->txt("book_schedule_type_none_direct"),
131 $lng->txt("book_schedule_type_none_direct_info"),
132 $mode_disabled && $schedule_type !== \ilObjBookingPool::TYPE_NO_SCHEDULE
133 )
134 ->number(
135 "limit",
136 $lng->txt("book_overall_limit"),
137 $lng->txt("book_total_individual_bookings_limit"),
138 $settings->getOverallLimit()
139 );
140
141 $pref_options_disabled = false;
142 if ($schedule_type === \ilObjBookingPool::TYPE_NO_SCHEDULE_PREFERENCES) {
143 $pref_manager = $this->domain->preferences(
144 new \ilObjBookingPool($this->ref_id)
145 );
146 $pref_options_disabled = $pref_manager->hasRun();
147 }
148
149 $form = $form
150 ->group(
152 $lng->txt("book_schedule_type_none_preference"),
153 $lng->txt("book_schedule_type_none_preference_info"),
154 $mode_disabled && $schedule_type !== \ilObjBookingPool::TYPE_NO_SCHEDULE_PREFERENCES
155 );
156 $form = $form
157 ->number(
158 "preference_nr",
159 $lng->txt("book_nr_of_preferences"),
160 $lng->txt("book_nr_preferences") . " - " .
161 $lng->txt("book_nr_of_preferences_info"),
162 $settings->getPreferenceNr()
163 );
164 if ($pref_options_disabled) {
165 $form = $form->disabled();
166 }
167 $form = $form
168 ->dateTime(
169 "pref_deadline",
170 $lng->txt("book_pref_deadline"),
171 $lng->txt("book_pref_deadline_info"),
172 $settings->getPrefDeadline()
173 ? new \ilDateTime($settings->getPrefDeadline(), IL_CAL_UNIX) : null
174 );
175
176 if ($pref_options_disabled) {
177 $form = $form->disabled();
178 } else {
179 if (!$mode_disabled) {
180 $form = $form->required();
181 }
182 }
183 $form->end();
184
185 $form = $form
186 ->checkbox(
187 "public",
188 $lng->txt("book_public_log"),
189 $lng->txt("book_public_log_info"),
190 $settings->getPublicLog()
191 )
192 ->checkbox(
193 "messages",
194 $lng->txt("book_messages"),
195 $lng->txt("book_messages_info"),
196 $settings->getMessages()
197 );
198
199 $lng->loadLanguageModule("rep");
200
201 $form = $form
202 ->section(
203 "rep",
204 $lng->txt('rep_activation_availability')
205 )
206 ->addOnline(
207 $this->obj_id,
208 "book"
209 );
210
211 $form = $form
212 ->section(
213 "obj_presentation",
214 $lng->txt('obj_presentation')
215 )->addStdTile(
216 $this->obj_id,
217 "book"
218 );
219
220 $form = $form->addAdditionalFeatures(
221 $this->obj_id,
222 [
224 ]
225 );
226
227 return $form;
228 }
229
230 protected function save(): void
231 {
232 $mt = $this->gui->ui()->mainTemplate();
233 $form = $this->getEditForm();
234 $ctrl = $this->gui->ctrl();
235 $lng = $this->domain->lng();
236
237 $old_settings = $this->domain->bookingSettings()->getByObjId($this->obj_id);
238
239 if ($form->isValid()) {
240 $form->saveStdTitleAndDescription(
241 $this->obj_id,
242 "book"
243 );
244 $form->saveStdTile(
245 $this->obj_id,
246 "book"
247 );
248 $form->saveOnline(
249 $this->obj_id,
250 "book"
251 );
252 $form->saveAdditionalFeatures(
253 $this->obj_id,
254 [
256 ]
257 );
258
259 $settings = $this->data->settings(
260 $this->obj_id,
261 (bool) $form->getData("public"),
262 (int) $form->getData("stype"),
263 (int) $form->getData("limit"),
264 (int) $form->getData("period"),
265 (bool) $form->getData("rmd"),
266 (int) $form->getData("rmd_day"),
267 $form->getData("pref_deadline")
268 ? (int) $form->getData("pref_deadline")->getUnixTime()
269 : 0,
270 (int) $form->getData("preference_nr"),
271 (bool) $form->getData("messages")
272 );
273
274 $this->domain->bookingSettings()->update($settings);
275
276
277 // check if template is changed
278 $form->redirectToDidacticConfirmationIfChanged(
279 $this->ref_id,
280 "book",
281 static::class
282 );
283
284 $mt->setOnScreenMessage("success", $lng->txt("msg_obj_modified"), true);
285 $ctrl->redirectByClass(self::class, "edit");
286 } else {
287 $mt = $this->gui->ui()->mainTemplate();
288 $mt->setContent($form->render());
289 }
290 }
291}
Author: Alexander Killing killing@leifos.de
@ilCtrl_Calls ILIAS\BookingManager\Settings\SettingsGUI: ilDidacticTemplateGUI
__construct(protected InternalDataService $data, protected InternalDomainService $domain, protected InternalGUIService $gui, protected int $obj_id, protected int $ref_id, protected bool $creation_mode, protected object $parent_gui)
const IL_CAL_UNIX
static getList(int $a_pool_id, ?string $a_title=null)
Get list of booking objects.
GUI class for didactic template settings inside repository objects.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:66
addStdTitleAndDescription(int $obj_id, string $type)
addOnline(int $obj_id, string $type)
addStdTile(int $obj_id, string $type)
global $lng
Definition: privfeed.php:26