ILIAS  trunk Revision v12.0_alpha-1613-gae4c99ebb18
BookingsTableDeleteAction.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29use ilDateTime;
40use ILIAS\UI\Factory as UIFactory;
41use ILIAS\UI\Renderer as UIRenderer;
45use ilUserUtil;
46
48{
50
51 public const string ACTION_ID = 'delete';
52
53 public const string ACTION_LABEL = 'book_set_delete';
54
55 public function __construct(
56 private readonly AccessManager $access,
57 private readonly UIFactory $ui_factory,
58 private readonly UIRenderer $ui_renderer,
59 private readonly Language $lng,
60 private readonly ReservationDBRepository $reservation_repository,
61 private readonly HttpService $http,
62 private readonly ilGlobalTemplateInterface $tpl,
63 private readonly ilCtrlInterface $ctrl,
64 private readonly ilObjBookingPool $booking_pool,
65 private readonly array $bookings
66 ) {
67 }
68
69 public function getActionId(): string
70 {
71 return self::ACTION_ID;
72 }
73
74 public function getActionLabel(): string
75 {
76 return self::ACTION_LABEL;
77 }
78
79 public function isAvailable(): bool
80 {
81 return true;
82 }
83
84 public function allowActionForRecord(mixed $record): bool
85 {
86 return $this->access->canManageAllReservations($this->booking_pool->getRefId());
87 }
88
89 public function getTableAction(
90 URLBuilder $url_builder,
91 URLBuilderToken $row_id_token,
92 URLBuilderToken $action_token,
93 URLBuilderToken $action_type_token
94 ): Action {
95 $action_type = $this->access->canManageAllReservations($this->booking_pool->getRefId()) ? 'standard' : 'single';
96 return $this->ui_factory->table()->action()->$action_type(
97 $this->lng->txt($this->getActionLabel()),
98 $url_builder
99 ->withParameter($action_token, self::ACTION_ID)
100 ->withParameter($action_type_token, self::SHOW_MODAL_ACTION),
101 $row_id_token
102 )->withAsync();
103 }
104
105 protected function getModal(
106 URLBuilder $url_builder,
107 array $selected_records,
108 bool $all_records_selected
109 ): ?Modal {
110 return $this->ui_factory->modal()->interruptive(
111 $this->lng->txt('confirm'),
112 $this->lng->txt('book_confirm_delete'),
113 $url_builder->buildURI()->__toString()
114 )->withAffectedItems(
115 array_map(
116 fn(array $selected_record): Standard => $this->ui_factory->modal()->interruptiveItem()->standard(
117 (string) $selected_record['booking_reservation_id'],
118 $this->formatBookingDescription($selected_record)
119 ),
120 $selected_records
121 )
122 )->withActionButtonLabel($this->lng->txt($this->getActionLabel()));
123 }
124
125 protected function onSubmit(URLBuilder $url_builder, array $selected_records, bool $all_records_selected): ?Modal
126 {
127 if (!$this->access->canManageAllReservations($this->booking_pool->getRefId())) {
128 $this->showErrorMessage($this->lng->txt('no_permission'));
129 $this->ctrl->redirectByClass(ilBookingReservationsGUI::class, ilBookingReservationsGUI::DEFAULT_CMD);
130 return null;
131 }
132
133 foreach ($selected_records as $selected_record) {
134 $booking_reservation = new ilBookingReservation($selected_record['booking_reservation_id']);
135 $booking_reservation->delete();
136
137 if ($this->booking_pool->getScheduleType() !== ilObjBookingPool::TYPE_NO_SCHEDULE) {
138 $cal_entry_id = $booking_reservation->getCalendarEntry();
139 if ($cal_entry_id) {
140 (new ilCalendarEntry($cal_entry_id))->delete();
141 }
142 }
143 }
144
145 if ($selected_records !== []) {
146 $this->showSuccessMessage($this->lng->txt('reservation_deleted'));
147 }
148 $this->ctrl->redirectByClass(ilBookingReservationsGUI::class, ilBookingReservationsGUI::DEFAULT_CMD);
149 return null;
150 }
151
152 protected function resolveRecords(?array $selected_ids = null): array
153 {
154 return array_map(
155 fn(int $selected_record): array => $this->bookings[$selected_record],
156 $selected_ids ?? array_keys($this->bookings)
157 );
158 }
159
160 protected function formatBookingDescription(array $booking): string
161 {
162 $title = (new ilBookingObject($booking['object_id']))->getTitle();
163 $user = strip_tags(ilUserUtil::getNamePresentation($booking['user_id']));
164 $parts = [$title, $user];
165 if ($this->booking_pool->getScheduleType() !== ilObjBookingPool::TYPE_NO_SCHEDULE && $booking['date_from']) {
167 new ilDateTime($booking['date_from'], IL_CAL_UNIX),
168 new ilDateTime($booking['date_to'] + 1, IL_CAL_UNIX)
169 );
170 }
171 return implode(' – ', $parts);
172 }
173}
getModal(URLBuilder $url_builder, array $selected_records, bool $all_records_selected)
onSubmit(URLBuilder $url_builder, array $selected_records, bool $all_records_selected)
getTableAction(URLBuilder $url_builder, URLBuilderToken $row_id_token, URLBuilderToken $action_token, URLBuilderToken $action_type_token)
__construct(private readonly AccessManager $access, private readonly UIFactory $ui_factory, private readonly UIRenderer $ui_renderer, private readonly Language $lng, private readonly ReservationDBRepository $reservation_repository, private readonly HttpService $http, private readonly ilGlobalTemplateInterface $tpl, private readonly ilCtrlInterface $ctrl, private readonly ilObjBookingPool $booking_pool, private readonly array $bookings)
Repo class for reservations Acts on tables booking_reservation (rw), booking_reservation_group (rw) a...
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
withParameter(URLBuilderToken $token, string|array $value)
Change an acquired parameter's value if the supplied token is valid.
Definition: URLBuilder.php:166
const IL_CAL_UNIX
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...
Model for a calendar entry.
Class for date presentation.
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false, ?ilObjUser $user=null)
Format a period of two dates Shows: 14.
@classDescription Date and time handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilUserUtil.
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:
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This describes commonalities between the different modals.
Definition: Modal.php:35
An entity that renders components to a string output.
Definition: Renderer.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61
trait TableActionModalTrait
@template RecordType
modal(string $title="", string $cancel_label="")
global $lng
Definition: privfeed.php:26