Loheide-eu-mitarbeiterplatt.../plugins-core/stellen/src/Models/JobPosting.php
Friederich Loheide 14e39bd9b3
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m39s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 7m45s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m50s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m51s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 10m3s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 10m8s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m52s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m55s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m33s
Stellen: Bewerbung per E-Mail-Adresse (0.28.3)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 10:50:31 +00:00

102 lines
3.6 KiB
PHP

<?php
namespace Inhaus\Plugins\Stellen\Models;
use App\Models\User;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Facades\Storage;
/**
* Eine interne Stellenausschreibung. Sichtbar ab „published_at“ bis einschließlich zur Frist.
*/
#[Fillable(['title', 'department', 'location', 'employment', 'hours', 'contract', 'contract_note', 'pay_grade', 'start', 'deadline',
'description', 'pdf_path', 'pdf_name', 'apply_mode', 'apply_url', 'apply_email', 'contact_id', 'notify_email', 'published_at', 'created_by', 'updated_by'])]
class JobPosting extends Model
{
public const DISK = 'local';
public const EMPLOYMENT = ['full' => '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<JobPosting> $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<User, $this>
*/
public function contact(): BelongsTo
{
return $this->belongsTo(User::class, 'contact_id');
}
/**
* @return HasMany<JobApplication, $this>
*/
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 : '') : '');
}
}