ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilMDCopyrightConfigurationGUI Class Reference

@ilCtrl_Calls ilMDCopyrightConfigurationGUI: ilMDCopyrightUsageGUI, ilMDCopyrightImageUploadHandlerGUI More...

+ Collaboration diagram for ilMDCopyrightConfigurationGUI:

Public Member Functions

 __construct (ilObjMDSettingsGUI $parent_obj_gui)
 
 executeCommand ()
 
 showCopyrightSelection (int $current_id=0, ?RoundTrip $current_modal=null)
 
 saveEntry ()
 
 confirmDeleteEntries ()
 
 deleteEntries ()
 
 updateEntry ()
 
 saveCopyrightPosition ()
 

Protected Member Functions

 initCopyrightEditModal (?EntryInterface $entry=null, bool $open_on_load=false)
 
 deleteFile (EntryInterface $entry)
 
 deleteFileIfChanged (EntryInterface $entry, array $data)
 
 extractImageFromData (array $data)
 
 initEntryIdFromQuery ()
 
 initEntryIdFromPost ()
 

Protected Attributes

ilCtrl $ctrl
 
ilGlobalTemplateInterface $tpl
 
ilLanguage $lng
 
ilToolbarGUI $toolbar_gui
 
GlobalHttpState $http
 
Factory $refinery
 
UIFactory $ui_factory
 
UIRenderer $ui_renderer
 
IRSS $irss
 
ilObjMDSettingsGUI $parent_obj_gui
 
ilMDSettingsAccessService $access_service
 
RendererInterface $renderer
 
RepositoryInterface $repository
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilMDCopyrightConfigurationGUI::__construct ( ilObjMDSettingsGUI  $parent_obj_gui)

Definition at line 56 of file class.ilMDCopyrightConfigurationGUI.php.

57 {
58 global $DIC;
59
60 $this->ctrl = $DIC->ctrl();
61 $this->lng = $DIC->language();
62 $this->tpl = $DIC->ui()->mainTemplate();
63 $this->toolbar_gui = $DIC->toolbar();
64 $this->http = $DIC->http();
65 $this->refinery = $DIC->refinery();
66 $this->ui_factory = $DIC->ui()->factory();
67 $this->ui_renderer = $DIC->ui()->renderer();
68 $this->irss = $DIC->resourceStorage();
69
70 $this->parent_obj_gui = $parent_obj_gui;
71 $this->access_service = new ilMDSettingsAccessService(
72 $this->parent_obj_gui->getRefId(),
73 $DIC->access()
74 );
75 $this->renderer = new Renderer(
76 $DIC->ui()->factory(),
77 $DIC->resourceStorage()
78 );
79 $this->repository = new DatabaseRepository(new Wrapper($DIC->database()));
80
81 $this->lng->loadLanguageModule("meta");
82 }
renderer()
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26

References $DIC, $parent_obj_gui, ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), renderer(), and ILIAS\UI\examples\Deck\repository().

+ Here is the call graph for this function:

Member Function Documentation

◆ confirmDeleteEntries()

ilMDCopyrightConfigurationGUI::confirmDeleteEntries ( )

Definition at line 193 of file class.ilMDCopyrightConfigurationGUI.php.

193 : void
194 {
195 $entry_ids = $this->initEntryIdFromPost();
196 if (!count($entry_ids)) {
197 $this->tpl->setOnScreenMessage('info', $this->lng->txt('select_one'));
198 $this->showCopyrightSelection();
199 return;
200 }
201
202 $c_gui = new ilConfirmationGUI();
203 // set confirm/cancel commands
204 $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteEntries"));
205 $c_gui->setHeaderText($this->lng->txt("md_delete_cp_sure"));
206 $c_gui->setCancel($this->lng->txt("cancel"), "showCopyrightSelection");
207 $c_gui->setConfirm($this->lng->txt("confirm"), "deleteEntries");
208
209 // add items to delete
210 foreach ($entry_ids as $entry_id) {
211 $entry = $this->repository->getEntry($entry_id);
212 $c_gui->addItem('entry_id[]', (string) $entry_id, $entry->title());
213 }
214 $this->tpl->setContent($c_gui->getHTML());
215 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
showCopyrightSelection(int $current_id=0, ?RoundTrip $current_modal=null)

References ILIAS\Repository\ctrl(), ILIAS\Repository\lng(), and ILIAS\UI\examples\Deck\repository().

+ Here is the call graph for this function:

◆ deleteEntries()

ilMDCopyrightConfigurationGUI::deleteEntries ( )

Definition at line 217 of file class.ilMDCopyrightConfigurationGUI.php.

217 : bool
218 {
219 $entry_ids = $this->initEntryIdFromPost();
220 if (!count($entry_ids)) {
221 $this->tpl->setOnScreenMessage('info', $this->lng->txt('select_one'));
222 $this->showCopyrightSelection();
223 return true;
224 }
225
226 foreach ($entry_ids as $entry_id) {
227 $entry = $this->repository->getEntry($entry_id);
228 $this->deleteFile($entry);
229 $this->repository->deleteEntry($entry_id);
230 }
231 $this->tpl->setOnScreenMessage('success', $this->lng->txt('md_copyrights_deleted'));
232 $this->showCopyrightSelection();
233 return true;
234 }

References ILIAS\Repository\lng(), and ILIAS\UI\examples\Deck\repository().

+ Here is the call graph for this function:

◆ deleteFile()

ilMDCopyrightConfigurationGUI::deleteFile ( EntryInterface  $entry)
protected

Definition at line 408 of file class.ilMDCopyrightConfigurationGUI.php.

408 : void
409 {
410 if (($image_file = $entry->copyrightData()->imageFile()) === '') {
411 return;
412 }
413 if ($id = $this->irss->manage()->find($image_file)) {
414 $this->irss->manage()->remove($id, new ilMDCopyrightImageStakeholder());
415 }
416 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References $id, and ILIAS\MetaData\Copyright\EntryInterface\copyrightData().

+ Here is the call graph for this function:

◆ deleteFileIfChanged()

ilMDCopyrightConfigurationGUI::deleteFileIfChanged ( EntryInterface  $entry,
array  $data 
)
protected

Definition at line 418 of file class.ilMDCopyrightConfigurationGUI.php.

421 : void {
422 if (($image_file = $entry->copyrightData()->imageFile()) === '') {
423 return;
424 }
425 if (
426 $data['copyright']['image'][0] === 'file_group' &&
427 $image_file === ($data['copyright']['image'][1]['image_file'][0] ?? '')
428 ) {
429 return;
430 }
431 $this->deleteFile($entry);
432 }

◆ executeCommand()

ilMDCopyrightConfigurationGUI::executeCommand ( )

Definition at line 84 of file class.ilMDCopyrightConfigurationGUI.php.

84 : void
85 {
86 $next_class = $this->ctrl->getNextClass($this);
87 $cmd = $this->ctrl->getCmd();
88
89 if (
90 !$this->access_service->hasCurrentUserVisibleAccess() ||
91 !$this->access_service->hasCurrentUserReadAccess()
92 ) {
93 throw new ilPermissionException($this->lng->txt('no_permission'));
94 }
95
96 switch ($next_class) {
97 case strtolower(ilMDCopyrightUsageGUI::class):
98 // this command is used if copyrightUsageGUI calls getParentReturn (see ...UsageGUI->setTabs)
99 $this->ctrl->setReturn($this, 'showCopyrightSelection');
100 $entry = $this->repository->getEntry($this->initEntryIdFromQuery());
101 $gui = new ilMDCopyrightUsageGUI($entry);
102 $this->ctrl->forwardCommand($gui);
103 break;
104
105 case strtolower(ilMDCopyrightImageUploadHandlerGUI::class):
106 $entry = $this->repository->getEntry($this->initEntryIdFromQuery());
107 $file_id = empty($entry?->copyrightData()?->imageFile()) ? '' : $entry?->copyrightData()?->imageFile();
109 $this->ctrl->forwardCommand($handler);
110
111 // no break
112 default:
113 if (!$cmd || $cmd === 'view') {
114 $cmd = 'showCopyrightSelection';
115 }
116
117 $this->$cmd();
118 break;
119 }
120 }
$handler
Definition: oai.php:29

References $handler, ILIAS\Repository\ctrl(), initEntryIdFromQuery(), ILIAS\Repository\lng(), and ILIAS\UI\examples\Deck\repository().

+ Here is the call graph for this function:

◆ extractImageFromData()

ilMDCopyrightConfigurationGUI::extractImageFromData ( array  $data)
protected

Definition at line 434 of file class.ilMDCopyrightConfigurationGUI.php.

434 : string|URI
435 {
436 $v = $data['copyright']['image'];
437 if ($v[0] === 'link_group') {
438 return empty($link = $v[1]['image_link']) ? '' : $link;
439 }
440 if ($v[0] === 'file_group') {
441 return $v[1]['image_file'][0] ?? '';
442 }
443 return '';
444 }
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35

References $data.

◆ initCopyrightEditModal()

ilMDCopyrightConfigurationGUI::initCopyrightEditModal ( ?EntryInterface  $entry = null,
bool  $open_on_load = false 
)
protected

Definition at line 262 of file class.ilMDCopyrightConfigurationGUI.php.

265 : RoundTrip {
266 $inputs = [];
267 $ff = $this->ui_factory->input()->field();
268
269 $title = $ff
270 ->text($this->lng->txt('title'))
271 ->withValue($entry?->title() ?? '')
272 ->withRequired(true)
273 ->withMaxLength(255);
274 $inputs['title'] = $title;
275
276 $des = $ff
277 ->textarea($this->lng->txt('description'))
278 ->withValue($entry?->description() ?? '');
279 $inputs['description'] = $des;
280
281 $usage = $ff
282 ->radio($this->lng->txt('meta_copyright_usage'))
283 ->withOption('0', $this->lng->txt('meta_copyright_in_use'))
284 ->withOption('1', $this->lng->txt('meta_copyright_outdated'))
285 ->withValue((int) $entry?->isOutdated());
286 $inputs['outdated'] = $usage;
287
288 $cp_data = $entry?->copyrightData();
289
290 $full_name = $ff
291 ->text($this->lng->txt('md_copyright_full_name'))
292 ->withValue($cp_data?->fullName() ?? '');
293
294 $link = $ff
295 ->url(
296 $this->lng->txt('md_copyright_link'),
297 $this->lng->txt('md_copyright_link_info')
298 )
299 ->withValue((string) $cp_data?->link())
300 ->withAdditionalTransformation(
301 $this->refinery->custom()->transformation(fn($v) => $v instanceof URI ? $v : null)
302 );
303
304 $image_link = $ff
305 ->url($this->lng->txt('md_copyright_image_link'))
306 ->withValue((string) $cp_data?->imageLink())
307 ->withAdditionalTransformation($this->refinery->custom()->transformation(
308 fn($v) => $v instanceof URI ? $v : null
309 ));
310
311 $file_id = empty($cp_data?->imageFile()) ? '' : $cp_data?->imageFile();
312 $image_file = $ff
313 ->file(
315 $this->lng->txt('md_copyright_image_file')
316 )
317 ->withMaxFiles(1)
318 ->withAcceptedMimeTypes([MimeType::IMAGE__PNG, MimeType::IMAGE__JPEG]);
319 if ($file_id !== '') {
320 $image_file = $image_file->withValue([$file_id]);
321 };
322
323 $image_value = 'link_group';
324 if (!is_null($cp_data) && !$cp_data->isImageLink()) {
325 $image_value = 'file_group';
326 }
327 $image = $ff
328 ->switchableGroup(
329 [
330 'link_group' => $ff->group(
331 ['image_link' => $image_link],
332 $this->lng->txt('md_copyright_image_is_link')
333 ),
334 'file_group' => $ff->group(
335 ['image_file' => $image_file],
336 $this->lng->txt('md_copyright_image_is_file')
337 ),
338 ],
339 $this->lng->txt('md_copyright_image')
340 )
341 ->withValue($image_value);
342
343 $alt_text = $ff
344 ->text(
345 $this->lng->txt('md_copyright_alt_text'),
346 $this->lng->txt('md_copyright_alt_text_info')
347 )
348 ->withValue($cp_data?->altText() ?? '');
349
350 $cop = $ff
351 ->section(
352 [
353 'full_name' => $full_name,
354 'link' => $link,
355 'image' => $image,
356 'alt_text' => $alt_text
357 ],
358 $this->lng->txt('md_copyright_value')
359 );
360 $inputs['copyright'] = $cop;
361
362 if (!isset($entry)) {
363 $title = $this->lng->txt('md_copyright_add');
364 $post_url = $this->ctrl->getLinkTarget($this, 'saveEntry');
365 } else {
366 $title = $this->lng->txt('md_copyright_edit');
367 $this->ctrl->setParameter($this, 'entry_id', $entry->id());
368 $post_url = $this->ctrl->getLinkTarget($this, 'updateEntry');
369 $this->ctrl->clearParameters($this);
370 }
371
372 $modal = $this->ui_factory->modal()->roundtrip(
373 $title,
374 null,
375 $inputs,
376 $post_url
377 );
378 if ($open_on_load) {
379 $modal = $modal->withOnLoad($modal->getShowSignal());
380 }
381 return $modal;
382 }
link(string $caption, string $href, bool $new_viewport=false)

◆ initEntryIdFromPost()

ilMDCopyrightConfigurationGUI::initEntryIdFromPost ( )
protected

Definition at line 458 of file class.ilMDCopyrightConfigurationGUI.php.

458 : array
459 {
460 $entries = [];
461 if ($this->http->wrapper()->post()->has('entry_id')) {
462 return $this->http->wrapper()->post()->retrieve(
463 'entry_id',
464 $this->refinery->kindlyTo()->listOf(
465 $this->refinery->kindlyTo()->int()
466 )
467 );
468 }
469 return [];
470 }

References ILIAS\FileDelivery\http(), and ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ initEntryIdFromQuery()

ilMDCopyrightConfigurationGUI::initEntryIdFromQuery ( )
protected

Definition at line 446 of file class.ilMDCopyrightConfigurationGUI.php.

446 : int
447 {
448 $entry_id = 0;
449 if ($this->http->wrapper()->query()->has('entry_id')) {
450 $entry_id = $this->http->wrapper()->query()->retrieve(
451 'entry_id',
452 $this->refinery->kindlyTo()->int()
453 );
454 }
455 return $entry_id;
456 }

References ILIAS\FileDelivery\http(), and ILIAS\Repository\refinery().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveCopyrightPosition()

ilMDCopyrightConfigurationGUI::saveCopyrightPosition ( )

Definition at line 384 of file class.ilMDCopyrightConfigurationGUI.php.

384 : bool
385 {
386 if (!$this->http->wrapper()->post()->has('order')) {
387 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_select_one'), true);
388 $this->ctrl->redirect($this, 'showCopyrightSelection');
389 return false;
390 }
391 $positions = $this->http->wrapper()->post()->retrieve(
392 'order',
393 $this->refinery->kindlyTo()->dictOf(
394 $this->refinery->kindlyTo()->string()
395 )
396 );
397 asort($positions);
398 $ids = [];
399 foreach ($positions as $entry_id => $position_ignored) {
400 $ids[] = (int) $entry_id;
401 }
402 $this->repository->reorderEntries(...$ids);
403 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'));
404 $this->ctrl->redirect($this, 'showCopyrightSelection');
405 return false;
406 }

References ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), ILIAS\Repository\int(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and ILIAS\UI\examples\Deck\repository().

+ Here is the call graph for this function:

◆ saveEntry()

ilMDCopyrightConfigurationGUI::saveEntry ( )

Definition at line 170 of file class.ilMDCopyrightConfigurationGUI.php.

170 : void
171 {
172 $modal = $this
173 ->initCopyrightEditModal(null, true)
174 ->withRequest($this->http->request());
175
176 if ($data = $modal->getData()) {
177 $this->repository->createEntry(
178 $data['title'],
179 $data['description'],
180 (bool) $data['outdated'],
181 $data['copyright']['full_name'],
182 $data['copyright']['link'],
183 $this->extractImageFromData($data),
184 $data['copyright']['alt_text']
185 );
186 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
187
188 $this->ctrl->redirect($this, 'showCopyrightSelection');
189 }
190 $this->showCopyrightSelection(0, $modal);
191 }

References $data, ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), and ILIAS\UI\examples\Deck\repository().

+ Here is the call graph for this function:

◆ showCopyrightSelection()

ilMDCopyrightConfigurationGUI::showCopyrightSelection ( int  $current_id = 0,
?RoundTrip  $current_modal = null 
)

Definition at line 122 of file class.ilMDCopyrightConfigurationGUI.php.

125 : void {
126 $has_write = $this->access_service->hasCurrentUserWriteAccess();
127
128 $table_gui = new ilMDCopyrightTableGUI(
129 $this->repository,
130 $this->renderer,
131 $this,
132 'showCopyrightSelection',
133 $has_write
134 );
135 $table_gui->setTitle($this->lng->txt("md_copyright_selection"));
136 $table_gui->parseSelections();
137
138 $edit_modals = [];
139 if ($has_write) {
140 foreach ($this->repository->getAllEntries() as $entry) {
141 if ($entry->id() === $current_id) {
142 $modal = $current_modal;
143 } else {
144 $modal = $this->initCopyrightEditModal($entry);
145 }
146 $table_gui->setEditModalSignal($entry->id(), $modal->getShowSignal());
147 $edit_modals[] = $modal;
148 }
149 if ($current_id === 0 && !is_null($current_modal)) {
150 $add_modal = $current_modal;
151 } else {
152 $add_modal = $this->initCopyrightEditModal();
153 }
154 $this->toolbar_gui->addComponent($this->ui_factory->button()->standard(
155 $this->lng->txt('md_copyright_add'),
156 $add_modal->getShowSignal()
157 ));
158
159 $table_gui->addMultiCommand("confirmDeleteEntries", $this->lng->txt("delete"));
160 $table_gui->setSelectAllCheckbox("entry_id");
161 }
162
163 $this->tpl->setContent(
164 $table_gui->getHTML() .
165 (isset($add_modal) ? $this->ui_renderer->render($add_modal) : '') .
166 $this->ui_renderer->render($edit_modals)
167 );
168 }
initCopyrightEditModal(?EntryInterface $entry=null, bool $open_on_load=false)

◆ updateEntry()

ilMDCopyrightConfigurationGUI::updateEntry ( )

Definition at line 236 of file class.ilMDCopyrightConfigurationGUI.php.

236 : void
237 {
238 $entry = $this->repository->getEntry($this->initEntryIdFromQuery());
239 $modal = $this
240 ->initCopyrightEditModal($entry, true)
241 ->withRequest($this->http->request());
242
243 if ($data = $modal->getData()) {
244 $this->deleteFileIfChanged($entry, $data);
245 $this->repository->updateEntry(
246 $entry->id(),
247 $data['title'],
248 $data['description'],
249 (bool) $data['outdated'],
250 $data['copyright']['full_name'],
251 $data['copyright']['link'],
252 $this->extractImageFromData($data),
253 $data['copyright']['alt_text']
254 );
255 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
256
257 $this->ctrl->redirect($this, 'showCopyrightSelection');
258 }
259 $this->showCopyrightSelection($entry->id(), $modal);
260 }
deleteFileIfChanged(EntryInterface $entry, array $data)

References $data, ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), and ILIAS\UI\examples\Deck\repository().

+ Here is the call graph for this function:

Field Documentation

◆ $access_service

ilMDSettingsAccessService ilMDCopyrightConfigurationGUI::$access_service
protected

Definition at line 52 of file class.ilMDCopyrightConfigurationGUI.php.

◆ $ctrl

ilCtrl ilMDCopyrightConfigurationGUI::$ctrl
protected

Definition at line 41 of file class.ilMDCopyrightConfigurationGUI.php.

◆ $http

GlobalHttpState ilMDCopyrightConfigurationGUI::$http
protected

Definition at line 45 of file class.ilMDCopyrightConfigurationGUI.php.

◆ $irss

IRSS ilMDCopyrightConfigurationGUI::$irss
protected

Definition at line 49 of file class.ilMDCopyrightConfigurationGUI.php.

◆ $lng

ilLanguage ilMDCopyrightConfigurationGUI::$lng
protected

Definition at line 43 of file class.ilMDCopyrightConfigurationGUI.php.

◆ $parent_obj_gui

ilObjMDSettingsGUI ilMDCopyrightConfigurationGUI::$parent_obj_gui
protected

Definition at line 51 of file class.ilMDCopyrightConfigurationGUI.php.

Referenced by __construct().

◆ $refinery

Factory ilMDCopyrightConfigurationGUI::$refinery
protected

Definition at line 46 of file class.ilMDCopyrightConfigurationGUI.php.

◆ $renderer

RendererInterface ilMDCopyrightConfigurationGUI::$renderer
protected

Definition at line 53 of file class.ilMDCopyrightConfigurationGUI.php.

◆ $repository

RepositoryInterface ilMDCopyrightConfigurationGUI::$repository
protected

Definition at line 54 of file class.ilMDCopyrightConfigurationGUI.php.

◆ $toolbar_gui

ilToolbarGUI ilMDCopyrightConfigurationGUI::$toolbar_gui
protected

Definition at line 44 of file class.ilMDCopyrightConfigurationGUI.php.

◆ $tpl

ilGlobalTemplateInterface ilMDCopyrightConfigurationGUI::$tpl
protected

Definition at line 42 of file class.ilMDCopyrightConfigurationGUI.php.

◆ $ui_factory

UIFactory ilMDCopyrightConfigurationGUI::$ui_factory
protected

Definition at line 47 of file class.ilMDCopyrightConfigurationGUI.php.

◆ $ui_renderer

UIRenderer ilMDCopyrightConfigurationGUI::$ui_renderer
protected

Definition at line 48 of file class.ilMDCopyrightConfigurationGUI.php.


The documentation for this class was generated from the following file: