ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ProcessUtilGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 
29 {
32  protected \ilCtrl $ctrl;
33  protected \ilLogger $log;
34  protected \ilObjBookingPool $pool;
35  protected \ilBookingHelpAdapter $help;
38  protected object $parent_gui;
39 
40  public function __construct(
41  InternalDomainService $domain_service,
42  InternalGUIService $gui_service,
43  \ilObjBookingPool $pool,
44  object $parent_gui
45  ) {
46  $this->gui = $gui_service;
47  $this->domain = $domain_service;
48  $this->log = $domain_service->log();
49  $this->help = $gui_service->bookingHelp($pool);
50  $this->parent_gui = $parent_gui;
51  $this->pool = $pool;
52  $this->ctrl = $this->gui->ctrl();
53  $this->request = $this->gui->standardRequest();
54  $this->objects_manager = $domain_service->objects($pool->getId());
55  }
56 
57  // Back to parent
58  public function back(): void
59  {
60  $this->log->debug("back");
61  $retCmd = $this->request->getReturnCmd();
62  $this->log->debug("returnCmd is " . $retCmd);
63  if ($retCmd !== "") {
64  $this->ctrl->redirectByClass(get_class($this->parent_gui), $retCmd);
65  } else {
66  //var_dump(get_class($this->parent_gui));
67  //exit;
68  $this->ctrl->returnToParent($this->parent_gui);
69  }
70  }
71 
72  public function setHelpId(string $a_id): void
73  {
74  $this->help->setHelpId($a_id);
75  }
76 
77  // Table to assign participants to an object.
78  public function assignParticipants(int $book_obj_id): void
79  {
80  $tabs = $this->gui->tabs();
81  $ctrl = $this->gui->ctrl();
82  $lng = $this->domain->lng();
83  $main_tpl = $this->gui->mainTemplate();
84 
85  $tabs->clearTargets();
86  $tabs->setBackTarget($lng->txt('book_back_to_list'), $ctrl->getLinkTarget($this->parent_gui, 'back'));
87 
88  $table = new \ilBookingAssignParticipantsTableGUI($this->parent_gui, 'assignParticipants', $this->pool->getRefId(), $this->pool->getId(), $book_obj_id);
89  $main_tpl->setContent($table->getHTML());
90  }
91 
92 
93  /*
94  public function checkPermissionBool(string $a_perm) : bool
95  {
96  $access = $this->domain->access();
97  if (!$access->checkAccess($a_perm, "", $this->pool->getRefId())) {
98  return false;
99  }
100  return true;
101  }
102 
103  protected function checkPermission(string $a_perm) : void
104  {
105  $main_tpl = $this->gui->mainTemplate();
106  $lng = $this->domain->lng();
107 
108  if (!$this->checkPermissionBool($a_perm)) {
109  $main_tpl->setOnScreenMessage('failure', $lng->txt("no_permission"), true);
110  $this->back();
111  }
112  }*/
113 
114  public function handleBookingSuccess(
115  int $a_obj_id,
116  string $post_info_cmd,
117  ?array $a_rsv_ids = null
118  ): void {
119  $this->log->debug("handleBookingSuccess");
120  $main_tpl = $this->gui->mainTemplate();
121  $ctrl = $this->gui->ctrl();
122  $lng = $this->domain->lng();
123  $request = $this->gui->standardRequest();
124 
125  $main_tpl->setOnScreenMessage('success', $lng->txt('book_reservation_confirmed'), true);
126 
127  // show post booking information?
128  $obj = new \ilBookingObject($a_obj_id);
129  $pfile = $this->objects_manager->getBookingInfoFilename($a_obj_id);
130  $ptext = $obj->getPostText();
131 
132  if (trim($ptext) || $pfile) {
133  if (count($a_rsv_ids)) {
134  $ctrl->setParameter(
135  $this->parent_gui,
136  'rsv_ids',
137  implode(";", $a_rsv_ids)
138  );
139  }
140  $ctrl->redirect($this->parent_gui, $post_info_cmd);
141  } else {
142  if ($ctrl->isAsynch()) {
143  $this->gui->send("<script>window.location.href = '" .
144  $ctrl->getLinkTarget($this->parent_gui, $request->getReturnCmd()) . "';</script>");
145  } else {
146  $this->back();
147  }
148  }
149  }
150 
154  public function displayPostInfo(
155  int $book_obj_id,
156  int $user_id,
157  string $file_deliver_cmd
158  ): void {
159  $this->log->debug("displayPostInfo");
160  $main_tpl = $this->gui->mainTemplate();
161  $ctrl = $this->gui->ctrl();
162  $lng = $this->domain->lng();
163  $id = $book_obj_id;
164  $request = $this->gui->standardRequest();
165 
166  if (!$id) {
167  return;
168  }
169 
170  $rsv_ids = $request->getReservationIdsFromString();
171 
172  $tmp = [];
173  if ($rsv_ids === [] && $request->getReservationId() !== '') {
174  $reservationIdParts = explode('_', $request->getReservationId());
175 
176  $user_id = (int) ($reservationIdParts[1] ?? 0);
177  $from = (int) ($reservationIdParts[2] ?? 0);
178 
179  if ($from > time()) {
180  $to = (int) ($reservationIdParts[3] ?? 0);
181  $tmp["$from-" . ($to + 1)] = 1;
182  }
183  $rsv_ids = [0];
184  }
185 
186  // placeholder
187 
189  foreach ($book_ids as $book_id) {
190  if (in_array($book_id, $rsv_ids) || count($rsv_ids) === 0) {
191  $obj = new \ilBookingReservation($book_id);
192  $from = $obj->getFrom();
193  $to = $obj->getTo();
194  if ($from > time()) {
195  $tmp[$from . "-" . $to + 1] = $tmp[$from . "-" . $to + 1] ?? 0;
196  $tmp[$from . "-" . $to + 1]++;
197  }
198  }
199  }
200 
203 
204  $period = array();
205  ksort($tmp);
206  foreach ($tmp as $time => $counter) {
207  $time = explode("-", $time);
209  new \ilDateTime($time[0], IL_CAL_UNIX),
210  new \ilDateTime($time[1], IL_CAL_UNIX)
211  );
212  if ($counter > 1) {
213  $time .= " (" . $counter . ")";
214  }
215  $period[] = $time;
216  }
217  $book_id = array_shift($book_ids);
218 
220 
221  /*
222  #23578 since Booking pool participants.
223  $obj = new ilBookingReservation($book_id);
224  if ($obj->getUserId() != $ilUser->getId())
225  {
226  return;
227  }
228  */
229 
230  $obj = new \ilBookingObject($id);
231  $pfile = $this->objects_manager->getBookingInfoFilename($id);
232  $ptext = $obj->getPostText();
233 
234  $mytpl = new \ilTemplate('tpl.booking_reservation_post.html', true, true, 'components/ILIAS/BookingManager/BookingProcess');
235  $mytpl->setVariable("TITLE", $lng->txt('book_post_booking_information'));
236 
237  if ($ptext) {
238  // placeholder
239  $ptext = str_replace(
240  ["[OBJECT]", "[PERIOD]"],
241  [$obj->getTitle(), implode("<br />", $period)],
242  $ptext
243  );
244 
245  $mytpl->setVariable("POST_TEXT", nl2br($ptext));
246  }
247 
248  if ($pfile) {
249  $url = $ctrl->getLinkTarget($this->parent_gui, $file_deliver_cmd);
250 
251  $mytpl->setVariable("DOWNLOAD", $lng->txt('download'));
252  $mytpl->setVariable("URL_FILE", $url);
253  $mytpl->setVariable("TXT_FILE", $pfile);
254  }
255 
256  $mytpl->setVariable("TXT_SUBMIT", $lng->txt('ok'));
257  $mytpl->setVariable("URL_SUBMIT", $ctrl->getLinkTarget($this->parent_gui, "back"));
258 
259  $main_tpl->setContent($mytpl->get());
260  }
261 
265  public function deliverPostFile(
266  int $book_obj_id,
267  int $user_id
268  ): void {
269  $this->log->debug("deliverPostFile");
270  $id = $book_obj_id;
271  if (!$id) {
272  return;
273  }
274 
276  $book_id = current($book_ids);
277  $obj = new \ilBookingReservation($book_id);
278  if ($obj->getUserId() !== $user_id) {
279  return;
280  }
281 
282  $this->domain->objects($this->pool->getId())->deliverBookingInfo($id);
283  }
284 
285 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static array static setUseRelativeDates(bool $a_status)
set use relative dates
displayPostInfo(int $book_obj_id, int $user_id, string $file_deliver_cmd)
Display post booking informations.
static getObjectReservationForUser(int $a_object_id, int $a_user_id)
$url
Definition: shib_logout.php:68
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_CAL_UNIX
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Author: Alexander Killing killing@leifos.de
handleBookingSuccess(int $a_obj_id, string $post_info_cmd, ?array $a_rsv_ids=null)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
global $lng
Definition: privfeed.php:31
deliverPostFile(int $book_obj_id, int $user_id)
Deliver post booking file.
__construct(InternalDomainService $domain_service, InternalGUIService $gui_service, \ilObjBookingPool $pool, object $parent_gui)
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false, ?ilObjUser $user=null)
Format a period of two dates Shows: 14.