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>
79 lines
2.3 KiB
PHP
79 lines
2.3 KiB
PHP
<?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');
|
||
}
|
||
}
|