ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
BookableItemTableDeleteAction.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
32use ILIAS\UI\Factory as UIFactory;
35use ilLanguage;
37use ILIAS\UI\Renderer as UIRenderer;
38
40{
42
43 public const string ACTION_ID = 'delete';
44 public const string ACTION_LABEL = 'delete_bookable_item';
45
46 public function __construct(
47 private readonly UIFactory $ui_factory,
48 private readonly UIRenderer $ui_renderer,
49 private readonly ilLanguage $lng,
50 private readonly ilGlobalTemplateInterface $tpl,
51 private readonly HttpService $http,
52 private readonly AccessManager $access,
53 private readonly ilObjBookingPool $pool,
54 private readonly int $ref_id,
55 private readonly bool $active_management,
56 ) {
57 }
58
59 public function getActionId(): string
60 {
61 return self::ACTION_ID;
62 }
63
64 public function getActionLabel(): string
65 {
66 return self::ACTION_LABEL;
67 }
68
69 public function isAvailable(): bool
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()->standard(
81 $this->lng->txt(self::ACTION_LABEL),
82 $url_builder
83 ->withParameter($action_token, self::ACTION_ID)
84 ->withParameter($action_type_token, self::SHOW_MODAL_ACTION),
85 $row_id_token
86 )->withAsync();
87 }
88
89 public function allowActionForRecord(mixed $record): bool
90 {
91 return true;
92 }
93
94 public function getModal(
95 URLBuilder $url_builder,
96 array $selected_records,
97 bool $all_records_selected
98 ): ?Modal {
99 return $this->ui_factory->modal()->interruptive(
100 $this->lng->txt('confirm'),
101 $this->lng->txt('book_confirm_delete'),
102 $url_builder->buildURI()->__toString()
103 )->withAffectedItems(
104 array_map(
105 fn(array $record): InterruptiveItem => $this->ui_factory->modal()->interruptiveItem()->standard(
106 (string) $record['booking_object_id'],
107 (string) $record['title']
108 ),
109 $selected_records
110 )
111 )->withActionButtonLabel($this->lng->txt('delete'));
112 }
113
114 public function onSubmit(
115 URLBuilder $url_builder,
116 array $selected_records,
117 bool $all_records_selected
118 ): ?Modal {
119 if (!$this->access->canManageObjects($this->ref_id)) {
120 $this->showErrorMessage($this->lng->txt('no_permission'));
121 return null;
122 }
123
124 foreach ($selected_records as $record) {
125 $object_id = (int) ($record['booking_object_id'] ?? 0);
126 if ($object_id <= 0) {
127 continue;
128 }
129
130 $object = new ilBookingObject($object_id);
131 $object->deleteReservationsAndCalEntries($object_id);
132 $object->delete();
133 }
134
135 $this->showSuccessMessage($this->lng->txt('book_object_deleted'));
136 return null;
137 }
138
143 protected function resolveRecords(?array $selected_ids = null): array
144 {
145 $by_id = [];
146 foreach (ilBookingObject::getList($this->pool->getId()) as $item) {
147 $by_id[(int) $item['booking_object_id']] = [
148 'booking_object_id' => (int) $item['booking_object_id'],
149 'title' => (string) $item['title'],
150 ];
151 }
152
153 if ($selected_ids === null) {
154 return array_values($by_id);
155 }
156
157 $unique = array_values(array_unique(array_map('intval', $selected_ids)));
158 $result = [];
159 foreach ($unique as $object_id) {
160 if (!isset($by_id[$object_id])) {
161 continue;
162 }
163
164 $result[] = $by_id[$object_id];
165 }
166
167 return $result;
168 }
169}
getTableAction(URLBuilder $url_builder, URLBuilderToken $row_id_token, URLBuilderToken $action_token, URLBuilderToken $action_type_token)
__construct(private readonly UIFactory $ui_factory, private readonly UIRenderer $ui_renderer, private readonly ilLanguage $lng, private readonly ilGlobalTemplateInterface $tpl, private readonly HttpService $http, private readonly AccessManager $access, private readonly ilObjBookingPool $pool, private readonly int $ref_id, private readonly bool $active_management,)
onSubmit(URLBuilder $url_builder, array $selected_records, bool $all_records_selected)
getModal(URLBuilder $url_builder, array $selected_records, bool $all_records_selected)
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getList(int $a_pool_id, ?string $a_title=null)
Get list of booking objects.
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
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
trait TableActionModalTrait
@template RecordType
readonly ilGlobalTemplateInterface $tpl
modal(string $title="", string $cancel_label="")
global $lng
Definition: privfeed.php:26
if(!file_exists('../ilias.ini.php'))