Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m8s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m12s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m12s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m5s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m6s
CI / Build-Artefakte aktuell (pull_request) Failing after 43s
- Neuigkeiten mit Kategorien, Titelbild (WebP-Varianten), Lesezeit, geplanter Veröffentlichung und Hervorhebung; Text wird beim Speichern bereinigt - Termine mit Ort, Online-Link, ganztägigen Terminen und .ics-Export - Startseite nach Intranet-Vorbild: Slider, Neuigkeiten, Termine, Aktuelles aus den Bereichen; mobil in sinnvoller Reihenfolge - Admin: Beiträge, Kategorien und Termine - Bildverarbeitung für Shared Hosting: nur eine Vollbild-Kopie im Speicher, Speicherlimit bei Bedarf auf 256 MB angehoben (wie WordPress) - Demo-Inhalte für die Entwicklung Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
85 lines
2.6 KiB
PHP
85 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Support\Images;
|
|
use App\Support\RichText;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
#[Fillable([
|
|
'author_id', 'title', 'description', 'location', 'online_url',
|
|
'starts_at', 'ends_at', 'all_day', 'image_path', 'is_published',
|
|
])]
|
|
class Event extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::saving(function (Event $event): void {
|
|
if ($event->isDirty('description') || $event->description_html === null) {
|
|
$event->description_html = app(RichText::class)->toSafeHtml($event->description);
|
|
}
|
|
});
|
|
|
|
// Bildvarianten erzeugen bzw. beim Austausch die alten Dateien entfernen.
|
|
static::saved(function (Event $event): void {
|
|
if (! $event->wasRecentlyCreated && ! $event->wasChanged('image_path')) {
|
|
return;
|
|
}
|
|
|
|
$previous = $event->wasRecentlyCreated ? null : $event->getOriginal('image_path');
|
|
|
|
if ($previous && $previous !== $event->image_path) {
|
|
app(Images::class)->deleteWithVariants($previous);
|
|
}
|
|
|
|
if ($event->image_path) {
|
|
app(Images::class)->createVariants($event->image_path);
|
|
}
|
|
});
|
|
|
|
static::deleted(fn (Event $event) => app(Images::class)->deleteWithVariants($event->image_path));
|
|
}
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'starts_at' => 'datetime',
|
|
'ends_at' => 'datetime',
|
|
'all_day' => 'boolean',
|
|
'is_published' => 'boolean',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<User, $this>
|
|
*/
|
|
public function author(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
/**
|
|
* Veröffentlichte Termine, die noch nicht vorbei sind (laufende eingeschlossen).
|
|
*
|
|
* @param Builder<Event> $query
|
|
*/
|
|
public function scopeUpcoming(Builder $query): void
|
|
{
|
|
$query->where('is_published', true)
|
|
->where(fn (Builder $q) => $q
|
|
->where('ends_at', '>=', now())
|
|
->orWhere(fn (Builder $q) => $q->whereNull('ends_at')->where('starts_at', '>=', now()->startOfDay())))
|
|
->orderBy('starts_at');
|
|
}
|
|
|
|
public function imageUrl(string $variant = 'large'): ?string
|
|
{
|
|
return app(Images::class)->url($this->image_path, $variant);
|
|
}
|
|
}
|