ILIAS  trunk Revision v11.0_alpha-1861-g09f3d197f78
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 28 of file class.ilBookingPreferencesGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilBookingPreferencesGUI::__construct ( ilObjBookingPool  $pool)

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

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

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

Member Function Documentation

◆ executeCommand()

ilBookingPreferencesGUI::executeCommand ( )

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

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

61  : void
62  {
64 
65  $next_class = $ctrl->getNextClass($this);
66  $cmd = $ctrl->getCmd("show");
67  if ($cmd === "render") {
68  $cmd = "show";
69  }
70  switch ($next_class) {
71  default:
72  if (in_array($cmd, ["show", "savePreferences"])) {
73  $this->$cmd();
74  }
75  }
76  }
getCmd(?string $fallback_command=null)
getNextClass($a_gui_class=null)
+ Here is the call graph for this function:

◆ initPreferenceForm()

ilBookingPreferencesGUI::initPreferenceForm ( )

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

References $ctrl, Vendor\Package\$f, $lng, $repo, $ui, ilCtrl\getLinkTarget(), ilBookingObject\getList(), ilBookingPreferencesDBRepository\getPreferencesOfUser(), renderBookingInfo(), ilLanguage\txt(), and ILIAS\Repository\user().

Referenced by listPreferenceOptions(), and savePreferences().

103  : Form\Standard
104  {
105  $ui = $this->ui;
106  $f = $ui->factory();
107  $ctrl = $this->ctrl;
108  $lng = $this->lng;
109  $repo = $this->repo;
110 
111  $preferences = $repo->getPreferencesOfUser($this->pool->getId(), $this->user->getId());
112  $preferences = $preferences->getPreferences();
113 
114  $this->renderBookingInfo();
115 
116  $fields = [];
117  foreach (ilBookingObject::getList($this->pool->getId()) as $book_obj) {
118  $checked = isset($preferences[$this->user->getId()]) &&
119  in_array((int) $book_obj["booking_object_id"], $preferences[$this->user->getId()], true);
120 
121  $fields["cb_" . $book_obj["booking_object_id"]] =
122  $f->input()->field()->checkbox($book_obj["title"], $book_obj["description"])->withValue($checked);
123  }
124 
125  // section
126  $section1 = $f->input()->field()->section($fields, $lng->txt("book_preferences"));
127 
128  $form_action = $ctrl->getLinkTarget($this, "savePreferences");
129  return $f->input()->container()->form()->standard($form_action, ["sec" => $section1]);
130  }
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...
getLinkTarget(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
ilBookingPreferencesDBRepository $repo
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.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ listBookingResults()

ilBookingPreferencesGUI::listBookingResults ( )
protected

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

References Vendor\Package\$b, $ctrl, $lng, $main_tpl, $repo, $ui, $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(), ilLanguage\txt(), and ILIAS\Repository\user().

Referenced by show().

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

References $ui, ilBookingObject\getList(), initPreferenceForm(), and ILIAS\Repository\lng().

Referenced by savePreferences(), and show().

91  : void {
92  $ui = $this->ui;
93  if (count(ilBookingObject::getList($this->pool->getId())) > 0) {
94  if (is_null($form)) {
95  $form = $this->initPreferenceForm();
96  }
97  $this->main_tpl->setContent($ui->renderer()->render($form));
98  } else {
99  $this->main_tpl->setOnScreenMessage('info', $this->lng->txt("book_type_warning"));
100  }
101  }
static getList(int $a_pool_id, ?string $a_title=null)
Get list of booking objects.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ renderBookingInfo()

ilBookingPreferencesGUI::renderBookingInfo ( )
protected

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

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

Referenced by initPreferenceForm().

190  : void
191  {
192  $lng = $this->lng;
193  $info = $lng->txt("book_preference_info");
194  $info = str_replace(["%1", "%2"], [
195  $this->pool->getPreferenceNumber(),
197  new ilDateTime($this->pool->getPreferenceDeadline(), IL_CAL_UNIX)
198  )
199  ], $info);
200  $this->main_tpl->setOnScreenMessage('info', $info);
201  }
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...
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,)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ savePreferences()

ilBookingPreferencesGUI::savePreferences ( )

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

References $ctrl, $data, $id, $lng, $repo, $request, initPreferenceForm(), ILIAS\Repository\int(), listPreferenceOptions(), ilBookingObject\lookupTitle(), ilCtrl\redirect(), ilBookingPreferencesDBRepository\savePreferencesOfUser(), ilLanguage\txt(), and ILIAS\Repository\user().

132  : void
133  {
134  $preferences = $this->service->domain()->preferences($this->pool);
135 
136  if (!$preferences->isGivingPreferencesPossible()) {
137  return;
138  }
139 
141  $form = $this->initPreferenceForm();
142  $lng = $this->lng;
143  $ctrl = $this->ctrl;
144  $repo = $this->repo;
145 
146  if ($request->getMethod() === "POST") {
147  $form = $form->withRequest($request);
148  $data = $form->getData();
149 
150  if (is_array($data["sec"])) {
151  $obj_ids = [];
152  foreach ($data["sec"] as $k => $v) {
153  if ($v === true) {
154  $id = explode("_", $k);
155  $obj_ids[] = (int) $id[1];
156  }
157  }
158 
159  if (count($obj_ids) > $this->pool->getPreferenceNumber()) {
160  $this->main_tpl->setOnScreenMessage('failure', $lng->txt("book_too_many_preferences"), true);
161  $this->listPreferenceOptions($form);
162  return;
163  }
164 
165  if (count($obj_ids) < $this->pool->getPreferenceNumber()) {
166  $this->main_tpl->setOnScreenMessage('failure', $lng->txt("book_not_enough_preferences"), true);
167  $this->listPreferenceOptions($form);
168  return;
169  }
170 
171  $preferences = $this->service->data()->preferences(
172  [$this->user->getId() => $obj_ids]
173  );
174 
175  $repo->savePreferencesOfUser($this->pool->getId(), $this->user->getId(), $preferences);
176  $part = new ilBookingParticipant($this->user->getId(), $this->pool->getId());
177 
178  $titles = implode(", ", array_map(static function ($id) {
180  }, $obj_ids));
181 
182  $this->main_tpl->setOnScreenMessage('success', $lng->txt("book_preferences_saved") . " (" . $titles . ")", true);
183  }
184  }
185  $ctrl->redirect($this, "show");
186  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
listPreferenceOptions(?Form\Standard $form=null)
ilBookingPreferencesDBRepository $repo
redirect(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
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
static lookupTitle(int $object_id)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:

◆ show()

ilBookingPreferencesGUI::show ( )
protected

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

References listBookingResults(), and listPreferenceOptions().

78  : void
79  {
80  $preferences = $this->service->domain()->preferences($this->pool);
81 
82  if ($preferences->isGivingPreferencesPossible()) {
83  $this->listPreferenceOptions();
84  } else {
85  $this->listBookingResults();
86  }
87  }
listPreferenceOptions(?Form\Standard $form=null)
+ Here is the call graph for this function:

Field Documentation

◆ $access

AccessManager ilBookingPreferencesGUI::$access
protected

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

◆ $ctrl

ilCtrl ilBookingPreferencesGUI::$ctrl
protected

◆ $lng

ilLanguage ilBookingPreferencesGUI::$lng
protected

◆ $main_tpl

ilGlobalTemplateInterface ilBookingPreferencesGUI::$main_tpl
protected

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

Referenced by listBookingResults().

◆ $objects_manager

ObjectsManager ilBookingPreferencesGUI::$objects_manager
protected

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

◆ $pool

ilObjBookingPool ilBookingPreferencesGUI::$pool
protected

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

Referenced by __construct().

◆ $repo

ilBookingPreferencesDBRepository ilBookingPreferencesGUI::$repo
protected

◆ $request

Psr Http Message ServerRequestInterface ilBookingPreferencesGUI::$request
protected

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

Referenced by savePreferences().

◆ $service

InternalService ilBookingPreferencesGUI::$service
protected

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

◆ $ui

ILIAS DI UIServices ilBookingPreferencesGUI::$ui
protected

◆ $user

ilObjUser ilBookingPreferencesGUI::$user
protected

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


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