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

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-27 09:52:00 +00:00
parent d148f2fbe2
commit 0bd20a527e
121 changed files with 946 additions and 298 deletions

View 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(),
];
}
}