ILIAS  trunk Revision v12.0_alpha-1613-gae4c99ebb18
BookingsTableMailAction.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
32use ILIAS\UI\Factory as UIFactory;
33use ILIAS\UI\Renderer as UIRenderer;
36use ilLink;
39use ilObjUser;
40
42{
43 public const string ACTION_ID = 'mail';
44
45 public const string ACTION_LABEL = 'book_mail_to_booker';
46
47 public function __construct(
48 private readonly AccessManager $access,
49 private readonly UIFactory $ui_factory,
50 private readonly UIRenderer $ui_renderer,
51 private readonly Language $lng,
52 private readonly ReservationDBRepository $reservation_repository,
53 private readonly HttpService $http,
54 private readonly ilGlobalTemplateInterface $tpl,
55 private readonly ilCtrlInterface $ctrl,
56 private readonly ilObjBookingPool $booking_pool,
57 private readonly array $bookings
58 ) {
59 }
60
61 public function getActionId(): string
62 {
63 return self::ACTION_ID;
64 }
65
66 public function getActionLabel(): string
67 {
68 return self::ACTION_LABEL;
69 }
70
71 public function isAvailable(): bool
72 {
73 return true;
74 }
75
76 public function allowActionForRecord(mixed $record): bool
77 {
78 return $this->access->canManageAllReservations($this->booking_pool->getRefId());
79 }
80
81 public function getTableAction(
82 URLBuilder $url_builder,
83 URLBuilderToken $row_id_token,
84 URLBuilderToken $action_token,
85 URLBuilderToken $action_type_token
86 ): Action {
87 $action_type = $this->access->canManageAllReservations($this->booking_pool->getRefId()) ? 'standard' : 'single';
88 return $this->ui_factory->table()->action()->$action_type(
89 $this->lng->txt($this->getActionLabel()),
90 $url_builder
91 ->withParameter($action_token, self::ACTION_ID)
92 ->withParameter($action_type_token, 'mail'),
93 $row_id_token
94 );
95 }
96
97 public function onExecute(
98 URLBuilder $url_builder,
99 URLBuilderToken $row_id_token,
100 URLBuilderToken $action_token,
101 URLBuilderToken $action_type_token
102 ): mixed {
103 $row_parameters = $this->http->resolveRowParameters($row_id_token->getName());
104 $row_parameters = $row_parameters === HttpService::ALL_OBJECTS ? null : $row_parameters;
105 $selected_user_ids = $this->resolveRecords($row_parameters);
106
107 if ($selected_user_ids === []) {
108 $this->tpl->setOnScreenMessage(
110 $this->lng->txt('no_valid_selection'),
111 true
112 );
113 return null;
114 }
115
116 $users = [];
117 foreach ($selected_user_ids as $user_id) {
119 }
120
122 $return_url = $this->ctrl->getLinkTargetByClass(ilBookingReservationsGUI::class, ilBookingReservationsGUI::DEFAULT_CMD);
123 $this->ctrl->redirectToURL(ilMailFormCall::getRedirectTarget(
124 $return_url,
125 '',
126 [],
127 [
128 'type' => 'new',
129 'rcp_to' => implode(',', $users),
130 ilMailFormCall::SIGNATURE_KEY => $this->createMailSignature()
131 ]
132 ));
133 return null;
134 }
135
136 protected function resolveRecords(?array $selected_ids = null): array
137 {
138 $user_ids = array_map(
139 fn(int $reservation_id): int => $this->bookings[$reservation_id]['user_id'],
140 $selected_ids ?? array_keys($this->bookings)
141 );
142 return array_values(array_unique($user_ids));
143 }
144
145 private function createMailSignature(): string
146 {
147 // #16530 - see ilObjCourseGUI::createMailSignature
148 $sig = chr(13) . chr(10) . chr(13) . chr(10) . chr(13) . chr(10);
149 $sig .= "{$this->lng->txt('book_mail_permanent_link')}: ";
150 $sig .= chr(13) . chr(10);
151 $sig .= ilLink::_getLink($this->booking_pool->getRefId());
152 return rawurlencode(base64_encode($sig));
153 }
154}
onExecute(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)
getTableAction(URLBuilder $url_builder, URLBuilderToken $row_id_token, URLBuilderToken $action_token, URLBuilderToken $action_type_token)
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
final const string SIGNATURE_KEY
static getRedirectTarget( $gui, string $cmd, array $gui_params=[], array $mail_params=[], array $context_params=[])
static setRecipients(array $recipients, string $type='to')
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
static _lookupLogin(int $a_user_id)
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...
resolveRecords(?array $selected_ids=null)
static http()
Fetches the global http state from ILIAS.
global $lng
Definition: privfeed.php:26