Files
laraundfelix/app/Domain/Catalog/EditorialContentKind.php
T
LarsandClaude Sonnet 5.5 0ac70884cc
CI Feature / test (push) Successful in 5m10s
Deploy Test / test (push) In progress
Zeige auf der Shopkachel Titelbild, Saeulen, Materialart mit Symbol und Marker
- ShopCatalog als gemeinsame Datenquelle der Kacheln, shop/kachel als Partial
- Titelbild nur mit Website-Freigabe (PresentationMedia::coverPresentation), schmueckend mit leerem alt
- Symbol je Materialart (Stammdaten), Marker Neu, Aktualisiert, Beliebt mit Einstellung am Artikel
- Migration 2026_12_01_100000, rein ergaenzend
- ADR-54, Plan, DEPLOYMENT.md

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-26 07:44:47 +01:00

110 lines
3.4 KiB
PHP

<?php
namespace App\Domain\Catalog;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* Fachliche Materialart (FACH-56 bis FACH-58). Die Bezeichnung ist pflegbar, die Kennung (slug) bleibt nach dem Anlegen
* fest. Zulässige Objektkontexte bestimmen, wo eine Materialart neu gewählt werden kann; vorhandene Zuordnungen bleiben
* immer erhalten (siehe EditorialVocabulary).
*/
class EditorialContentKind extends Model
{
/** Objektkontexte aus dem Fachmodell: Medium (ContentElement), Modul und Programm (Composition), Lizenzartikel. */
public const CONTEXTS = [
'medium' => 'Medium',
'modul' => 'Modul',
'uebung' => 'Übung',
'dokument' => 'Dokument',
'programm' => 'Programm',
'lizenzartikel' => 'Lizenzartikel',
];
/**
* Kennungen, auf die der Code fachlich verweist: öffentliche Programmseiten und das Anlegen von Programmen und
* Modulen (programm, modul), Vertraulichkeit von Traineranleitungen (traineranleitung). Ihre Bezeichnung bleibt
* pflegbar; deaktivieren, Kontexte ändern und löschen sind gesperrt.
*/
public const SYSTEM_SLUGS = ['programm', 'modul', 'uebung', 'dokument', 'traineranleitung', self::EXERCISE_SECTION_SLUG, self::DOCUMENT_CHAPTER_SLUG];
/**
* Textabschnitte einer Übung. Die Materialart wird nur automatisch gesetzt (ExerciseSections) und hat deshalb
* keinen wählbaren Kontext.
*/
public const EXERCISE_SECTION_SLUG = 'uebungsabschnitt';
/** Kapitel eines Dokuments: wie Übungsabschnitte nur automatisch gesetzt, nie öffentlich (ADR-51). */
public const DOCUMENT_CHAPTER_SLUG = 'dokumentkapitel';
protected $fillable = [
'slug',
'label',
'symbol',
'sort_order',
'is_active',
'contexts',
];
protected function casts(): array
{
return [
'is_active' => 'boolean',
'contexts' => 'array',
'sort_order' => 'integer',
];
}
public function compositions(): HasMany
{
return $this->hasMany(Composition::class);
}
public function contentElements(): HasMany
{
return $this->hasMany(ContentElement::class);
}
public function licenseArticles(): HasMany
{
return $this->hasMany(LicenseArticle::class);
}
/**
* @param Builder<EditorialContentKind> $query
*/
public function scopeActive(Builder $query): void
{
$query->where('is_active', true);
}
public function allows(string $context): bool
{
return in_array($context, (array) ($this->contexts ?? []), true);
}
/** Wird nie von Hand gewählt, sondern von der Übungsverwaltung gesetzt. */
public function isAutomatic(): bool
{
return in_array($this->slug, [self::EXERCISE_SECTION_SLUG, self::DOCUMENT_CHAPTER_SLUG], true);
}
public function isSystem(): bool
{
return in_array($this->slug, self::SYSTEM_SLUGS, true);
}
/**
* Alle Materialarten in Pflegereihenfolge (ohne Kontext- oder Aktivfilter). Für Auswahlstellen gilt
* EditorialVocabulary.
*
* @return array<int, string>
*/
public static function selectOptions(): array
{
return static::query()->orderBy('sort_order')->orderBy('id')->pluck('label', 'id')->all();
}
}