ILIAS  release_8 Revision v8.24
ilBookingPreferencesGUI Class Reference

Booking preferences ui class. More...

+ Collaboration diagram for ilBookingPreferencesGUI:

Public Member Functions

 __construct (ilObjBookingPool $pool)
 
 executeCommand ()
 
 initPreferenceForm ()
 
 savePreferences ()
 

Protected Member Functions

 show ()
 
 listPreferenceOptions (Form\Standard $form=null)
 
 renderBookingInfo ()
 
 listBookingResults ()
 

Protected Attributes

ILIAS BookingManager InternalService $service
 
ilCtrl $ctrl
 
ilGlobalTemplateInterface $main_tpl
 
ilObjBookingPool $pool
 
ILIAS DI UIServices $ui
 
ilLanguage $lng
 
Psr Http Message ServerRequestInterface $request
 
ilObjUser $user
 
ilBookingPreferencesDBRepository $repo
 
ilAccessHandler $access
 

Detailed Description

Booking preferences ui class.

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

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

Constructor & Destructor Documentation

◆ __construct()

ilBookingPreferencesGUI::__construct ( ilObjBookingPool  $pool)

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

40 {
41 global $DIC;
42
43 $this->ctrl = $DIC->ctrl();
44 $this->ui = $DIC->ui();
45 $this->lng = $DIC->language();
46 $this->user = $DIC->user();
47 $this->request = $DIC->http()->request();
48 $this->main_tpl = $DIC->ui()->mainTemplate();
49 $this->service = $DIC->bookingManager()->internal();
50 $this->pool = $pool;
51 $this->repo = $this->service->repo()->preferences();
52 $this->access = $DIC->access();
53 }
global $DIC
Definition: feed.php:28

References $DIC, $pool, ILIAS\Repository\access(), ILIAS\Repository\ctrl(), ILIAS\Repository\lng(), ILIAS\Repository\ui(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

Member Function Documentation

◆ executeCommand()

ilBookingPreferencesGUI::executeCommand ( )

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

55 : void
56 {
58
59 $next_class = $ctrl->getNextClass($this);
60 $cmd = $ctrl->getCmd("show");
61 if ($cmd === "render") {
62 $cmd = "show";
63 }
64 switch ($next_class) {
65 default:
66 if (in_array($cmd, ["show", "savePreferences"])) {
67 $this->$cmd();
68 }
69 }
70 }
getNextClass($a_gui_class=null)
@inheritDoc
getCmd(string $fallback_command=null)
@inheritDoc

References $ctrl, ilCtrl\getCmd(), and ilCtrl\getNextClass().

+ Here is the call graph for this function:

◆ initPreferenceForm()

ilBookingPreferencesGUI::initPreferenceForm ( )

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

97 : Form\Standard
98 {
99 $ui = $this->ui;
100 $f = $ui->factory();
104
105 $preferences = $repo->getPreferencesOfUser($this->pool->getId(), $this->user->getId());
106 $preferences = $preferences->getPreferences();
107
108 $this->renderBookingInfo();
109
110 $fields = [];
111 foreach (ilBookingObject::getList($this->pool->getId()) as $book_obj) {
112 $checked = isset($preferences[$this->user->getId()]) &&
113 in_array((int) $book_obj["booking_object_id"], $preferences[$this->user->getId()], true);
114
115 $fields["cb_" . $book_obj["booking_object_id"]] =
116 $f->input()->field()->checkbox($book_obj["title"], $book_obj["description"])->withValue($checked);
117 }
118
119 // section
120 $section1 = $f->input()->field()->section($fields, $lng->txt("book_preferences"));
121
122 $form_action = $ctrl->getLinkTarget($this, "savePreferences");
123 return $f->input()->container()->form()->standard($form_action, ["sec" => $section1]);
124 }
static getList(int $a_pool_id, string $a_title=null)
Get list of booking objects.
getPreferencesOfUser(int $a_pool_id, int $a_user_id)
Get booking preferences for a pool id.
ilBookingPreferencesDBRepository $repo
getLinkTarget(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...

References Vendor\Package\$f, $lng, ilCtrl\getLinkTarget(), ilBookingObject\getList(), ilBookingPreferencesDBRepository\getPreferencesOfUser(), and ILIAS\Repository\user().

Referenced by listPreferenceOptions().

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

◆ listBookingResults()

ilBookingPreferencesGUI::listBookingResults ( )
protected

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

197 : void
198 {
202 $ui = $this->ui;
204
205 $info_gui = new ilInfoScreenGUI($this);
206
207 // preferences
208 $info_gui->addSection($lng->txt("book_your_preferences"));
209 $preferences = $repo->getPreferencesOfUser($this->pool->getId(), $this->user->getId());
210 $preferences = $preferences->getPreferences();
211 $cnt = 1;
212 if (isset($preferences[$this->user->getId()])) {
213 foreach ($preferences[$this->user->getId()] as $book_obj_id) {
214 $book_obj = new ilBookingObject($book_obj_id);
215 $info_gui->addProperty((string) $cnt++, $book_obj->getTitle());
216 }
217 } else {
218 $info_gui->addProperty("", $lng->txt("book_no_preferences_for_you"));
219 }
220
221 // bookings
222 $this->service->domain()->preferences($this->pool)->storeBookings(
223 $this->repo->getPreferences($this->pool->getId())
224 );
225 $bookings = $this->service->domain()->preferences($this->pool)->readBookings();
226 $info_gui->addSection($lng->txt("book_your_bookings"));
227 $cnt = 1;
228 if (isset($bookings[$this->user->getId()])) {
229 foreach ($bookings[$this->user->getId()] as $book_obj_id) {
230 $book_obj = new ilBookingObject($book_obj_id);
231
232 // post info button
233 $post_info_button = "";
234 if ($book_obj->getPostFile() || $book_obj->getPostText()) {
235 $ctrl->setParameterByClass("ilBookingObjectGUI", "object_id", $book_obj_id);
236 $b = $ui->factory()->button()->shy(
237 $lng->txt("book_post_booking_information"),
238 $ctrl->getLinkTargetByClass(["ilBookingObjectGUI", "ilBookingProcessGUI"], "displayPostInfo")
239 );
240 $post_info_button = "<br>" . $ui->renderer()->render($b);
241 }
242 $info_gui->addProperty((string) $cnt++, $book_obj->getTitle() . $post_info_button);
243 }
244 } else {
245 $info_gui->addProperty("", $lng->txt("book_no_bookings_for_you"));
246 }
247
248 // all users
249 if ($this->access->checkAccess("write", "", $this->pool->getRefId())) {
250 $info_gui->addSection($lng->txt("book_all_users"));
251 $preferences = $repo->getPreferences($this->pool->getId());
252 $preferences = $preferences->getPreferences();
253 foreach ($preferences as $user_id => $obj_ids) {
254 $booking_str = "<br>" . $lng->txt("book_log") . ": -";
255 if (isset($bookings[$user_id])) {
256 $booking_str = "<br>" . $lng->txt("book_log") . ": " . implode(", ", array_map(
257 static function ($obj_id) {
258 return (new ilBookingObject($obj_id))->getTitle();
259 },
260 $bookings[$user_id]
261 ));
262 }
263
264 $info_gui->addProperty(
265 ilUserUtil::getNamePresentation($user_id, false, false, "", true),
266 $lng->txt("book_preferences") . ": " . implode(", ", array_map(static function ($obj_id) {
267 return (new ilBookingObject($obj_id))->getTitle();
268 }, $obj_ids)) . $booking_str
269 );
270 }
271 }
272
273 $main_tpl->setContent($info_gui->getHTML());
274 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getPreferences(int $a_pool_id)
Get booking preferences for a pool id.
ilGlobalTemplateInterface $main_tpl
getLinkTargetByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
setParameterByClass(string $a_class, string $a_parameter, $a_value)
@inheritDoc
Class ilInfoScreenGUI.
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link="", bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
setContent(string $a_html)
Sets content for standard template.

References Vendor\Package\$b, $lng, ILIAS\Repository\access(), ilCtrl\getLinkTargetByClass(), ilUserUtil\getNamePresentation(), ilBookingPreferencesDBRepository\getPreferences(), ilBookingPreferencesDBRepository\getPreferencesOfUser(), ilGlobalTemplateInterface\setContent(), ilCtrl\setParameterByClass(), and ILIAS\Repository\user().

Referenced by show().

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

◆ listPreferenceOptions()

ilBookingPreferencesGUI::listPreferenceOptions ( Form\Standard  $form = null)
protected

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

85 : void {
86 $ui = $this->ui;
87 if (count(ilBookingObject::getList($this->pool->getId())) > 0) {
88 if (is_null($form)) {
89 $form = $this->initPreferenceForm();
90 }
91 $this->main_tpl->setContent($ui->renderer()->render($form));
92 } else {
93 $this->main_tpl->setOnScreenMessage('info', $this->lng->txt("book_type_warning"));
94 }
95 }

References $ui, and initPreferenceForm().

Referenced by show().

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

◆ renderBookingInfo()

ilBookingPreferencesGUI::renderBookingInfo ( )
protected

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

184 : void
185 {
187 $info = $lng->txt("book_preference_info");
188 $info = str_replace(["%1", "%2"], [
189 $this->pool->getPreferenceNumber(),
191 new ilDateTime($this->pool->getPreferenceDeadline(), IL_CAL_UNIX)
192 )
193 ], $info);
194 $this->main_tpl->setOnScreenMessage('info', $info);
195 }
const IL_CAL_UNIX
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling

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

+ Here is the call graph for this function:

◆ savePreferences()

ilBookingPreferencesGUI::savePreferences ( )

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

126 : void
127 {
128 $preferences = $this->service->domain()->preferences($this->pool);
129
130 if (!$preferences->isGivingPreferencesPossible()) {
131 return;
132 }
133
135 $form = $this->initPreferenceForm();
139
140 if ($request->getMethod() === "POST") {
141 $form = $form->withRequest($request);
142 $data = $form->getData();
143
144 if (is_array($data["sec"])) {
145 $obj_ids = [];
146 foreach ($data["sec"] as $k => $v) {
147 if ($v === true) {
148 $id = explode("_", $k);
149 $obj_ids[] = (int) $id[1];
150 }
151 }
152
153 if (count($obj_ids) > $this->pool->getPreferenceNumber()) {
154 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("book_too_many_preferences"), true);
155 $this->listPreferenceOptions($form);
156 return;
157 }
158
159 if (count($obj_ids) < $this->pool->getPreferenceNumber()) {
160 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("book_not_enough_preferences"), true);
161 $this->listPreferenceOptions($form);
162 return;
163 }
164
165 $preferences = $this->service->data()->preferences(
166 [$this->user->getId() => $obj_ids]
167 );
168
169 $repo->savePreferencesOfUser($this->pool->getId(), $this->user->getId(), $preferences);
170 $part = new ilBookingParticipant($this->user->getId(), $this->pool->getId());
171
172 $titles = implode(", ", array_map(static function ($id) {
174 }, $obj_ids));
175
176 $this->main_tpl->setOnScreenMessage('success', $lng->txt("book_preferences_saved") . " (" . $titles . ")", true);
177 }
178 }
179 $ctrl->redirect($this, "show");
180 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static lookupTitle(int $object_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
savePreferencesOfUser(int $a_pool_id, int $a_user_id, ilBookingPreferences $preferences)
Save all preferences of a user for a pool.
listPreferenceOptions(Form\Standard $form=null)
Psr Http Message ServerRequestInterface $request
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
@inheritDoc

References $data, $id, $lng, ILIAS\Repository\int(), ilBookingObject\lookupTitle(), ilCtrl\redirect(), ilBookingPreferencesDBRepository\savePreferencesOfUser(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ show()

ilBookingPreferencesGUI::show ( )
protected

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

72 : void
73 {
74 $preferences = $this->service->domain()->preferences($this->pool);
75
76 if ($preferences->isGivingPreferencesPossible()) {
77 $this->listPreferenceOptions();
78 } else {
79 $this->listBookingResults();
80 }
81 }

References listBookingResults(), and listPreferenceOptions().

+ Here is the call graph for this function:

Field Documentation

◆ $access

ilAccessHandler ilBookingPreferencesGUI::$access
protected

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

◆ $ctrl

ilCtrl ilBookingPreferencesGUI::$ctrl
protected

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

Referenced by executeCommand().

◆ $lng

ilLanguage ilBookingPreferencesGUI::$lng
protected

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

◆ $main_tpl

ilGlobalTemplateInterface ilBookingPreferencesGUI::$main_tpl
protected

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

◆ $pool

ilObjBookingPool ilBookingPreferencesGUI::$pool
protected

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

Referenced by __construct().

◆ $repo

ilBookingPreferencesDBRepository ilBookingPreferencesGUI::$repo
protected

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

◆ $request

Psr Http Message ServerRequestInterface ilBookingPreferencesGUI::$request
protected

◆ $service

ILIAS BookingManager InternalService ilBookingPreferencesGUI::$service
protected

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

◆ $ui

ILIAS DI UIServices ilBookingPreferencesGUI::$ui
protected

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

Referenced by listPreferenceOptions().

◆ $user

ilObjUser ilBookingPreferencesGUI::$user
protected

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


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