ILIAS  trunk Revision v12.0_alpha-1613-gae4c99ebb18
BookableItemTableBookForParticipantAction.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29use ILIAS\Refinery\Factory as Refinery;
31use ILIAS\UI\Factory as UIFactory;
34use ilLanguage;
36
38{
39 public const string ACTION_ID = 'book_for_participant';
40 public const string ACTION_LABEL = 'book_assign_participants';
41
42 public function __construct(
43 private readonly UIFactory $ui_factory,
44 private readonly ilLanguage $lng,
45 private readonly ilCtrlInterface $ctrl,
46 private readonly HttpService $http,
47 private readonly Refinery $refinery,
48 private readonly AccessManager $access,
49 private readonly ilObjBookingPool $pool,
50 private readonly int $ref_id,
51 private readonly bool $active_management,
52 ) {
53 }
54
55 public function getActionId(): string
56 {
57 return self::ACTION_ID;
58 }
59
60 public function getActionLabel(): string
61 {
62 return self::ACTION_LABEL;
63 }
64
65 public function isAvailable(): bool
66 {
67 if ($this->pool->getScheduleType() === ilObjBookingPool::TYPE_NO_SCHEDULE_PREFERENCES) {
68 return false;
69 }
70
71 return $this->active_management && $this->access->canManageObjects($this->ref_id);
72 }
73
74 public function getTableAction(
75 URLBuilder $url_builder,
76 URLBuilderToken $row_id_token,
77 URLBuilderToken $action_token,
78 URLBuilderToken $action_type_token
79 ): Action {
80 return $this->ui_factory->table()->action()->single(
81 $this->lng->txt(self::ACTION_LABEL),
82 $url_builder
83 ->withParameter($action_token, self::ACTION_ID)
84 ->withParameter($action_type_token, 'redirect'),
85 $row_id_token
86 );
87 }
88
89 public function onExecute(
90 URLBuilder $url_builder,
91 URLBuilderToken $row_id_token,
92 URLBuilderToken $action_token,
93 URLBuilderToken $action_type_token
94 ): mixed {
95 $row_ids = $this->resolveRowIds($row_id_token->getName());
96 if ($row_ids === []) {
97 return null;
98 }
99
100 $first_parts = explode('_', $row_ids[0]);
101 $primary_object_id = (int) $first_parts[0];
102 if ($primary_object_id <= 0) {
103 return null;
104 }
105
106 $target_class = $this->pool->getScheduleType() === ilObjBookingPool::TYPE_FIX_SCHEDULE
107 ? ilBookingProcessWithScheduleGUI::class
108 : ilBookingProcessWithoutScheduleGUI::class;
109
110 $this->ctrl->setParameterByClass($target_class, 'object_id', (string) $primary_object_id);
111
112 if (isset($first_parts[1], $first_parts[2])) {
113 $this->ctrl->setParameterByClass(
114 $target_class,
115 'slot',
116 $first_parts[1] . '_' . $first_parts[2]
117 );
118 $this->ctrl->setParameterByClass($target_class, 'seed', date('Y-m-d', (int) $first_parts[1]));
119 }
120
121 $this->ctrl->redirectByClass($target_class, 'assignParticipants');
122 return null;
123 }
124
125 public function allowActionForRecord(mixed $record): bool
126 {
127 if (!is_array($record)) {
128 return false;
129 }
130
131 if ($this->pool->getOverallLimit() && (int) $record['available'] <= 0) {
132 return false;
133 }
134
135 return (bool) $record['is_available'];
136 }
137
141 private function resolveRowIds(string $key): array
142 {
143 $value = $this->http->get(
144 $key,
145 $this->refinery->custom()->transformation(
146 static function (mixed $raw): array {
147 if ($raw === null || $raw === '') {
148 return [];
149 }
150
151 if (is_array($raw)) {
152 return array_values(array_map('strval', $raw));
153 }
154
155 return [(string) $raw];
156 }
157 )
158 ) ?? [];
159
160 return array_values(array_filter($value, static fn(string $v): bool => $v !== ''));
161 }
162}
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 Refinery $refinery, private readonly AccessManager $access, 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
Builds data types.
Definition: Factory.php:36
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...
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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