Files
BauIN/app/Models/Dokument.php
T
ChristophandClaude Opus 5.5 6aac8b0a16 Datenmodell Kern: Projekt, PFA, Vertrag, LV, Nachtrag, Dokument
- Mandant, Auftragnehmer, Projekt mit Suchreihenfolge, Abschnitt (PFA), Vertrag,
  Leistungsverzeichnis, Nachtrag (MKA nur als Bezug), Nachtragsposition, Dokument
- Projektmitglieder mit Projektrolle, Freigaben für vertrauliche Dokumente
- Mandant, Land und Projekt werden vom übergeordneten Datensatz übernommen;
  Fehlzuordnungen über Mandanten oder Projekte hinweg werden abgewiesen
- Feste Morph-Map, Factories, Demodaten (Musterbahn, PFA 1–4, N14/N16/N21), Tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 08:34:24 +02:00

96 lines
2.7 KiB
PHP

<?php
namespace App\Models;
use App\Enums\DokumentKategorie;
use App\Enums\Land;
use App\Models\Concerns\ErbtZuordnung;
use Carbon\CarbonImmutable;
use Database\Factories\DokumentFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Table;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
/**
* Hochgeladene Datei im privaten Speicher. Gehört zu einem Projekt und optional zu einem LV,
* Nachtrag oder Vertrag. Ohne Projekt ist es ein allgemeines Dokument (Einstellungen).
* Vertrauliche Dokumente sehen nur die freigegebenen Personen.
*
* @property int $id
* @property int $mandant_id
* @property Land $land
* @property int|null $projekt_id
* @property string|null $dokumentable_type
* @property int|null $dokumentable_id
* @property DokumentKategorie $kategorie
* @property string $dateiname
* @property string $pfad
* @property string $mime_type
* @property int $groesse
* @property string $sha256
* @property bool $vertraulich
* @property int|null $hochgeladen_von
* @property CarbonImmutable|null $created_at
* @property CarbonImmutable|null $updated_at
*/
#[Table('dokumente')]
#[Fillable([
'mandant_id', 'land', 'projekt_id', 'kategorie', 'dateiname', 'pfad', 'mime_type',
'groesse', 'sha256', 'vertraulich', 'hochgeladen_von',
])]
class Dokument extends Model
{
/** @use HasFactory<DokumentFactory> */
use ErbtZuordnung, HasFactory;
/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'land' => Land::class,
'kategorie' => DokumentKategorie::class,
'vertraulich' => 'boolean',
'groesse' => 'integer',
];
}
protected function zuordnungsEltern(): ?Model
{
if ($this->dokumentable_type !== null) {
return $this->dokumentable()->getResults();
}
return $this->projekt()->first();
}
/** @return BelongsTo<Projekt, $this> */
public function projekt(): BelongsTo
{
return $this->belongsTo(Projekt::class);
}
/** @return MorphTo<Model, $this> */
public function dokumentable(): MorphTo
{
return $this->morphTo();
}
/** @return BelongsTo<User, $this> */
public function hochgeladenVon(): BelongsTo
{
return $this->belongsTo(User::class, 'hochgeladen_von');
}
/** @return BelongsToMany<User, $this> */
public function freigaben(): BelongsToMany
{
return $this->belongsToMany(User::class, 'dokument_freigaben')->withTimestamps();
}
}