Files
fewo-stommer/app/Models/ChannelTask.php
LarsandCursor 8ebc1a3878 Assign the existing site to one landlord so stommer.info can run tenancy.
Seebad 0.3 stays in this release. With a single landlord every host still reaches the default website.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-23 12:00:11 +02:00

79 lines
2.3 KiB
PHP
Raw Permalink 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 App\Models;
use App\Enums\ChannelTaskAction;
use App\Enums\ChannelTaskStatus;
use App\Models\Concerns\BelongsToTenant;
use Database\Factories\ChannelTaskFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Scope;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* A change that has to be made by hand (or by an external automation) on a portal that
* cannot be kept in sync fast enough by calendar feeds, e.g. because of instant booking.
*/
#[Fillable(['channel_id', 'action', 'starts_on', 'ends_on', 'reason', 'status', 'completed_by', 'completed_at', 'reminded_at', 'automation_sent_at', 'automation_error'])]
class ChannelTask extends Model
{
/** @use HasFactory<ChannelTaskFactory> */
use BelongsToTenant, HasFactory;
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'action' => ChannelTaskAction::class,
'status' => ChannelTaskStatus::class,
'starts_on' => 'immutable_date',
'ends_on' => 'immutable_date',
'completed_at' => 'immutable_datetime',
'reminded_at' => 'immutable_datetime',
'automation_sent_at' => 'immutable_datetime',
];
}
/**
* @return BelongsTo<Channel, $this>
*/
public function channel(): BelongsTo
{
return $this->belongsTo(Channel::class);
}
/**
* @param Builder<ChannelTask> $query
* @return Builder<ChannelTask>
*/
#[Scope]
protected function open(Builder $query): Builder
{
return $query->where('status', ChannelTaskStatus::Open);
}
public function complete(string $completedBy): void
{
$this->update([
'status' => ChannelTaskStatus::Done,
'completed_by' => $completedBy,
'completed_at' => now(),
]);
}
/**
* Human readable period, e.g. "14.06.2027 – 21.06.2027".
*/
public function period(): string
{
return $this->starts_on->format('d.m.Y').' – '.$this->ends_on->format('d.m.Y');
}
}