Neues Modul Glossar (0.27.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 6m52s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 6m46s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m6s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 7m2s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m29s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 6m31s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 5m54s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m58s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m17s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 6m52s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 6m46s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m6s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 7m2s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m29s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 6m31s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 5m54s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m58s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m17s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
d148f2fbe2
commit
0bd20a527e
121 changed files with 946 additions and 298 deletions
18
plugins-core/glossar/src/GlossarPlugin.php
Normal file
18
plugins-core/glossar/src/GlossarPlugin.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Glossar;
|
||||
|
||||
use App\Plugins\Plugin;
|
||||
use App\Search\GlobalSearch;
|
||||
use App\Support\Abilities;
|
||||
use App\Support\Navigation;
|
||||
|
||||
class GlossarPlugin extends Plugin
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->make(Navigation::class)->add('glossar', 'Glossar', '/glossar', active: 'glossary.*', sort: 75);
|
||||
$this->app->make(Abilities::class)->define('glossary.manage', 'Glossar pflegen', 'Glossar', portal: true);
|
||||
$this->app->make(GlobalSearch::class)->add('glossar', 'Glossar', 'book-open', fn (...$args) => app(GlossarySearch::class)(...$args), sort: 45);
|
||||
}
|
||||
}
|
||||
27
plugins-core/glossar/src/GlossarySearch.php
Normal file
27
plugins-core/glossar/src/GlossarySearch.php
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Glossar;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Search\GlobalSearch;
|
||||
use Inhaus\Plugins\Glossar\Models\GlossaryEntry;
|
||||
|
||||
/** Suchquelle für die globale Suche */
|
||||
class GlossarySearch
|
||||
{
|
||||
/**
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function __invoke(User $user, string $search, int $limit): array
|
||||
{
|
||||
$query = GlossaryEntry::query();
|
||||
GlobalSearch::whereTerms($query, ['term', 'aliases', 'description'], $search);
|
||||
|
||||
return $query->orderBy('sort_key')->limit($limit)->get()->map(fn (GlossaryEntry $entry) => [
|
||||
'title' => $entry->term.($entry->aliases ? ' ('.$entry->aliases.')' : ''),
|
||||
'url' => '/glossar#'.$entry->anchor(),
|
||||
'excerpt' => GlobalSearch::excerpt(strip_tags((string) $entry->description), $search),
|
||||
'meta' => 'Glossar',
|
||||
])->all();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Glossar\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Pagebuilder\Field;
|
||||
use App\Support\Audit;
|
||||
use App\Support\RichText;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Inhaus\Plugins\Glossar\Models\GlossaryEntry;
|
||||
|
||||
class GlossaryController extends Controller
|
||||
{
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
return Inertia::render('glossar::Index', [
|
||||
'entries' => GlossaryEntry::query()->orderBy('sort_key')->orderBy('term')->get()->map->toPortal(),
|
||||
'canManage' => $request->user()->can('glossary.manage'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$this->authorizeManage($request);
|
||||
$entry = GlossaryEntry::query()->create([...$this->validated($request), 'created_by' => $request->user()->id, 'updated_by' => $request->user()->id]);
|
||||
Audit::log('glossary.created', ['entry' => $entry->id, 'term' => $entry->term]);
|
||||
|
||||
return back()->with('status', '„'.$entry->term.'“ ist im Glossar.');
|
||||
}
|
||||
|
||||
public function update(Request $request, GlossaryEntry $entry): RedirectResponse
|
||||
{
|
||||
$this->authorizeManage($request);
|
||||
$entry->update([...$this->validated($request, $entry), 'updated_by' => $request->user()->id]);
|
||||
Audit::log('glossary.updated', ['entry' => $entry->id, 'term' => $entry->term]);
|
||||
|
||||
return back()->with('status', 'Gespeichert.');
|
||||
}
|
||||
|
||||
public function destroy(Request $request, GlossaryEntry $entry): RedirectResponse
|
||||
{
|
||||
$this->authorizeManage($request);
|
||||
$entry->delete();
|
||||
Audit::log('glossary.deleted', ['entry' => $entry->id, 'term' => $entry->term]);
|
||||
|
||||
return back()->with('status', '„'.$entry->term.'“ gelöscht.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function validated(Request $request, ?GlossaryEntry $entry = null): array
|
||||
{
|
||||
$data = $request->validate([
|
||||
'term' => ['required', 'string', 'max:150'],
|
||||
'aliases' => ['nullable', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string', 'max:50000'],
|
||||
'link_url' => ['nullable', 'string', 'max:1000'],
|
||||
'link_label' => ['nullable', 'string', 'max:100'],
|
||||
], [], ['term' => 'Begriff', 'aliases' => 'Abkürzung / Synonyme', 'description' => 'Erklärung', 'link_url' => 'Link']);
|
||||
|
||||
$term = trim($data['term']);
|
||||
$duplicate = GlossaryEntry::query()->where('sort_key', GlossaryEntry::sortKey($term))->when($entry, fn ($q) => $q->whereKeyNot($entry->id))->exists();
|
||||
if ($duplicate) {
|
||||
throw ValidationException::withMessages(['term' => 'Diesen Begriff gibt es schon im Glossar.']);
|
||||
}
|
||||
|
||||
$link = filled($data['link_url'] ?? null) ? Field::safeUrl($data['link_url']) : '';
|
||||
|
||||
return [
|
||||
'term' => $term,
|
||||
'aliases' => filled($data['aliases'] ?? null) ? trim($data['aliases']) : null,
|
||||
'description' => filled($data['description'] ?? null) ? app(RichText::class)->sanitize($data['description']) : null,
|
||||
'link_url' => $link !== '' ? $link : null,
|
||||
'link_label' => $link !== '' && filled($data['link_label'] ?? null) ? trim($data['link_label']) : null,
|
||||
];
|
||||
}
|
||||
|
||||
private function authorizeManage(Request $request): void
|
||||
{
|
||||
abort_unless($request->user()->can('glossary.manage'), 403);
|
||||
}
|
||||
}
|
||||
56
plugins-core/glossar/src/Models/GlossaryEntry.php
Normal file
56
plugins-core/glossar/src/Models/GlossaryEntry.php
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace Inhaus\Plugins\Glossar\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Ein Begriff im Glossar. Buchstabe und Sortierschlüssel entstehen beim Speichern:
|
||||
* Umlaute zählen wie ihr Grundbuchstabe (Ä → A), Ziffern und Zeichen unter „#“.
|
||||
*/
|
||||
#[Fillable(['term', 'aliases', 'description', 'link_url', 'link_label', 'created_by', 'updated_by'])]
|
||||
class GlossaryEntry extends Model
|
||||
{
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saving(function (GlossaryEntry $entry) {
|
||||
$entry->sort_key = self::sortKey($entry->term);
|
||||
$first = strtoupper(substr($entry->sort_key, 0, 1));
|
||||
$entry->letter = $first !== '' && ctype_alpha($first) ? $first : '#';
|
||||
});
|
||||
}
|
||||
|
||||
public static function sortKey(string $term): string
|
||||
{
|
||||
$key = Str::lower(strtr(trim($term), ['Ä' => 'A', 'Ö' => 'O', 'Ü' => 'U', 'ä' => 'a', 'ö' => 'o', 'ü' => 'u', 'ß' => 'ss']));
|
||||
$key = Str::ascii($key);
|
||||
|
||||
// Führende Anführungszeichen o. Ä. nicht mitsortieren
|
||||
return mb_substr(ltrim($key, " \t\"'„“‚‘»«([-–"), 0, 190);
|
||||
}
|
||||
|
||||
/** Anker für Direktlinks, z. B. /glossar#begriff-12 */
|
||||
public function anchor(): string
|
||||
{
|
||||
return 'begriff-'.$this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toPortal(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'term' => $this->term,
|
||||
'aliases' => $this->aliases,
|
||||
'description' => $this->description,
|
||||
'link_url' => $this->link_url,
|
||||
'link_label' => $this->link_label,
|
||||
'letter' => $this->letter,
|
||||
'anchor' => $this->anchor(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue