ILIAS  release_8 Revision v8.24
class.ilBookingPreferencesGUI.php
Go to the documentation of this file.
1<?php
2
20
26{
27 protected \ILIAS\BookingManager\InternalService $service;
28 protected ilCtrl $ctrl;
31 protected \ILIAS\DI\UIServices $ui;
32 protected ilLanguage $lng;
33 protected \Psr\Http\Message\ServerRequestInterface $request;
34 protected ilObjUser $user;
37
38 public function __construct(
40 ) {
41 global $DIC;
42
43 $this->ctrl = $DIC->ctrl();
44 $this->ui = $DIC->ui();
45 $this->lng = $DIC->language();
46 $this->user = $DIC->user();
47 $this->request = $DIC->http()->request();
48 $this->main_tpl = $DIC->ui()->mainTemplate();
49 $this->service = $DIC->bookingManager()->internal();
50 $this->pool = $pool;
51 $this->repo = $this->service->repo()->preferences();
52 $this->access = $DIC->access();
53 }
54
55 public function executeCommand(): void
56 {
58
59 $next_class = $ctrl->getNextClass($this);
60 $cmd = $ctrl->getCmd("show");
61 if ($cmd === "render") {
62 $cmd = "show";
63 }
64 switch ($next_class) {
65 default:
66 if (in_array($cmd, ["show", "savePreferences"])) {
67 $this->$cmd();
68 }
69 }
70 }
71
72 protected function show(): void
73 {
74 $preferences = $this->service->domain()->preferences($this->pool);
75
76 if ($preferences->isGivingPreferencesPossible()) {
77 $this->listPreferenceOptions();
78 } else {
79 $this->listBookingResults();
80 }
81 }
82
83 protected function listPreferenceOptions(
84 Form\Standard $form = null
85 ): void {
86 $ui = $this->ui;
87 if (count(ilBookingObject::getList($this->pool->getId())) > 0) {
88 if (is_null($form)) {
89 $form = $this->initPreferenceForm();
90 }
91 $this->main_tpl->setContent($ui->renderer()->render($form));
92 } else {
93 $this->main_tpl->setOnScreenMessage('info', $this->lng->txt("book_type_warning"));
94 }
95 }
96
97 public function initPreferenceForm(): Form\Standard
98 {
99 $ui = $this->ui;
100 $f = $ui->factory();
101 $ctrl = $this->ctrl;
103 $repo = $this->repo;
104
105 $preferences = $repo->getPreferencesOfUser($this->pool->getId(), $this->user->getId());
106 $preferences = $preferences->getPreferences();
107
108 $this->renderBookingInfo();
109
110 $fields = [];
111 foreach (ilBookingObject::getList($this->pool->getId()) as $book_obj) {
112 $checked = isset($preferences[$this->user->getId()]) &&
113 in_array((int) $book_obj["booking_object_id"], $preferences[$this->user->getId()], true);
114
115 $fields["cb_" . $book_obj["booking_object_id"]] =
116 $f->input()->field()->checkbox($book_obj["title"], $book_obj["description"])->withValue($checked);
117 }
118
119 // section
120 $section1 = $f->input()->field()->section($fields, $lng->txt("book_preferences"));
121
122 $form_action = $ctrl->getLinkTarget($this, "savePreferences");
123 return $f->input()->container()->form()->standard($form_action, ["sec" => $section1]);
124 }
125
126 public function savePreferences(): void
127 {
128 $preferences = $this->service->domain()->preferences($this->pool);
129
130 if (!$preferences->isGivingPreferencesPossible()) {
131 return;
132 }
133
134 $request = $this->request;
135 $form = $this->initPreferenceForm();
137 $ctrl = $this->ctrl;
138 $repo = $this->repo;
139
140 if ($request->getMethod() === "POST") {
141 $form = $form->withRequest($request);
142 $data = $form->getData();
143
144 if (is_array($data["sec"])) {
145 $obj_ids = [];
146 foreach ($data["sec"] as $k => $v) {
147 if ($v === true) {
148 $id = explode("_", $k);
149 $obj_ids[] = (int) $id[1];
150 }
151 }
152
153 if (count($obj_ids) > $this->pool->getPreferenceNumber()) {
154 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("book_too_many_preferences"), true);
155 $this->listPreferenceOptions($form);
156 return;
157 }
158
159 if (count($obj_ids) < $this->pool->getPreferenceNumber()) {
160 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("book_not_enough_preferences"), true);
161 $this->listPreferenceOptions($form);
162 return;
163 }
164
165 $preferences = $this->service->data()->preferences(
166 [$this->user->getId() => $obj_ids]
167 );
168
169 $repo->savePreferencesOfUser($this->pool->getId(), $this->user->getId(), $preferences);
170 $part = new ilBookingParticipant($this->user->getId(), $this->pool->getId());
171
172 $titles = implode(", ", array_map(static function ($id) {
174 }, $obj_ids));
175
176 $this->main_tpl->setOnScreenMessage('success', $lng->txt("book_preferences_saved") . " (" . $titles . ")", true);
177 }
178 }
179 $ctrl->redirect($this, "show");
180 }
181
182
183
184 protected function renderBookingInfo(): void
185 {
187 $info = $lng->txt("book_preference_info");
188 $info = str_replace(["%1", "%2"], [
189 $this->pool->getPreferenceNumber(),
191 new ilDateTime($this->pool->getPreferenceDeadline(), IL_CAL_UNIX)
192 )
193 ], $info);
194 $this->main_tpl->setOnScreenMessage('info', $info);
195 }
196
197 protected function listBookingResults(): void
198 {
199 $main_tpl = $this->main_tpl;
201 $repo = $this->repo;
202 $ui = $this->ui;
203 $ctrl = $this->ctrl;
204
205 $info_gui = new ilInfoScreenGUI($this);
206
207 // preferences
208 $info_gui->addSection($lng->txt("book_your_preferences"));
209 $preferences = $repo->getPreferencesOfUser($this->pool->getId(), $this->user->getId());
210 $preferences = $preferences->getPreferences();
211 $cnt = 1;
212 if (isset($preferences[$this->user->getId()])) {
213 foreach ($preferences[$this->user->getId()] as $book_obj_id) {
214 $book_obj = new ilBookingObject($book_obj_id);
215 $info_gui->addProperty((string) $cnt++, $book_obj->getTitle());
216 }
217 } else {
218 $info_gui->addProperty("", $lng->txt("book_no_preferences_for_you"));
219 }
220
221 // bookings
222 $this->service->domain()->preferences($this->pool)->storeBookings(
223 $this->repo->getPreferences($this->pool->getId())
224 );
225 $bookings = $this->service->domain()->preferences($this->pool)->readBookings();
226 $info_gui->addSection($lng->txt("book_your_bookings"));
227 $cnt = 1;
228 if (isset($bookings[$this->user->getId()])) {
229 foreach ($bookings[$this->user->getId()] as $book_obj_id) {
230 $book_obj = new ilBookingObject($book_obj_id);
231
232 // post info button
233 $post_info_button = "";
234 if ($book_obj->getPostFile() || $book_obj->getPostText()) {
235 $ctrl->setParameterByClass("ilBookingObjectGUI", "object_id", $book_obj_id);
236 $b = $ui->factory()->button()->shy(
237 $lng->txt("book_post_booking_information"),
238 $ctrl->getLinkTargetByClass(["ilBookingObjectGUI", "ilBookingProcessGUI"], "displayPostInfo")
239 );
240 $post_info_button = "<br>" . $ui->renderer()->render($b);
241 }
242 $info_gui->addProperty((string) $cnt++, $book_obj->getTitle() . $post_info_button);
243 }
244 } else {
245 $info_gui->addProperty("", $lng->txt("book_no_bookings_for_you"));
246 }
247
248 // all users
249 if ($this->access->checkAccess("write", "", $this->pool->getRefId())) {
250 $info_gui->addSection($lng->txt("book_all_users"));
251 $preferences = $repo->getPreferences($this->pool->getId());
252 $preferences = $preferences->getPreferences();
253 foreach ($preferences as $user_id => $obj_ids) {
254 $booking_str = "<br>" . $lng->txt("book_log") . ": -";
255 if (isset($bookings[$user_id])) {
256 $booking_str = "<br>" . $lng->txt("book_log") . ": " . implode(", ", array_map(
257 static function ($obj_id) {
258 return (new ilBookingObject($obj_id))->getTitle();
259 },
260 $bookings[$user_id]
261 ));
262 }
263
264 $info_gui->addProperty(
265 ilUserUtil::getNamePresentation($user_id, false, false, "", true),
266 $lng->txt("book_preferences") . ": " . implode(", ", array_map(static function ($obj_id) {
267 return (new ilBookingObject($obj_id))->getTitle();
268 }, $obj_ids)) . $booking_str
269 );
270 }
271 }
272
273 $main_tpl->setContent($info_gui->getHTML());
274 }
275}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
const IL_CAL_UNIX
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static lookupTitle(int $object_id)
static getList(int $a_pool_id, string $a_title=null)
Get list of booking objects.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
savePreferencesOfUser(int $a_pool_id, int $a_user_id, ilBookingPreferences $preferences)
Save all preferences of a user for a pool.
getPreferences(int $a_pool_id)
Get booking preferences for a pool id.
getPreferencesOfUser(int $a_pool_id, int $a_user_id)
Get booking preferences for a pool id.
Booking preferences ui class.
listPreferenceOptions(Form\Standard $form=null)
ilBookingPreferencesDBRepository $repo
Psr Http Message ServerRequestInterface $request
ILIAS BookingManager InternalService $service
ilGlobalTemplateInterface $main_tpl
Class ilCtrl provides processing control methods.
getLinkTargetByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
getNextClass($a_gui_class=null)
@inheritDoc
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
@inheritDoc
getCmd(string $fallback_command=null)
@inheritDoc
getLinkTarget(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
setParameterByClass(string $a_class, string $a_parameter, $a_value)
@inheritDoc
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
Class ilInfoScreenGUI.
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link="", bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
global $DIC
Definition: feed.php:28
This describes commonalities between all forms.
Definition: Form.php:33
This describes a standard form.
Definition: Standard.php:27
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setContent(string $a_html)
Sets content for standard template.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21
$lng