All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Has been skipped
CI / PHP 8.4 / mariadb:10.6 (pull_request) Has been skipped
CI / PHP 8.3 / mariadb:11.4 (pull_request) Has been skipped
CI / PHP 8.4 / mariadb:11.4 (pull_request) Has been skipped
CI / PHP 8.3 / mysql:8.0 (pull_request) Has been skipped
CI / PHP 8.4 / mysql:8.0 (pull_request) Has been skipped
CI / PHP 8.3 / mysql:8.4 (pull_request) Has been skipped
CI / PHP 8.4 / mysql:8.4 (pull_request) Has been skipped
CI / Browser-Tests (pull_request) Successful in 8m33s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 9m8s
CI / PHP 8.3 / mysql:8.4-1 (pull_request) Successful in 17m55s
CI / Build-Artefakte aktuell (pull_request) Successful in 9m50s
- Wissensquellen: Termine, Downloads, Formulare, Stellen, Ideen, Umfragen, Personen, eigene IT-Tickets/Geräte (OpenNIT, je Anfrage zwischengespeichert) - Ranking mit IDF, Abfrage je Begriff, Abkürzungen als ganze Wörter, LIKE unabhängig von Groß-/Kleinschreibung (JSON-Spalten), Datum im Prompt - Demo-Inhalte für einen Träger der Eingliederungshilfe (DemoData), mehrseitige PDFs, vorhandene Inhalte je Bereich entfernen Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
83 lines
4.1 KiB
PHP
83 lines
4.1 KiB
PHP
<?php
|
||
|
||
namespace Inhaus\Plugins\Downloads;
|
||
|
||
use App\Ask\Knowledge;
|
||
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\Search\GlobalSearch;
|
||
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->make(Knowledge::class)->add('downloads', 'Downloads', fn (...$args) => app(DownloadKnowledge::class)(...$args));
|
||
$this->app->make(GlobalSearch::class)->add('downloads', 'Downloads', 'folder-down', fn (...$args) => app(DownloadSearch::class)(...$args), sort: 40);
|
||
|
||
$this->app->singleton(FolderTree::class);
|
||
|
||
$this->app->make(Navigation::class)->add('downloads', 'Downloads', '/downloads', active: 'downloads.*', sort: 50, icon: 'folder-down');
|
||
|
||
$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', portal: true);
|
||
$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(),
|
||
];
|
||
}));
|
||
}
|
||
}
|