„Dokumente“ heißt jetzt „Downloads“
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>
This commit is contained in:
Friederich Loheide 2026-09-26 15:03:32 +00:00
parent c71131d054
commit f78cc96be7
120 changed files with 1091 additions and 866 deletions

View file

@ -0,0 +1,78 @@
<?php
namespace Inhaus\Plugins\Downloads;
use App\Dashboard\Widgets;
use App\Models\User;
use App\Pagebuilder\Blocks;
use App\Pagebuilder\BlockType;
use App\Pagebuilder\Field;
use App\Plugins\Plugin;
use App\Support\Abilities;
use App\Support\Navigation;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Gate;
use Inhaus\Plugins\Downloads\Models\Download;
use Inhaus\Plugins\Downloads\Models\DownloadFolder;
use Inhaus\Plugins\Downloads\Policies\DownloadFolderPolicy;
class DownloadsPlugin extends Plugin
{
public function register(): void
{
$this->app->singleton(FolderTree::class);
$this->app->make(Navigation::class)->add('downloads', 'Downloads', '/downloads', active: 'downloads.*', sort: 50);
$abilities = $this->app->make(Abilities::class);
$abilities->define('downloads.manage', 'Downloads: gesamten Bereich verwalten', 'Downloads');
$abilities->define('downloads.edit', 'Downloads pflegen', 'Downloads', resource: 'download_folder');
$abilities->resourceType(
'download_folder',
'Download-Ordner',
fn () => $this->app->make(FolderTree::class)->options(),
fn (array $ids) => $this->app->make(FolderTree::class)->descendantIds($ids),
);
Gate::policy(DownloadFolder::class, DownloadFolderPolicy::class);
// Startseite: gemerkte Dateien – ohne Favoriten die meistgenutzten.
$this->app->make(Widgets::class)->add('downloads.favorites', 'downloads::MyDownloads', 'aside', sort: 25, props: function (User $user) {
$visible = $this->app->make(FolderTree::class)->visibleIds($user) ?: [0];
$favorites = Download::query()->whereIn('folder_id', $visible)
->whereIn('id', DB::table('download_favorites')->where('user_id', $user->id)->select('download_id'))
->with('currentVersion')->orderBy('title')->limit(6)->get();
$popular = $favorites->isEmpty()
? Download::query()->whereIn('folder_id', $visible)->where('download_count', '>', 0)->with('currentVersion')->orderByDesc('download_count')->limit(5)->get()
: collect();
return [
'favorites' => $favorites->map(fn (Download $d) => DownloadPresenter::row($d, null, true))->all(),
'popular' => $popular->map(fn (Download $d) => DownloadPresenter::row($d))->all(),
];
}, label: 'Meine Downloads');
$this->app->make(Blocks::class)->add(BlockType::make('downloads.folder', 'Downloads', 'file-down', 'dynamic', 'downloads::FolderBlock')
->description('Die Dateien eines Download-Ordners – immer in der aktuellen Fassung.')
->fields([
Field::text('title', 'Überschrift', 150),
Field::select('folder', 'Ordner', fn () => collect($this->app->make(FolderTree::class)->options())->mapWithKeys(fn ($name, $id) => [(string) $id => $name])->all()),
Field::toggle('show_description', 'Beschreibungen anzeigen', true),
])
->resolveUsing(function (array $data, ?User $user) {
$tree = $this->app->make(FolderTree::class);
$folderId = (int) $data['folder'];
if (! $folderId || ! $tree->isVisible($folderId, $user)) {
return null;
}
$downloads = Download::query()->where('folder_id', $folderId)->with('currentVersion')->orderBy('title')->limit(100)->get();
return [
'folder_url' => route('downloads.folder', $folderId),
'downloads' => $downloads->map(fn (Download $d) => DownloadPresenter::row($d))->all(),
];
}));
}
}