Loheide-eu-mitarbeiterplatt.../plugins-core/speiseplan/src/Models/Week.php
Friederich Loheide b50d089946
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Failing after 3m18s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Failing after 3m27s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Failing after 3m0s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Failing after 2m56s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 4m4s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 4m1s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 3m41s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 3m39s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m10s
QM-Texterkennung: Imagick nur mit Ghostscript als verfügbar melden
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 16:38:17 +00:00

52 lines
1.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Inhaus\Plugins\Speiseplan\Models;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Storage;
/**
* Speiseplan einer Kalenderwoche (ein Bild, A4 hoch).
*/
#[Fillable(['week_start', 'path', 'original_name', 'width', 'height', 'uploaded_by'])]
class Week extends Model
{
public const DISK = 'local';
protected $table = 'speiseplan_weeks';
protected static function booted(): void
{
static::deleted(fn (Week $week) => Storage::disk(self::DISK)->delete($week->path));
}
protected function casts(): array
{
return ['week_start' => 'date'];
}
public static function mondayOf(Carbon|string $date): Carbon
{
return Carbon::parse($date)->startOfWeek(Carbon::MONDAY)->startOfDay();
}
/**
* @return array<string, mixed>
*/
public function present(): array
{
$end = $this->week_start->copy()->addDays(4);
return [
'id' => $this->id,
'week_start' => $this->week_start->toDateString(),
'week' => (int) $this->week_start->isoWeek(),
'label' => 'KW '.$this->week_start->isoWeek().' · '.$this->week_start->format('d.m.').' – '.$end->format('d.m.Y'),
'image_url' => route('speiseplan.image', ['week' => $this->id, 'v' => $this->updated_at?->timestamp]),
'width' => $this->width,
'height' => $this->height,
];
}
}