ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilBookingPreferencesGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
11{
15 protected $ctrl;
16
20 protected $main_tpl;
21
25 protected $service;
26
30 protected $pool;
31
35 protected $ui;
36
40 protected $lng;
41
45 protected $request;
46
50 protected $user;
51
55 protected $repo;
56
60 protected $access;
61
66 {
67 global $DIC;
68
69 $this->ctrl = $DIC->ctrl();
70 $this->ui = $DIC->ui();
71 $this->lng = $DIC->language();
72 $this->user = $DIC->user();
73 $this->request = $DIC->http()->request();
74 $this->main_tpl = $DIC->ui()->mainTemplate();
75 $this->service = $DIC->bookingManager()->internal();
76 $this->pool = $pool;
77 $this->repo = $this->service->repo()->getPreferencesRepo();
78 $this->access = $DIC->access();
79 }
80
84 public function executeCommand()
85 {
87
88 $next_class = $ctrl->getNextClass($this);
89 $cmd = $ctrl->getCmd("show");
90 if ($cmd == "render") {
91 $cmd = "show";
92 }
93 switch ($next_class) {
94 default:
95 if (in_array($cmd, ["show", "savePreferences"])) {
96 $this->$cmd();
97 }
98 }
99 }
100
104 protected function show()
105 {
106 $preferences = $this->service->domain()->preferences($this->pool);
107
108 if ($preferences->isGivingPreferencesPossible()) {
109 $this->listPreferenceOptions();
110 } else {
111 $this->listBookingResults();
112 }
113 }
114
118 protected function listPreferenceOptions($form = null)
119 {
120 $ui = $this->ui;
121 if (count(ilBookingObject::getList($this->pool->getId())) > 0) {
122 if (is_null($form)) {
123 $form = $this->initPreferenceForm();
124 }
125 $this->main_tpl->setContent($ui->renderer()->render($form));
126 } else {
127 ilUtil::sendInfo($this->lng->txt("book_type_warning"));
128 }
129 }
130
135 public function initPreferenceForm()
136 {
137 $ui = $this->ui;
138 $f = $ui->factory();
142
143 $preferences = $repo->getPreferencesOfUser($this->pool->getId(), $this->user->getId());
144 $preferences = $preferences->getPreferences();
145
146 $this->renderBookingInfo();
147
148 $fields = [];
149 foreach (ilBookingObject::getList($this->pool->getId()) as $book_obj) {
150 $checked = (is_array($preferences[$this->user->getId()]) &&
151 in_array($book_obj["booking_object_id"], $preferences[$this->user->getId()]))
152 ? true
153 : false;
154
155 $fields["cb_" . $book_obj["booking_object_id"]] =
156 $f->input()->field()->checkbox($book_obj["title"], $book_obj["description"])->withValue($checked);
157 }
158
159 // section
160 $section1 = $f->input()->field()->section($fields, $lng->txt("book_preferences"));
161
162 $form_action = $ctrl->getLinkTarget($this, "savePreferences");
163 return $f->input()->container()->form()->standard($form_action, ["sec" => $section1]);
164 }
165
169 public function savePreferences()
170 {
171 $preferences = $this->service->domain()->preferences($this->pool);
172
173 if (!$preferences->isGivingPreferencesPossible()) {
174 return;
175 }
176
178 $form = $this->initPreferenceForm();
182
183 if ($request->getMethod() == "POST") {
184 $form = $form->withRequest($request);
185 $data = $form->getData();
186
187 if (is_array($data["sec"])) {
188 $obj_ids = [];
189 foreach ($data["sec"] as $k => $v) {
190 if ($v === true) {
191 $id = explode("_", $k);
192 $obj_ids[] = (int) $id[1];
193 }
194 }
195
196 if (count($obj_ids) > $this->pool->getPreferenceNumber()) {
197 ilUtil::sendFailure($lng->txt("book_too_many_preferences"), true);
198 $this->listPreferenceOptions($form);
199 return;
200 }
201
202 if (count($obj_ids) < $this->pool->getPreferenceNumber()) {
203 ilUtil::sendFailure($lng->txt("book_not_enough_preferences"), true);
204 $this->listPreferenceOptions($form);
205 return;
206 }
207
208 $preferences = $this->service->data()->preferencesFactory()->preferences(
209 [$this->user->getId() => $obj_ids]
210 );
211
212 $repo->savePreferencesOfUser($this->pool->getId(), $this->user->getId(), $preferences);
213 $part = new ilBookingParticipant($this->user->getId(), $this->pool->getId());
214
215 $titles = implode(", ", array_map(function ($id) {
217 }, $obj_ids));
218
219 ilUtil::sendSuccess($lng->txt("book_preferences_saved") . " (" . $titles . ")", true);
220 }
221 }
222 $ctrl->redirect($this, "show");
223 }
224
225
226
230 protected function renderBookingInfo()
231 {
233 $info = $lng->txt("book_preference_info");
234 $info = str_replace("%1", $this->pool->getPreferenceNumber(), $info);
235 $info = str_replace("%2", ilDatePresentation::formatDate(
236 new ilDateTime($this->pool->getPreferenceDeadline(), IL_CAL_UNIX)
237 ), $info);
238 ilUtil::sendInfo($info);
239 }
240
241
245 protected function listBookingResults()
246 {
250 $ui = $this->ui;
252
253 $info_gui = new ilInfoScreenGUI($this);
254
255 // preferences
256 $info_gui->addSection($lng->txt("book_your_preferences"));
257 $preferences = $repo->getPreferencesOfUser($this->pool->getId(), $this->user->getId());
258 $preferences = $preferences->getPreferences();
259 $cnt = 1;
260 if (is_array($preferences[$this->user->getId()])) {
261 foreach ($preferences[$this->user->getId()] as $book_obj_id) {
262 $book_obj = new ilBookingObject($book_obj_id);
263 $info_gui->addProperty((string) $cnt++, $book_obj->getTitle());
264 }
265 } else {
266 $info_gui->addProperty("", $lng->txt("book_no_preferences_for_you"));
267 }
268
269 // bookings
270 $this->service->domain()->preferences($this->pool)->storeBookings(
271 $this->repo->getPreferences($this->pool->getId())
272 );
273 $bookings = $this->service->domain()->preferences($this->pool)->readBookings();
274 $info_gui->addSection($lng->txt("book_your_bookings"));
275 $cnt = 1;
276 if (is_array($bookings[$this->user->getId()])) {
277 foreach ($bookings[$this->user->getId()] as $book_obj_id) {
278 $book_obj = new ilBookingObject($book_obj_id);
279
280 // post info button
281 $post_info_button = "";
282 if ($book_obj->getPostFile() || $book_obj->getPostText()) {
283 $ctrl->setParameterByClass("ilBookingObjectGUI", "object_id", $book_obj_id);
284 $b = $ui->factory()->button()->shy(
285 $lng->txt("book_post_booking_information"),
286 $ctrl->getLinkTargetByClass(["ilBookingObjectGUI", "ilBookingProcessGUI"], "displayPostInfo")
287 );
288 $post_info_button = "<br>" . $ui->renderer()->render($b);
289 }
290 $info_gui->addProperty((string) $cnt++, $book_obj->getTitle() . $post_info_button);
291 }
292 } else {
293 $info_gui->addProperty("", $lng->txt("book_no_bookings_for_you"));
294 }
295
296 // all users
297 if ($this->access->checkAccess("write", "", $this->pool->getRefId())) {
298 $info_gui->addSection($lng->txt("book_all_users"));
299 $preferences = $repo->getPreferences($this->pool->getId());
300 $preferences = $preferences->getPreferences();
301 foreach ($preferences as $user_id => $obj_ids) {
302 $booking_str = "<br>" . $lng->txt("book_log") . ": -";
303 if (is_array($bookings[$user_id])) {
304 $booking_str = "<br>" . $lng->txt("book_log") . ": " . implode(", ", array_map(function ($obj_id) {
305 $book_obj = new ilBookingObject($obj_id);
306 return $book_obj->getTitle();
307 }, $bookings[$user_id]));
308 }
309
310 $info_gui->addProperty(
311 ilUserUtil::getNamePresentation($user_id, false, false, "", true),
312 $lng->txt("book_preferences") . ": " . implode(", ", array_map(function ($obj_id) {
313 $book_obj = new ilBookingObject($obj_id);
314 return $book_obj->getTitle();
315 }, $obj_ids)) . $booking_str
316 );
317 }
318 }
319
320 $main_tpl->setContent($info_gui->getHTML());
321 }
322}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
a bookable ressource
static lookupTitle($object_id)
Lookup pool id.
static getList($a_pool_id, $a_title=null)
Get list of booking objects for given type.
Class ilBookingParticipant.
Booking preferences ui class.
__construct(ilObjBookingPool $pool)
Constructor.
listPreferenceOptions($form=null)
List preference options.
initPreferenceForm()
Init preferences form.
listBookingResults()
List booking results.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
Class ilInfoScreenGUI.
Class ilObjBookingPool.
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$data
Definition: storeScorm.php:23
ui()
Definition: ui.php:5
$DIC
Definition: xapitoken.php:46