ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
class.ProcessUtilGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28
30{
33 protected \ilCtrl $ctrl;
34 protected \ilLogger $log;
35 protected \ilObjBookingPool $pool;
36 protected \ilBookingHelpAdapter $help;
39 protected object $parent_gui;
40 protected \ilLanguage $lng;
41 protected \ilGlobalTemplateInterface $tpl;
42
43 public function __construct(
44 InternalDomainService $domain_service,
45 InternalGUIService $gui_service,
47 object $parent_gui
48 ) {
49 $this->gui = $gui_service;
50 $this->domain = $domain_service;
51 $this->log = $domain_service->log();
52 $this->help = $gui_service->bookingHelp($pool);
53 $this->parent_gui = $parent_gui;
54 $this->pool = $pool;
55 $this->ctrl = $this->gui->ctrl();
56 $this->request = $this->gui->standardRequest();
57 $this->objects_manager = $domain_service->objects($pool->getId());
58 $this->lng = $domain_service->lng();
59 $this->tpl = $this->gui->mainTemplate();
60 }
61
62 // Back to parent
63 public function back(): void
64 {
65 $this->log->debug("back");
66 $retCmd = $this->request->getReturnCmd();
67 $this->log->debug("returnCmd is " . $retCmd);
68
69 $class = get_class($this->parent_gui);
70 if ($retCmd === 'week' && $class === ilBookingProcessWithScheduleGUI::class) {
71 if ($this->request->getOriginCmd() === 'book') {
72 $this->domain->objectSelection($this->pool->getId())->setSelectedObjects([$this->request->getObjectId()]);
73 }
74 $this->ctrl->setParameterByClass($class, 'seed', $this->request->getSeed());
75 $this->ctrl->redirectByClass($class, $retCmd);
76 return;
77 }
78
79 if ($retCmd === 'render') {
80 $this->redirectToRender();
81 return;
82 }
83
84 if ($retCmd !== "") {
85 $this->ctrl->redirectByClass(get_class($this->parent_gui), $retCmd);
86 } else {
87 //var_dump(get_class($this->parent_gui));
88 //exit;
89 $this->ctrl->returnToParent($this->parent_gui);
90 }
91 }
92
93 public function setHelpId(string $a_id): void
94 {
95 $this->help->setHelpId($a_id);
96 }
97
98 // Table to assign participants to an object.
99 public function assignParticipants(int $book_obj_id): void
100 {
101 $tabs = $this->gui->tabs();
102 $ctrl = $this->gui->ctrl();
103 $lng = $this->domain->lng();
104 $main_tpl = $this->gui->mainTemplate();
105
106 $tabs->clearTargets();
107 $tabs->setBackTarget($lng->txt('book_back_to_list'), $ctrl->getLinkTarget($this->parent_gui, 'back'));
108
109 $table = new \ilBookingAssignParticipantsTableGUI($this->parent_gui, 'assignParticipants', $this->pool->getRefId(), $this->pool->getId(), $book_obj_id);
110 $main_tpl->setContent($table->getHTML());
111 }
112
113
114 /*
115 public function checkPermissionBool(string $a_perm) : bool
116 {
117 $access = $this->domain->access();
118 if (!$access->checkAccess($a_perm, "", $this->pool->getRefId())) {
119 return false;
120 }
121 return true;
122 }
123
124 protected function checkPermission(string $a_perm) : void
125 {
126 $main_tpl = $this->gui->mainTemplate();
127 $lng = $this->domain->lng();
128
129 if (!$this->checkPermissionBool($a_perm)) {
130 $main_tpl->setOnScreenMessage('failure', $lng->txt("no_permission"), true);
131 $this->back();
132 }
133 }*/
134
135 public function handleBookingSuccess(
136 int $a_obj_id,
137 string $post_info_cmd,
138 ?array $a_rsv_ids = null,
139 ?string $message = null
140 ): void {
141 $this->log->debug('handleBookingSuccess');
142 $this->tpl->setOnScreenMessage(
143 'success',
144 $message ?: $this->lng->txt('book_reservation_confirmed'),
145 true
146 );
147
149 $this->redirectToBookingInformationIfAvailable($a_obj_id, $post_info_cmd, $a_rsv_ids);
150 $this->redirectToRender();
151 }
152
153 public function redirectToBookingInformationIfAvailable(int $a_obj_id, string $post_info_cmd, ?array $a_rsv_ids = null): void
154 {
155 $obj = new \ilBookingObject($a_obj_id);
156 if (trim($obj->getPostText()) === '' && $this->objects_manager->getBookingInfoFilename($a_obj_id) === '') {
157 return;
158 }
159
160 $a_rsv_ids ??= [];
161 if ($a_rsv_ids !== []) {
162 $this->ctrl->setParameter($this->parent_gui, 'rsv_ids', implode(';', $a_rsv_ids));
163 }
164 $this->ctrl->redirect($this->parent_gui, $post_info_cmd);
165 }
166
167 private function redirectToReturnCmdIfAsynchronous(): void
168 {
169 if (!$this->ctrl->isAsynch()) {
170 return;
171 }
172
173 $this->gui->send(
174 "<script>window.location.href = '{$this->ctrl->getLinkTarget($this->parent_gui, $this->request->getReturnCmd())}';</script>"
175 );
176 }
177
178 private function redirectToRender(): void
179 {
180 $this->ctrl->saveParameterByClass(\ilObjBookingPoolGUI::class, 'ref_id');
181 $this->ctrl->redirectByClass(\ilObjBookingPoolGUI::class, 'render');
182 }
183
187 public function displayPostInfo(
188 int $book_obj_id,
189 int $user_id,
190 string $file_deliver_cmd
191 ): void {
192 $this->log->debug('displayPostInfo');
193 $booking_ids = $this->request->getReservationIdsFromString();
194
195 $objects_with_periods = $this->resolveObjectsWithPeriodsForPostInfo(
196 $book_obj_id,
197 $user_id,
198 $booking_ids
199 );
200
201 if ($objects_with_periods === []) {
202 $this->ctrl->redirect($this->parent_gui, 'back');
203 return;
204 }
205
206 $booking_objects = [];
207 $booking_info_filenames = [];
208
209 $objects_with_info = [];
210 foreach ($objects_with_periods as $object_id => $periods) {
211 $booking_objects[$object_id] = new \ilBookingObject($object_id);
212 $booking_info_filenames[$object_id] = trim($this->objects_manager->getBookingInfoFilename($object_id));
213
214 if (
215 trim($booking_objects[$object_id]->getPostText()) === ''
216 && $booking_info_filenames[$object_id] === ''
217 ) {
218 continue;
219 }
220
221 $objects_with_info[$object_id] = $periods;
222 }
223
224 if ($objects_with_info === []) {
225 $this->ctrl->redirect($this->parent_gui, 'back');
226 return;
227 }
228
229 $template = new \ilTemplate(
230 'tpl.booking_reservation_post.html',
231 true,
232 true,
233 'components/ILIAS/BookingManager/BookingProcess'
234 );
235 $multiple_objects = count($objects_with_info) > 1;
236 $submit_url = $this->ctrl->getLinkTarget($this->parent_gui, 'back');
237
238 foreach ($objects_with_info as $object_id => $periods) {
239 $booking_object = $booking_objects[$object_id];
240 $post_text = trim($booking_object->getPostText());
241
242 $template->setCurrentBlock('info_block');
243 $title = $multiple_objects
244 ? sprintf($this->lng->txt('book_post_booking_information_for'), $booking_object->getTitle())
245 : $this->lng->txt('book_post_booking_information');
246 $template->setVariable('TITLE', $title);
247
248 if ($post_text !== '') {
249 $post_text = str_replace(
250 ['[OBJECT]', '[PERIOD]'],
251 [$booking_object->getTitle(), implode('<br />', $periods)],
252 $post_text
253 );
254 $template->setVariable('POST_TEXT', nl2br($post_text));
255 }
256
257 if ($booking_info_filenames[$object_id] === '') {
258 $template->parseCurrentBlock();
259 continue;
260 }
261
262 $this->ctrl->setParameter($this->parent_gui, 'object_id', $object_id);
263 $url = $this->ctrl->getLinkTarget($this->parent_gui, $file_deliver_cmd);
264 $this->ctrl->clearParameterByClass($this->parent_gui::class, 'object_id');
265
266 $template->setCurrentBlock('download');
267 $template->setVariable('DOWNLOAD', $this->lng->txt('download'));
268 $template->setVariable('URL_FILE', $url);
269 $template->setVariable('TXT_FILE', $booking_info_filenames[$object_id]);
270 $template->parseCurrentBlock();
271 $template->setCurrentBlock('info_block');
272
273 $template->parseCurrentBlock();
274 }
275
276 $template->setCurrentBlock('submit');
277 $template->setVariable('TXT_SUBMIT', $this->lng->txt('ok'));
278 $template->setVariable('URL_SUBMIT', $submit_url);
279 $template->parseCurrentBlock();
280
281 $this->tpl->setContent($template->get());
282 }
283
288 int $book_obj_id,
289 int $user_id,
290 array $booking_ids
291 ): array {
292 if ($booking_ids !== []) {
293 return $this->resolvePeriodsFromReservationIds($booking_ids);
294 }
295
296 if ($book_obj_id <= 0) {
297 return [];
298 }
299
300 $period_slots = [];
301 if ($this->request->getReservationId() !== '') {
302 $reservation_id_parts = explode('_', $this->request->getReservationId());
303 $user_id = (int) ($reservation_id_parts[1] ?? 0);
304 $from = (int) ($reservation_id_parts[2] ?? 0);
305
306 if ($from > time()) {
307 $to = (int) ($reservation_id_parts[3] ?? 0);
308 $period_slots["$from-$to"] = 1;
309 }
310 $booking_ids = [0];
311 }
312
314 foreach ($book_ids as $book_id) {
315 if (!in_array($book_id, $booking_ids, true) && $booking_ids !== []) {
316 continue;
317 }
318
319 $reservation = new \ilBookingReservation($book_id);
320 $from = $reservation->getFrom();
321 $to = $reservation->getTo();
322 if ($from > time()) {
323 $key = "$from-$to";
324 $period_slots[$key] = ($period_slots[$key] ?? 0) + 1;
325 }
326 }
327
328 return $period_slots === []
329 ? []
330 : [$book_obj_id => $this->formatPeriodSlots($period_slots)];
331 }
332
337 protected function resolvePeriodsFromReservationIds(array $booking_ids): array
338 {
339 $period_slots_by_object = [];
340
341 foreach ($booking_ids as $booking_id) {
342 $booking_id = (int) $booking_id;
343 if ($booking_id <= 0) {
344 continue;
345 }
346
347 $reservation = new \ilBookingReservation($booking_id);
348 $object_id = $reservation->getObjectId();
349 $key = "{$reservation->getFrom()}-{$reservation->getTo()}";
350 $period_slots_by_object[$object_id][$key] = ($period_slots_by_object[$object_id][$key] ?? 0) + 1;
351 }
352
353 $objects_with_periods = [];
354 foreach ($period_slots_by_object as $object_id => $period_slots) {
355 $objects_with_periods[$object_id] = $this->formatPeriodSlots($period_slots);
356 }
357
358 ksort($objects_with_periods);
359
360 return $objects_with_periods;
361 }
362
367 protected function formatPeriodSlots(array $period_slots): array
368 {
371
372 $period = [];
373 ksort($period_slots);
374 foreach ($period_slots as $time => $counter) {
375 $time_parts = explode('-', $time);
377 new \ilDateTime((int) $time_parts[0], IL_CAL_UNIX),
378 new \ilDateTime((int) $time_parts[1], IL_CAL_UNIX)
379 );
380
381 if ($counter > 1) {
382 $formatted .= " ($counter)";
383 }
384
385 $period[] = $formatted;
386 }
387
389
390 return $period;
391 }
392
396 public function deliverPostFile(
397 int $book_obj_id,
398 int $user_id
399 ): void {
400 $this->log->debug("deliverPostFile");
401 $id = $book_obj_id;
402 if (!$id) {
403 return;
404 }
405
407 $book_id = current($book_ids);
408 $obj = new \ilBookingReservation($book_id);
409 if ($obj->getUserId() !== $user_id) {
410 return;
411 }
412
413 $this->domain->objects($this->pool->getId())->deliverBookingInfo($id);
414 }
415
416}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(InternalDomainService $domain_service, InternalGUIService $gui_service, \ilObjBookingPool $pool, object $parent_gui)
redirectToBookingInformationIfAvailable(int $a_obj_id, string $post_info_cmd, ?array $a_rsv_ids=null)
resolveObjectsWithPeriodsForPostInfo(int $book_obj_id, int $user_id, array $booking_ids)
displayPostInfo(int $book_obj_id, int $user_id, string $file_deliver_cmd)
Display post booking informations.
deliverPostFile(int $book_obj_id, int $user_id)
Deliver post booking file.
handleBookingSuccess(int $a_obj_id, string $post_info_cmd, ?array $a_rsv_ids=null, ?string $message=null)
Author: Alexander Killing killing@leifos.de
const IL_CAL_UNIX
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getObjectReservationForUser(int $a_object_id, int $a_user_id)
getLinkTarget(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
static setUseRelativeDates(bool $a_status)
set use relative dates
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false, ?ilObjUser $user=null)
Format a period of two dates Shows: 14.
@classDescription Date and time handling
txt(string|LanguageIdentifier $a_topic, ?int $n=null)
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
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...
if(!file_exists('../ilias.ini.php'))