ILIAS  trunk Revision v12.0_alpha-1613-gae4c99ebb18
BookableItemTableBookingsAction.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29use ILIAS\UI\Factory as UIFactory;
32use ilLanguage;
33use ilObjUser;
35
37{
38 public const string ACTION_ID = 'bookings';
39 public const string ACTION_LABEL = 'book_log';
40
41 public function __construct(
42 private readonly UIFactory $ui_factory,
43 private readonly ilLanguage $lng,
44 private readonly ilCtrlInterface $ctrl,
45 private readonly HttpService $http,
46 private readonly AccessManager $access,
47 private readonly ilObjUser $user,
48 private readonly ilObjBookingPool $pool,
49 private readonly int $ref_id,
50 private readonly bool $active_management,
51 ) {
52 }
53
54 public function getActionId(): string
55 {
56 return self::ACTION_ID;
57 }
58
59 public function getActionLabel(): string
60 {
61 return self::ACTION_LABEL;
62 }
63
64 public function isAvailable(): bool
65 {
66 return
67 $this->active_management
68 && ($this->access->canManageOwnReservations($this->ref_id) || $this->access->canManageObjects($this->ref_id));
69 }
70
71 public function getTableAction(
72 URLBuilder $url_builder,
73 URLBuilderToken $row_id_token,
74 URLBuilderToken $action_token,
75 URLBuilderToken $action_type_token
76 ): Action {
77 return $this->ui_factory->table()->action()->single(
78 $this->lng->txt(self::ACTION_LABEL),
79 $url_builder
80 ->withParameter($action_token, self::ACTION_ID)
81 ->withParameter($action_type_token, 'redirect'),
82 $row_id_token
83 );
84 }
85
86 public function onExecute(
87 URLBuilder $url_builder,
88 URLBuilderToken $row_id_token,
89 URLBuilderToken $action_token,
90 URLBuilderToken $action_type_token
91 ): mixed {
92 $row_id = (string) $this->http->resolveRowParameter($row_id_token->getName());
93 $object_id = (int) explode('_', $row_id)[0];
94
95 if ($object_id <= 0) {
96 return null;
97 }
98
99 $this->ctrl->setParameterByClass(ilBookingReservationsGUI::class, 'object_id', (int) $object_id);
100
101 if (!$this->access->canManageAllReservations($this->ref_id) && !$this->access->canReadPublicLog($this->ref_id)) {
102 $this->ctrl->setParameterByClass(ilBookingReservationsGUI::class, 'user_id', (int) $this->user->getId());
103 }
104
105 if ($this->pool->getScheduleType() === ilObjBookingPool::TYPE_FIX_SCHEDULE) {
106 $this->ctrl->setParameterByClass(ilBookingReservationsGUI::class, 'period_from', explode('_', $row_id)[1] ?? null);
107 $this->ctrl->setParameterByClass(ilBookingReservationsGUI::class, 'period_to', explode('_', $row_id)[2] ?? null);
108 }
109
110 $this->ctrl->redirectByClass(ilBookingReservationsGUI::class, '');
111 return null;
112 }
113
114 public function allowActionForRecord(mixed $record): bool
115 {
116 $has_reservations = $record['has_reservations'] ?? false;
117
118 if (
119 $this->access->canManageAllReservations($this->ref_id)
120 || $this->access->canReadPublicLog($this->ref_id)
121 ) {
122 return $has_reservations;
123 }
124
125 if ($this->access->canManageOwnReservations($this->ref_id)) {
126 return $has_reservations && ($record['has_user_booking'] ?? false);
127 }
128
129 return false;
130 }
131}
getTableAction(URLBuilder $url_builder, URLBuilderToken $row_id_token, URLBuilderToken $action_token, URLBuilderToken $action_type_token)
__construct(private readonly UIFactory $ui_factory, private readonly ilLanguage $lng, private readonly ilCtrlInterface $ctrl, private readonly HttpService $http, private readonly AccessManager $access, private readonly ilObjUser $user, private readonly ilObjBookingPool $pool, private readonly int $ref_id, private readonly bool $active_management,)
onExecute(URLBuilder $url_builder, URLBuilderToken $row_id_token, URLBuilderToken $action_token, URLBuilderToken $action_type_token)
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:66
static http()
Fetches the global http state from ILIAS.
global $lng
Definition: privfeed.php:26