- Medium anlegen: Pflichtfeld Fachliche Materialart (serverseitig geprüft) - Materialart Übungsabschnitt (automatisch) für Abschnitte im Übungseditor und aus Shinkan, mit Verweis auf die Übung - Medienmanager: Checkboxen statt Dropdown, Start ohne Übungsabschnitte, persönlicher Standard je Konto - Zuordnung des Bestands nur bei belegter Herkunft; Übungsabschnitte nie öffentlich Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
105 lines
3.1 KiB
PHP
105 lines
3.1 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',
|
|
'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', 'traineranleitung', self::EXERCISE_SECTION_SLUG];
|
|
|
|
/**
|
|
* Textabschnitte einer Übung. Die Materialart wird nur automatisch gesetzt (ExerciseSections) und hat deshalb
|
|
* keinen wählbaren Kontext.
|
|
*/
|
|
public const EXERCISE_SECTION_SLUG = 'uebungsabschnitt';
|
|
|
|
protected $fillable = [
|
|
'slug',
|
|
'label',
|
|
'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 $this->slug === self::EXERCISE_SECTION_SLUG;
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|