Skip to content

Commit

Permalink
fix: download the items according to their usages.
Browse files Browse the repository at this point in the history
  • Loading branch information
ferishili committed Oct 5, 2023
1 parent 9defb2c commit 113628c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
24 changes: 22 additions & 2 deletions classes/Event/class.xoctEventGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -895,16 +895,36 @@ public function download(): void
{
$event_id = filter_input(INPUT_GET, 'event_id', FILTER_SANITIZE_STRING);
$publication_id = filter_input(INPUT_GET, 'pub_id', FILTER_SANITIZE_STRING);
$usage_type = filter_input(INPUT_GET, 'usage_type', FILTER_SANITIZE_STRING);
$usage_id = filter_input(INPUT_GET, 'usage_id', FILTER_SANITIZE_STRING);
$event = $this->event_repository->find($event_id);
$download_publications = $event->publications()->getDownloadPublications();
// Now that we have multiple sub-usages, we first check for publication_id which is passed by the multi-dropdowns.
if ($publication_id) {
$publication = array_filter($download_publications, function ($publication) use ($publication_id): bool {
return $publication->getId() === $publication_id;
});
$publication = array_shift($publication);
$publication = reset($publication);
} else {
$publication = array_shift($download_publications);
// If this is not multi-download dropdown, then it has to have the usage_type and usage_id parameters identified.
if (!empty($usage_type) && !empty($usage_id)) {
$publication = array_filter($download_publications,
function ($publication) use ($usage_type, $usage_id): bool {
return $publication->usage_id == $usage_id && $publication->usage_type === $usage_type;
}
);
$publication = reset($publication);
} else {
// As a fallback we take out the last publication, if non of the above has been met!
$publication = reset($download_publications);
}
}

if (empty($publication)) {
ilUtil::sendFailure($this->txt('msg_no_download_publication'), true);
$this->ctrl->redirect($this, self::CMD_STANDARD);
}

$url = $publication->getUrl();
$extension = pathinfo($url)['extension'];
$url = PluginConfig::getConfig(PluginConfig::F_SIGN_DOWNLOAD_LINKS) ? xoctSecureLink::signDownload($url) : $url;
Expand Down
16 changes: 14 additions & 2 deletions classes/Event/class.xoctEventRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,18 @@ public function getDownloadLinkHTML(
if (!$show_download) {
return '';
}

// Setting event_id is necessary, because we use it for both multi approach with pub_id or subusage approach with usage_type and usage_id.
$this->ctrl->setParameterByClass(xoctEventGUI::class, 'event_id', $this->event->getIdentifier());

// Setting the floowing parameters to null first, so that we get accurate parameters later on in download action.
$this->ctrl->setParameterByClass(xoctEventGUI::class, 'pub_id', null);
$this->ctrl->setParameterByClass(xoctEventGUI::class, 'usage_type', null);
$this->ctrl->setParameterByClass(xoctEventGUI::class, 'usage_id', null);

$multi = $download_publication_usage->isAllowMultiple();
if ($multi) {
$items = array_map(function ($dto): \ILIAS\UI\Component\Link\Standard {
$this->ctrl->setParameterByClass(xoctEventGUI::class, 'event_id', $this->event->getIdentifier());
$this->ctrl->setParameterByClass(xoctEventGUI::class, 'pub_id', $dto->getPublicationId());
return $this->factory->link()->standard(
$dto->getResolution(),
Expand All @@ -389,7 +397,11 @@ public function getDownloadLinkHTML(
)->withLabel($display_name);
$html = $this->renderer->renderAsync($dropdown);
} else {
$this->ctrl->setParameterByClass(xoctEventGUI::class, 'event_id', $this->event->getIdentifier());
$usage_type = $download_publication_usage->is_sub ? 'sub' : 'org';
$this->ctrl->setParameterByClass(xoctEventGUI::class, 'usage_type', $usage_type);
$usage_id = $usage_type === 'sub' ? $download_publication_usage->sub_id :
$download_publication_usage->getUsageId();
$this->ctrl->setParameterByClass(xoctEventGUI::class, 'usage_id', $usage_id);
$link = $this->ctrl->getLinkTargetByClass(xoctEventGUI::class, xoctEventGUI::CMD_DOWNLOAD);
$link_tpl = $this->plugin->getTemplate('default/tpl.player_link.html');
$link_tpl->setVariable('TARGET', '_self');
Expand Down
1 change: 1 addition & 0 deletions lang/ilias_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ event_msg_deleted#:#Aufzeichnung gelöscht
event_msg_unpublish_started#:#Die Publikationen werden nun entfernt.
event_msg_currently_unpublishing#:#Der Prozess zum Entfernen der Publikationen läuft bereits.
event_msg_no_access#:#kein Zugriff
event_msg_no_download_publication#:#Die Download-Publikation konnte nicht gefunden werden.
event_msg_success#:#Änderungen gespeichert
event_msg_scheduled#:#Aufzeichnungstermin(e) erstellt.
event_msg_scheduling_conflict#:#Termin(e) konnte(n) nicht erstellt werden, da es Überschneidungen mit existierenden Terminen gibt:
Expand Down
1 change: 1 addition & 0 deletions lang/ilias_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ event_msg_deleted#:#Event deleted
event_msg_unpublish_started#:#The publications are now being removed.
event_msg_currently_unpublishing#:#The process to remove the publications is already running.
event_msg_no_access#:#No Access
event_msg_no_download_publication#:#The download publication could not be found.
event_msg_success#:#Saved changes
event_msg_scheduled#:#Event(s) scheduled
event_msg_scheduling_conflict#:#Event(s) could not be scheduled, due to an overlap with existing events:
Expand Down

0 comments on commit 113628c

Please sign in to comment.