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
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
52 lines
1.5 KiB
PHP
52 lines
1.5 KiB
PHP
<?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,
|
||
];
|
||
}
|
||
}
|