ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
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

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

Detailed Description

Booking preferences ui class.

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

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

Constructor & Destructor Documentation

◆ __construct()

ilBookingPreferencesGUI::__construct ( ilObjBookingPool  $pool)

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

45 {
46 global $DIC;
47
48 $this->ctrl = $DIC->ctrl();
49 $this->ui = $DIC->ui();
50 $this->lng = $DIC->language();
51 $this->user = $DIC->user();
52 $this->request = $DIC->http()->request();
53 $this->main_tpl = $DIC->ui()->mainTemplate();
54 $this->service = $DIC->bookingManager()->internal();
55 $this->pool = $pool;
56 $this->repo = $this->service->repo()->preferences();
57 $this->access = $DIC->bookingManager()->internal()->domain()->access();
58 $this->objects_manager = $DIC->bookingManager()->internal()->domain()
59 ->objects($pool->getId());
60 }
global $DIC
Definition: shib_login.php:26

References $DIC, $pool, ILIAS\Repository\access(), ILIAS\Repository\ctrl(), ilObject\getId(), 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 62 of file class.ilBookingPreferencesGUI.php.

62 : void
63 {
65
66 $next_class = $ctrl->getNextClass($this);
67 $cmd = $ctrl->getCmd("show");
68 if ($cmd === "render") {
69 $cmd = "show";
70 }
71 switch ($next_class) {
72 default:
73 if (in_array($cmd, ["show", "savePreferences"])) {
74 $this->$cmd();
75 }
76 }
77 }
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 104 of file class.ilBookingPreferencesGUI.php.

104 : Form\Standard
105 {
106 $ui = $this->ui;
107 $f = $ui->factory();
111
112 $preferences = $repo->getPreferencesOfUser($this->pool->getId(), $this->user->getId());
113 $preferences = $preferences->getPreferences();
114
115 $this->renderBookingInfo();
116
117 $fields = [];
118 foreach (ilBookingObject::getList($this->pool->getId()) as $book_obj) {
119 $checked = isset($preferences[$this->user->getId()]) &&
120 in_array((int) $book_obj["booking_object_id"], $preferences[$this->user->getId()], true);
121
122 $fields["cb_" . $book_obj["booking_object_id"]] =
123 $f->input()->field()->checkbox($book_obj["title"], $book_obj["description"])->withValue($checked);
124 }
125
126 // section
127 $section1 = $f->input()->field()->section($fields, $lng->txt("book_preferences"));
128
129 $form_action = $ctrl->getLinkTarget($this, "savePreferences");
130 return $f->input()->container()->form()->standard($form_action, ["sec" => $section1]);
131 }
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|LanguageIdentifier $a_topic, ?int $n=null)
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 204 of file class.ilBookingPreferencesGUI.php.

204 : void
205 {
209 $ui = $this->ui;
211
212 $info_gui = new ilInfoScreenGUI($this);
213
214 // preferences
215 $info_gui->addSection($lng->txt("book_your_preferences"));
216 $preferences = $repo->getPreferencesOfUser($this->pool->getId(), $this->user->getId());
217 $preferences = $preferences->getPreferences();
218 $cnt = 1;
219 if (isset($preferences[$this->user->getId()])) {
220 $book_deleted_object = "[{$this->lng->txt("book_deleted_object")}]";
221 foreach ($preferences[$this->user->getId()] as $book_obj_id) {
222 $book_obj = new ilBookingObject($book_obj_id);
223 $info_gui->addProperty((string) $cnt++, $book_obj->getTitle() ?: $book_deleted_object);
224 }
225 } else {
226 $info_gui->addProperty("", $lng->txt("book_no_preferences_for_you"));
227 }
228
229 // bookings
230 $this->service->domain()->preferences($this->pool)->storeBookings(
231 $this->repo->getPreferences($this->pool->getId())
232 );
233 $bookings = $this->service->domain()->preferences($this->pool)->readBookings();
234 $info_gui->addSection($lng->txt("book_your_bookings"));
235 $cnt = 1;
236 if (isset($bookings[$this->user->getId()])) {
237 foreach ($bookings[$this->user->getId()] as $book_obj_id) {
238 $book_obj = new ilBookingObject($book_obj_id);
239 $post_file = $this->objects_manager->getBookingInfoFilename($book_obj_id);
240
241 // post info button
242 $post_info_button = "";
243 if ($post_file || $book_obj->getPostText()) {
244 $ctrl->setParameterByClass("ilBookingObjectGUI", "object_id", $book_obj_id);
245 $b = $ui->factory()->button()->shy(
246 $lng->txt("book_post_booking_information"),
247 $ctrl->getLinkTargetByClass(["ilBookingObjectGUI", "ilBookingProcessWithoutScheduleGUI"], "displayPostInfo")
248 );
249 $post_info_button = "<br>" . $ui->renderer()->render($b);
250 }
251 $info_gui->addProperty((string) $cnt++, $book_obj->getTitle() . $post_info_button);
252 }
253 } else {
254 $info_gui->addProperty("", $lng->txt("book_no_bookings_for_you"));
255 }
256
257 // all users
258 if ($this->access->canManageAllReservations($this->pool->getRefId())) {
259 $info_gui->addSection($lng->txt("book_all_users"));
260 $preferences = $repo->getPreferences($this->pool->getId());
261 $preferences = $preferences->getPreferences();
262 $book_deleted_object = "[{$this->lng->txt("book_deleted_object")}]";
263 $book_deleted_booking = "[{$this->lng->txt("book_deleted_booking")}]";
264
265 $markdown = (new DataFactory())->text()->markdown();
266
267 foreach ($preferences as $user_id => $obj_ids) {
268 $booking_titles = !isset($bookings[$user_id])
269 ? [$book_deleted_booking]
270 : array_map(
271 static fn(int $obj_id): string => (new ilBookingObject($obj_id))->getTitle(),
272 $bookings[$user_id]
273 );
274
275 $booking_str = "{$lng->txt("book_log")}: " . implode(", ", $booking_titles);
276
277 $preferences_str = "{$lng->txt("book_preferences")}: " . implode(
278 ", ",
279 array_map(
280 fn(int $obj_id): string
281 => (new ilBookingObject($obj_id))->getTitle() ?: $book_deleted_object,
282 $obj_ids
283 )
284 );
285
286 $info_gui->addProperty(
287 ilUserUtil::getNamePresentation($user_id, false, false, "", true),
288 (string) $markdown->simpleDocument("{$preferences_str}\n{$booking_str}")->toHTML()
289 );
290 }
291 }
292
293 $main_tpl->setContent($info_gui->getHTML());
294 }
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
setParameterByClass(string $a_class, string $a_parameter, $a_value)
@inheritDoc
getLinkTargetByClass( $a_class, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@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=null)
Default behaviour is:
setContent(string $a_html)
Sets content for standard template.

References Vendor\Package\$b, $lng, $user_id, ILIAS\Repository\access(), ilCtrl\getLinkTargetByClass(), ilUserUtil\getNamePresentation(), ilBookingPreferencesDBRepository\getPreferences(), ilBookingPreferencesDBRepository\getPreferencesOfUser(), ILIAS\GlobalScreen\Scope\Footer\Factory\getTitle(), ILIAS\UICore\GlobalTemplate\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 90 of file class.ilBookingPreferencesGUI.php.

92 : void {
93 $ui = $this->ui;
94 if (count(ilBookingObject::getList($this->pool->getId())) > 0) {
95 if (is_null($form)) {
96 $form = $this->initPreferenceForm();
97 }
98 $this->main_tpl->setContent($ui->renderer()->render($form));
99 } else {
100 $this->main_tpl->setOnScreenMessage('info', $this->lng->txt("book_type_warning"));
101 }
102 }

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 191 of file class.ilBookingPreferencesGUI.php.

191 : void
192 {
194 $info = $lng->txt("book_preference_info");
195 $info = str_replace(["%1", "%2"], [
196 $this->pool->getPreferenceNumber(),
198 new ilDateTime($this->pool->getPreferenceDeadline(), IL_CAL_UNIX)
199 )
200 ], $info);
201 $this->main_tpl->setOnScreenMessage('info', $info);
202 }
const IL_CAL_UNIX
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
$info
Definition: entry_point.php:21

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

+ Here is the call graph for this function:

◆ savePreferences()

ilBookingPreferencesGUI::savePreferences ( )

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

133 : void
134 {
135 $preferences = $this->service->domain()->preferences($this->pool);
136
137 if (!$preferences->isGivingPreferencesPossible()) {
138 return;
139 }
140
142 $form = $this->initPreferenceForm();
146
147 if ($request->getMethod() === "POST") {
148 $form = $form->withRequest($request);
149 $data = $form->getData();
150
151 if (is_array($data["sec"])) {
152 $obj_ids = [];
153 foreach ($data["sec"] as $k => $v) {
154 if ($v === true) {
155 $id = explode("_", $k);
156 $obj_ids[] = (int) $id[1];
157 }
158 }
159
160 if (count($obj_ids) > $this->pool->getPreferenceNumber()) {
161 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("book_too_many_preferences"), true);
162 $this->listPreferenceOptions($form);
163 return;
164 }
165
166 if (count($obj_ids) < $this->pool->getPreferenceNumber()) {
167 $this->main_tpl->setOnScreenMessage('failure', $lng->txt("book_not_enough_preferences"), true);
168 $this->listPreferenceOptions($form);
169 return;
170 }
171
172 $preferences = $this->service->data()->preferences(
173 [$this->user->getId() => $obj_ids]
174 );
175
176 $repo->savePreferencesOfUser($this->pool->getId(), $this->user->getId(), $preferences);
177 $part = new ilBookingParticipant($this->user->getId(), $this->pool->getId());
178
179 $titles = implode(", ", array_map(static function ($id) {
181 }, $obj_ids));
182
183 $this->main_tpl->setOnScreenMessage('success', $lng->txt("book_preferences_saved") . " (" . $titles . ")", true);
184 }
185 }
186 $ctrl->redirect($this, "show");
187 }
$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.
Psr Http Message ServerRequestInterface $request
listPreferenceOptions(?Form\Standard $form=null)
redirect(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
@inheritDoc
$data
Definition: storeScorm.php:45

References $data, $id, $lng, $request, 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 79 of file class.ilBookingPreferencesGUI.php.

79 : void
80 {
81 $preferences = $this->service->domain()->preferences($this->pool);
82
83 if ($preferences->isGivingPreferencesPossible()) {
84 $this->listPreferenceOptions();
85 } else {
86 $this->listBookingResults();
87 }
88 }

References listBookingResults(), and listPreferenceOptions().

+ Here is the call graph for this function:

Field Documentation

◆ $access

AccessManager ilBookingPreferencesGUI::$access
protected

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

◆ $ctrl

ilCtrl ilBookingPreferencesGUI::$ctrl
protected

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

Referenced by executeCommand().

◆ $lng

ilLanguage ilBookingPreferencesGUI::$lng
protected

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

◆ $main_tpl

ilGlobalTemplateInterface ilBookingPreferencesGUI::$main_tpl
protected

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

◆ $objects_manager

ObjectsManager ilBookingPreferencesGUI::$objects_manager
protected

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

◆ $pool

ilObjBookingPool ilBookingPreferencesGUI::$pool
protected

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

Referenced by __construct().

◆ $repo

ilBookingPreferencesDBRepository ilBookingPreferencesGUI::$repo
protected

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

◆ $request

Psr Http Message ServerRequestInterface ilBookingPreferencesGUI::$request
protected

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

◆ $service

InternalService ilBookingPreferencesGUI::$service
protected

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

◆ $ui

ILIAS DI UIServices ilBookingPreferencesGUI::$ui
protected

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

Referenced by listPreferenceOptions().

◆ $user

ilObjUser ilBookingPreferencesGUI::$user
protected

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


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