All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m38s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m31s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m39s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m54s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 3m50s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 3m55s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 3m18s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 3m19s
CI / Build-Artefakte aktuell (pull_request) Successful in 55s
Der Name „Dokumente“ bleibt dem kommenden QM-Modul (QM-Dokumente und -Formulare) vorbehalten. - Plugin plugins-core/downloads (Inhaus\Plugins\Downloads), Adresse /downloads, Rechte downloads.*, Objekttyp download_folder, Block downloads.folder, Kachel downloads.favorites - Migration für bestehende Installationen: Tabellen und Spalten, Rechte, Sichtbarkeiten, Menü, Startseiten-Anordnung, Blöcke in Seiten und Fassungen, Plugin-Zustand; mit Test - Alte Links unter /dokumente leiten dauerhaft weiter Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
42 lines
1.8 KiB
PHP
42 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Inhaus\Plugins\Downloads;
|
|
|
|
use Inhaus\Plugins\Downloads\Models\Download;
|
|
|
|
final class DownloadPresenter
|
|
{
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
/** Dateitypen, die für Vorschaubilder im Browser ausgeliefert werden (kein SVG/HTML). */
|
|
public const PREVIEW_MIMES = ['application/pdf', 'image/jpeg', 'image/png', 'image/gif', 'image/webp'];
|
|
|
|
/** Größere PDFs lädt die Kachelansicht nicht für ein Vorschaubild. */
|
|
public const PREVIEW_MAX_BYTES = 8 * 1024 * 1024;
|
|
|
|
public static function row(Download $download, ?string $folderName = null, bool $favorite = false): array
|
|
{
|
|
$version = $download->currentVersion;
|
|
$previewable = $version && in_array($version->mime, self::PREVIEW_MIMES, true) && $version->size <= self::PREVIEW_MAX_BYTES;
|
|
|
|
return [
|
|
'id' => $download->id,
|
|
'title' => $download->title,
|
|
'description' => $download->description,
|
|
'folder_id' => $download->folder_id,
|
|
'folder_name' => $folderName,
|
|
'version' => $version?->version,
|
|
'name' => $version?->name,
|
|
'extension' => $version?->extension(),
|
|
'size' => (int) ($version?->size ?? 0),
|
|
'updated_by' => $version?->relationLoaded('uploader') ? $version->uploader?->name : null,
|
|
'updated_at' => ($version?->created_at ?? $download->updated_at)?->toIso8601String(),
|
|
'download_url' => $version ? $download->downloadUrl($version) : null,
|
|
'preview_url' => $previewable ? $download->downloadUrl($version).'?vorschau=1' : null,
|
|
'preview_kind' => $previewable ? ($version->mime === 'application/pdf' ? 'pdf' : 'image') : null,
|
|
'favorite' => $favorite,
|
|
'download_count' => (int) $download->download_count,
|
|
];
|
|
}
|
|
}
|