ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
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 190 of file class.ilMDCopyrightConfigurationGUI.php.

190 : void
191 {
192 $entry_ids = $this->initEntryIdFromPost();
193 if (!count($entry_ids)) {
194 $this->tpl->setOnScreenMessage('info', $this->lng->txt('select_one'));
195 $this->showCopyrightSelection();
196 return;
197 }
198
199 $c_gui = new ilConfirmationGUI();
200 // set confirm/cancel commands
201 $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteEntries"));
202 $c_gui->setHeaderText($this->lng->txt("md_delete_cp_sure"));
203 $c_gui->setCancel($this->lng->txt("cancel"), "showCopyrightSelection");
204 $c_gui->setConfirm($this->lng->txt("confirm"), "deleteEntries");
205
206 // add items to delete
207 foreach ($entry_ids as $entry_id) {
208 $entry = $this->repository->getEntry($entry_id);
209 $c_gui->addItem('entry_id[]', (string) $entry_id, $entry->title());
210 }
211 $this->tpl->setContent($c_gui->getHTML());
212 }
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 214 of file class.ilMDCopyrightConfigurationGUI.php.

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

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 405 of file class.ilMDCopyrightConfigurationGUI.php.

405 : void
406 {
407 if (($image_file = $entry->copyrightData()->imageFile()) === '') {
408 return;
409 }
410 if ($id = $this->irss->manage()->find($image_file)) {
411 $this->irss->manage()->remove($id, new ilMDCopyrightImageStakeholder());
412 }
413 }
$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 415 of file class.ilMDCopyrightConfigurationGUI.php.

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

◆ 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 (!$this->access_service->hasCurrentUserReadAccess()) {
90 throw new ilPermissionException($this->lng->txt('no_permission'));
91 }
92
93 switch ($next_class) {
94 case strtolower(ilMDCopyrightUsageGUI::class):
95 // this command is used if copyrightUsageGUI calls getParentReturn (see ...UsageGUI->setTabs)
96 $this->ctrl->setReturn($this, 'showCopyrightSelection');
97 $entry = $this->repository->getEntry($this->initEntryIdFromQuery());
98 $gui = new ilMDCopyrightUsageGUI($entry);
99 $this->ctrl->forwardCommand($gui);
100 break;
101
102 case strtolower(ilMDCopyrightImageUploadHandlerGUI::class):
103 $entry = $this->repository->getEntry($this->initEntryIdFromQuery());
104 $file_id = empty($entry?->copyrightData()?->imageFile()) ? '' : $entry?->copyrightData()?->imageFile();
106 $this->ctrl->forwardCommand($handler);
107
108 // no break
109 default:
110 if (!$cmd || $cmd === 'view') {
111 $cmd = 'showCopyrightSelection';
112 }
113
114 $this->$cmd();
115 break;
116 }
117 }
$handler
Definition: oai.php:31

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 431 of file class.ilMDCopyrightConfigurationGUI.php.

431 : string|URI
432 {
433 $v = $data['copyright']['image'];
434 if ($v[0] === 'link_group') {
435 return empty($link = $v[1]['image_link']) ? '' : $link;
436 }
437 if ($v[0] === 'file_group') {
438 return $v[1]['image_file'][0] ?? '';
439 }
440 return '';
441 }
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 259 of file class.ilMDCopyrightConfigurationGUI.php.

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

◆ initEntryIdFromPost()

ilMDCopyrightConfigurationGUI::initEntryIdFromPost ( )
protected

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

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

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

+ Here is the call graph for this function:

◆ initEntryIdFromQuery()

ilMDCopyrightConfigurationGUI::initEntryIdFromQuery ( )
protected

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

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

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 381 of file class.ilMDCopyrightConfigurationGUI.php.

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

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 167 of file class.ilMDCopyrightConfigurationGUI.php.

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

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 119 of file class.ilMDCopyrightConfigurationGUI.php.

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

◆ updateEntry()

ilMDCopyrightConfigurationGUI::updateEntry ( )

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

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