Skip to content

Commit

Permalink
Calendar: handle multiple files with same name better (40847)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmitz-ilias committed Mar 19, 2024
1 parent 3f3ecc2 commit 960a73a
Showing 1 changed file with 40 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

use ILIAS\UI\Component\Link\Standard as StandardLink;

/**
* @author Jesús López Reyes <[email protected]>
* @ilCtrl_IsCalledBy ilAppointmentPresentationSessionGUI: ilCalendarAppointmentPresentationGUI
Expand All @@ -11,10 +29,8 @@ class ilAppointmentPresentationSessionGUI extends ilAppointmentPresentationGUI i
{
public function collectPropertiesAndActions(): void
{
global $DIC;

$f = $DIC->ui()->factory();
$r = $DIC->ui()->renderer();
$f = $this->ui->factory();
$r = $this->ui->renderer();
$this->lng->loadLanguageModule("sess");
$this->lng->loadLanguageModule("crs");

Expand Down Expand Up @@ -76,7 +92,7 @@ public function collectPropertiesAndActions(): void

$eventItems = ilObjectActivation::getItemsByEvent($this->getObjIdForAppointment());
if (count($eventItems)) {
$str = array();
$links = [];
foreach ($eventItems as $file) {
if ($file['type'] == "file") {
$this->has_files = true;
Expand All @@ -85,13 +101,13 @@ public function collectPropertiesAndActions(): void
if (ilObjFileAccess::_isFileInline($file["title"])) {
$link = $link->withOpenInNewViewport(true);
}
$str[$file['title']] = $r->render($link);
$links[] = $link;
}
}
if ($this->has_files) {
ksort($str, SORT_NATURAL | SORT_FLAG_CASE);
$this->addInfoProperty($this->lng->txt("files"), implode("<br>", $str));
$this->addListItemProperty($this->lng->txt("files"), implode(", ", $str));
$rendered = $this->sortAndRenderLinks(...$links);
$this->addInfoProperty($this->lng->txt("files"), implode("<br>", $rendered));
$this->addListItemProperty($this->lng->txt("files"), implode(", ", $rendered));
}
}

Expand Down Expand Up @@ -120,8 +136,6 @@ public function collectPropertiesAndActions(): void
*/
protected function getOtherMaterials(): array
{
global $DIC;

$event_items = new ilEventItems($this->getObjIdForAppointment());
$others = [];
foreach ($event_items->getItems() as $ref_id) {
Expand All @@ -135,4 +149,19 @@ protected function getOtherMaterials(): array
}
return $others;
}

/**
* @return string[]
*/
protected function sortAndRenderLinks(StandardLink ...$links): array
{
usort($links, function (StandardLink $a, $b) {
return $a->getLabel() <=> $b->getLabel();
});
$rendered = [];
foreach ($links as $link) {
$rendered[] = $this->ui->renderer()->render($link);
}
return $rendered;
}
}

0 comments on commit 960a73a

Please sign in to comment.