ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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
41 public function __construct(
42 InternalDomainService $domain_service,
43 InternalGUIService $gui_service,
45 object $parent_gui
46 ) {
47 $this->gui = $gui_service;
48 $this->domain = $domain_service;
49 $this->log = $domain_service->log();
50 $this->help = $gui_service->bookingHelp($pool);
51 $this->parent_gui = $parent_gui;
52 $this->pool = $pool;
53 $this->ctrl = $this->gui->ctrl();
54 $this->request = $this->gui->standardRequest();
55 $this->objects_manager = $domain_service->objects($pool->getId());
56 }
57
58 // Back to parent
59 public function back(): void
60 {
61 $this->log->debug("back");
62 $retCmd = $this->request->getReturnCmd();
63 $this->log->debug("returnCmd is " . $retCmd);
64
65 $class = get_class($this->parent_gui);
66 if ($retCmd === 'week' && $class === ilBookingProcessWithScheduleGUI::class) {
67 if ($this->request->getOriginCmd() === 'book') {
68 $this->domain->objectSelection($this->pool->getId())->setSelectedObjects([$this->request->getObjectId()]);
69 }
70 $this->ctrl->setParameterByClass($class, 'seed', $this->request->getSeed());
71 $this->ctrl->redirectByClass($class, $retCmd);
72 return;
73 }
74
75 if ($retCmd !== "") {
76 $this->ctrl->redirectByClass(get_class($this->parent_gui), $retCmd);
77 } else {
78 //var_dump(get_class($this->parent_gui));
79 //exit;
80 $this->ctrl->returnToParent($this->parent_gui);
81 }
82 }
83
84 public function setHelpId(string $a_id): void
85 {
86 $this->help->setHelpId($a_id);
87 }
88
89 // Table to assign participants to an object.
90 public function assignParticipants(int $book_obj_id): void
91 {
92 $tabs = $this->gui->tabs();
93 $ctrl = $this->gui->ctrl();
94 $lng = $this->domain->lng();
95 $main_tpl = $this->gui->mainTemplate();
96
97 $tabs->clearTargets();
98 $tabs->setBackTarget($lng->txt('book_back_to_list'), $ctrl->getLinkTarget($this->parent_gui, 'back'));
99
100 $table = new \ilBookingAssignParticipantsTableGUI($this->parent_gui, 'assignParticipants', $this->pool->getRefId(), $this->pool->getId(), $book_obj_id);
101 $main_tpl->setContent($table->getHTML());
102 }
103
104
105 /*
106 public function checkPermissionBool(string $a_perm) : bool
107 {
108 $access = $this->domain->access();
109 if (!$access->checkAccess($a_perm, "", $this->pool->getRefId())) {
110 return false;
111 }
112 return true;
113 }
114
115 protected function checkPermission(string $a_perm) : void
116 {
117 $main_tpl = $this->gui->mainTemplate();
118 $lng = $this->domain->lng();
119
120 if (!$this->checkPermissionBool($a_perm)) {
121 $main_tpl->setOnScreenMessage('failure', $lng->txt("no_permission"), true);
122 $this->back();
123 }
124 }*/
125
126 public function handleBookingSuccess(
127 int $a_obj_id,
128 string $post_info_cmd,
129 ?array $a_rsv_ids = null
130 ): void {
131 $this->log->debug("handleBookingSuccess");
132 $main_tpl = $this->gui->mainTemplate();
133 $ctrl = $this->gui->ctrl();
134 $lng = $this->domain->lng();
135 $request = $this->gui->standardRequest();
136
137 $main_tpl->setOnScreenMessage('success', $lng->txt('book_reservation_confirmed'), true);
138
139 // show post booking information?
140 $obj = new \ilBookingObject($a_obj_id);
141 $pfile = $this->objects_manager->getBookingInfoFilename($a_obj_id);
142 $ptext = $obj->getPostText();
143
144 if (trim($ptext) || $pfile) {
145 if (count($a_rsv_ids)) {
147 $this->parent_gui,
148 'rsv_ids',
149 implode(";", $a_rsv_ids)
150 );
151 }
152 $ctrl->redirect($this->parent_gui, $post_info_cmd);
153 } else {
154 if ($ctrl->isAsynch()) {
155 $this->gui->send("<script>window.location.href = '" .
156 $ctrl->getLinkTarget($this->parent_gui, $request->getReturnCmd()) . "';</script>");
157 } else {
158 $this->back();
159 }
160 }
161 }
162
166 public function displayPostInfo(
167 int $book_obj_id,
168 int $user_id,
169 string $file_deliver_cmd
170 ): void {
171 $this->log->debug("displayPostInfo");
172 $main_tpl = $this->gui->mainTemplate();
173 $ctrl = $this->gui->ctrl();
174 $lng = $this->domain->lng();
175 $id = $book_obj_id;
176 $request = $this->gui->standardRequest();
177
178 if (!$id) {
179 return;
180 }
181
182 $rsv_ids = $request->getReservationIdsFromString();
183
184 $tmp = [];
185 if ($rsv_ids === [] && $request->getReservationId() !== '') {
186 $reservationIdParts = explode('_', $request->getReservationId());
187
188 $user_id = (int) ($reservationIdParts[1] ?? 0);
189 $from = (int) ($reservationIdParts[2] ?? 0);
190
191 if ($from > time()) {
192 $to = (int) ($reservationIdParts[3] ?? 0);
193 $tmp["$from-" . ($to + 1)] = 1;
194 }
195 $rsv_ids = [0];
196 }
197
198 // placeholder
199
201 foreach ($book_ids as $book_id) {
202 if (in_array($book_id, $rsv_ids) || count($rsv_ids) === 0) {
203 $obj = new \ilBookingReservation($book_id);
204 $from = $obj->getFrom();
205 $to = $obj->getTo();
206 if ($from > time()) {
207 $tmp[$from . "-" . $to + 1] = $tmp[$from . "-" . $to + 1] ?? 0;
208 $tmp[$from . "-" . $to + 1]++;
209 }
210 }
211 }
212
215
216 $period = array();
217 ksort($tmp);
218 foreach ($tmp as $time => $counter) {
219 $time = explode("-", $time);
221 new \ilDateTime($time[0], IL_CAL_UNIX),
222 new \ilDateTime($time[1], IL_CAL_UNIX)
223 );
224 if ($counter > 1) {
225 $time .= " (" . $counter . ")";
226 }
227 $period[] = $time;
228 }
229 $book_id = array_shift($book_ids);
230
232
233 /*
234 #23578 since Booking pool participants.
235 $obj = new ilBookingReservation($book_id);
236 if ($obj->getUserId() != $ilUser->getId())
237 {
238 return;
239 }
240 */
241
242 $obj = new \ilBookingObject($id);
243 $pfile = $this->objects_manager->getBookingInfoFilename($id);
244 $ptext = $obj->getPostText();
245
246 $mytpl = new \ilTemplate('tpl.booking_reservation_post.html', true, true, 'components/ILIAS/BookingManager/BookingProcess');
247 $mytpl->setVariable("TITLE", $lng->txt('book_post_booking_information'));
248
249 if ($ptext) {
250 // placeholder
251 $ptext = str_replace(
252 ["[OBJECT]", "[PERIOD]"],
253 [$obj->getTitle(), implode("<br />", $period)],
254 $ptext
255 );
256
257 $mytpl->setVariable("POST_TEXT", nl2br($ptext));
258 }
259
260 if ($pfile) {
261 $url = $ctrl->getLinkTarget($this->parent_gui, $file_deliver_cmd);
262
263 $mytpl->setVariable("DOWNLOAD", $lng->txt('download'));
264 $mytpl->setVariable("URL_FILE", $url);
265 $mytpl->setVariable("TXT_FILE", $pfile);
266 }
267
268 $mytpl->setVariable("TXT_SUBMIT", $lng->txt('ok'));
269 $mytpl->setVariable("URL_SUBMIT", $ctrl->getLinkTarget($this->parent_gui, "back"));
270
271 $main_tpl->setContent($mytpl->get());
272 }
273
277 public function deliverPostFile(
278 int $book_obj_id,
279 int $user_id
280 ): void {
281 $this->log->debug("deliverPostFile");
282 $id = $book_obj_id;
283 if (!$id) {
284 return;
285 }
286
288 $book_id = current($book_ids);
289 $obj = new \ilBookingReservation($book_id);
290 if ($obj->getUserId() !== $user_id) {
291 return;
292 }
293
294 $this->domain->objects($this->pool->getId())->deliverBookingInfo($id);
295 }
296
297}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(InternalDomainService $domain_service, InternalGUIService $gui_service, \ilObjBookingPool $pool, object $parent_gui)
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)
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
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
@inheritDoc
isAsynch()
@inheritDoc
redirect(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=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
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...
global $lng
Definition: privfeed.php:31
$url
Definition: shib_logout.php:70
$counter