'Vollzeit', 'part' => 'Teilzeit', 'flex' => 'Voll- oder Teilzeit', 'mini' => 'Minijob', 'training' => 'Ausbildung / Studium', 'other' => 'Sonstiges']; public const CONTRACT = ['permanent' => 'Unbefristet', 'fixed' => 'Befristet']; public const APPLY_MODES = ['online' => 'Online im Portal', 'email' => 'Per E-Mail an eine Adresse', 'contact' => 'Über die Ansprechperson', 'link' => 'Über einen Link']; protected static function booted(): void { static::deleting(function (JobPosting $posting) { if ($posting->pdf_path) { Storage::disk(self::DISK)->delete($posting->pdf_path); } $posting->applications()->get()->each->delete(); }); } protected function casts(): array { return ['deadline' => 'date', 'published_at' => 'datetime', 'announced_at' => 'datetime']; } /** * Offene Stellen: veröffentlicht und Frist nicht abgelaufen. * * @param Builder $query */ public function scopeOpen(Builder $query): void { $query->whereNotNull('published_at')->where('published_at', '<=', now()) ->where(fn (Builder $q) => $q->whereNull('deadline')->orWhereDate('deadline', '>=', today())); } public function isOpen(): bool { return $this->published_at !== null && $this->published_at->isPast() && ($this->deadline === null || ! $this->deadline->isBefore(today())); } public function status(): string { return match (true) { $this->published_at === null => 'draft', $this->published_at->isFuture() => 'scheduled', $this->deadline !== null && $this->deadline->isBefore(today()) => 'expired', default => 'open', }; } /** * @return BelongsTo */ public function contact(): BelongsTo { return $this->belongsTo(User::class, 'contact_id'); } /** * @return HasMany */ public function applications(): HasMany { return $this->hasMany(JobApplication::class, 'posting_id'); } /** Wer die Bewerbungen dieser Stelle sehen darf */ public function canSeeApplications(?User $user): bool { return $user !== null && ($user->can('jobs.applications') || ($this->contact_id !== null && $this->contact_id === $user->id)); } /** * Kurzfassung der Eckdaten, z. B. „Teilzeit (30 Std./Woche) · befristet bis 31.12.2027“. */ public function summary(): string { return collect([ self::EMPLOYMENT[$this->employment] ?? null, $this->hours ? '('.$this->hours.')' : null, ])->filter()->implode(' ').($this->contract === 'fixed' ? ' · befristet'.($this->contract_note ? ' '.$this->contract_note : '') : ''); } }