ILIAS  release_7 Revision v7.30-3-g800a261c036
ilBookingPreferencesGUI Class Reference

Booking preferences ui class. More...

+ Collaboration diagram for ilBookingPreferencesGUI:

Public Member Functions

 __construct (ilObjBookingPool $pool)
 Constructor. More...
 
 executeCommand ()
 Execute command. More...
 
 initPreferenceForm ()
 Init preferences form. More...
 
 savePreferences ()
 Save preferences. More...
 

Protected Member Functions

 show ()
 Show. More...
 
 listPreferenceOptions ($form=null)
 List preference options. More...
 
 renderBookingInfo ()
 Render booking info. More...
 
 listBookingResults ()
 List booking results. More...
 

Protected Attributes

 $ctrl
 
 $main_tpl
 
 $service
 
 $pool
 
 $ui
 
 $lng
 
 $request
 
 $user
 
 $repo
 
 $access
 

Detailed Description

Booking preferences ui class.

Author
killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 10 of file class.ilBookingPreferencesGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilBookingPreferencesGUI::__construct ( ilObjBookingPool  $pool)

Constructor.

Definition at line 65 of file class.ilBookingPreferencesGUI.php.

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 }
user()
Definition: user.php:4
global $DIC
Definition: goto.php:24
ui()
Definition: ui.php:5

References $DIC, $pool, ui(), and user().

+ Here is the call graph for this function:

Member Function Documentation

◆ executeCommand()

ilBookingPreferencesGUI::executeCommand ( )

Execute command.

Definition at line 84 of file class.ilBookingPreferencesGUI.php.

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 }

References $ctrl.

◆ initPreferenceForm()

ilBookingPreferencesGUI::initPreferenceForm ( )

Init preferences form.

Returns
\ILIAS\UI\Component\Input\Container\Form\Standard

Definition at line 135 of file class.ilBookingPreferencesGUI.php.

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 }
static getList($a_pool_id, $a_title=null)
Get list of booking objects for given type.

References $ctrl, Vendor\Package\$f, $lng, $repo, $ui, ilBookingObject\getList(), renderBookingInfo(), and user().

Referenced by listPreferenceOptions(), and savePreferences().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ listBookingResults()

ilBookingPreferencesGUI::listBookingResults ( )
protected

List booking results.

Definition at line 245 of file class.ilBookingPreferencesGUI.php.

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 }
a bookable ressource
Class ilInfoScreenGUI.
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:

References Vendor\Package\$b, $ctrl, $lng, $main_tpl, $repo, $ui, ilUserUtil\getNamePresentation(), and user().

Referenced by show().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ listPreferenceOptions()

ilBookingPreferencesGUI::listPreferenceOptions (   $form = null)
protected

List preference options.

Definition at line 118 of file class.ilBookingPreferencesGUI.php.

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 }
initPreferenceForm()
Init preferences form.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.

References $ui, ilBookingObject\getList(), initPreferenceForm(), and ilUtil\sendInfo().

Referenced by savePreferences(), and show().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ renderBookingInfo()

ilBookingPreferencesGUI::renderBookingInfo ( )
protected

Render booking info.

Definition at line 230 of file class.ilBookingPreferencesGUI.php.

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 }
const IL_CAL_UNIX
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

References $lng, ilDatePresentation\formatDate(), IL_CAL_UNIX, and ilUtil\sendInfo().

Referenced by initPreferenceForm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ savePreferences()

ilBookingPreferencesGUI::savePreferences ( )

Save preferences.

Definition at line 169 of file class.ilBookingPreferencesGUI.php.

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 }
static lookupTitle($object_id)
Lookup pool id.
Class ilBookingParticipant.
listPreferenceOptions($form=null)
List preference options.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$data
Definition: storeScorm.php:23

References $ctrl, $data, $lng, $repo, $request, initPreferenceForm(), listPreferenceOptions(), ilBookingObject\lookupTitle(), ilUtil\sendFailure(), and user().

+ Here is the call graph for this function:

◆ show()

ilBookingPreferencesGUI::show ( )
protected

Show.

Definition at line 104 of file class.ilBookingPreferencesGUI.php.

105 {
106 $preferences = $this->service->domain()->preferences($this->pool);
107
108 if ($preferences->isGivingPreferencesPossible()) {
109 $this->listPreferenceOptions();
110 } else {
111 $this->listBookingResults();
112 }
113 }
listBookingResults()
List booking results.

References listBookingResults(), and listPreferenceOptions().

+ Here is the call graph for this function:

Field Documentation

◆ $access

ilBookingPreferencesGUI::$access
protected

Definition at line 60 of file class.ilBookingPreferencesGUI.php.

◆ $ctrl

ilBookingPreferencesGUI::$ctrl
protected

◆ $lng

ilBookingPreferencesGUI::$lng
protected

◆ $main_tpl

ilBookingPreferencesGUI::$main_tpl
protected

Definition at line 20 of file class.ilBookingPreferencesGUI.php.

Referenced by listBookingResults().

◆ $pool

ilBookingPreferencesGUI::$pool
protected

Definition at line 30 of file class.ilBookingPreferencesGUI.php.

Referenced by __construct().

◆ $repo

ilBookingPreferencesGUI::$repo
protected

◆ $request

ilBookingPreferencesGUI::$request
protected

Definition at line 45 of file class.ilBookingPreferencesGUI.php.

Referenced by savePreferences().

◆ $service

ilBookingPreferencesGUI::$service
protected

Definition at line 25 of file class.ilBookingPreferencesGUI.php.

◆ $ui

ilBookingPreferencesGUI::$ui
protected

◆ $user

ilBookingPreferencesGUI::$user
protected

Definition at line 50 of file class.ilBookingPreferencesGUI.php.


The documentation for this class was generated from the following file: