ILIAS  trunk Revision v12.0_alpha-1613-gae4c99ebb18
ScheduleTableDeleteAction.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
35use ILIAS\UI\Factory as UIFactory;
36use ILIAS\UI\Renderer as UIRenderer;
39use ilLanguage;
40
46{
48
49 public const string ACTION_ID = 'delete';
50
51 public const string ACTION_LABEL = 'delete';
52
53 public function __construct(
54 private readonly UIFactory $ui_factory,
55 private readonly UIRenderer $ui_renderer,
56 private readonly ilLanguage $lng,
57 private readonly AccessManager $access,
58 private readonly ilCtrlInterface $ctrl,
59 private readonly ilGlobalTemplateInterface $tpl,
60 private readonly HttpService $http,
61 private readonly ScheduleManager $schedule_manager,
62 private readonly int $ref_id,
63 ) {
64 }
65
66 public function getActionId(): string
67 {
68 return self::ACTION_ID;
69 }
70
71 public function getActionLabel(): string
72 {
73 return self::ACTION_LABEL;
74 }
75
76 public function isAvailable(): bool
77 {
78 return $this->access->canManageSettings($this->ref_id);
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 return $this->ui_factory->table()->action()->standard(
88 $this->lng->txt(self::ACTION_LABEL),
89 $url_builder
90 ->withParameter($action_token, self::ACTION_ID)
91 ->withParameter($action_type_token, self::SHOW_MODAL_ACTION),
92 $row_id_token
93 )->withAsync();
94 }
95
96 public function allowActionForRecord(mixed $record): bool
97 {
98 return $this->access->canManageSettings($this->ref_id) && !$record['is_used'];
99 }
100
101 public function getModal(
102 URLBuilder $url_builder,
103 array $selected_records,
104 bool $all_records_selected
105 ): ?Modal {
106 return $this->ui_factory->modal()->interruptive(
107 $this->lng->txt('confirm'),
108 $this->lng->txt('book_confirm_delete'),
109 $url_builder->buildURI()->__toString()
110 )->withAffectedItems(
111 array_map(
112 fn(array $record): InterruptiveItem => $this->ui_factory->modal()->interruptiveItem()->standard(
113 (string) $record['booking_schedule_id'],
114 $record['title'] ?? ''
115 ),
116 $selected_records
117 )
118 )->withActionButtonLabel($this->lng->txt('delete'));
119 }
120
121 public function onSubmit(
122 URLBuilder $url_builder,
123 array $selected_records,
124 bool $all_records_selected
125 ): ?Modal {
126 if (!$this->access->canManageSettings($this->ref_id)) {
127 $this->showErrorMessage($this->lng->txt('no_permission'));
128 return null;
129 }
130
131 $selected_records = array_filter(
132 $selected_records,
133 static fn(array $record): bool => !($record['is_used'] ?? true)
134 );
135
136 foreach ($selected_records as $record) {
137 (new ilBookingSchedule($record['booking_schedule_id']))->delete();
138 }
139
140 if ($selected_records !== []) {
141 $this->showSuccessMessage($this->lng->txt('book_schedule_deleted'));
142 }
143 $this->ctrl->redirectByClass(ilBookingScheduleGUI::class, 'render');
144 return null;
145 }
146
147 protected function resolveRecords(?array $selected_ids = null): array
148 {
149 $schedules = $this->schedule_manager->getScheduleData();
150
151 if ($selected_ids === null) {
152 return $schedules;
153 }
154
155 return array_filter(
156 array_map(
157 static fn(int $id): ?array => $schedules[$id] ?? null,
158 $selected_ids
159 )
160 );
161 }
162}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
@phpstan-type ScheduleRecord array{booking_schedule_id: int, title: string, object_has_schedule: ?...
onSubmit(URLBuilder $url_builder, array $selected_records, bool $all_records_selected)
__construct(private readonly UIFactory $ui_factory, private readonly UIRenderer $ui_renderer, private readonly ilLanguage $lng, private readonly AccessManager $access, private readonly ilCtrlInterface $ctrl, private readonly ilGlobalTemplateInterface $tpl, private readonly HttpService $http, private readonly ScheduleManager $schedule_manager, private readonly int $ref_id,)
getModal(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)
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
@ilCtrl_Calls ilBookingScheduleGUI:
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
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...
$ref_id
Definition: ltiauth.php:66
trait TableActionModalTrait
@template RecordType
modal(string $title="", string $cancel_label="")
global $lng
Definition: privfeed.php:26
if(!file_exists('../ilias.ini.php'))