-
Notifications
You must be signed in to change notification settings - Fork 554
/
ScheduledStatus.php
47 lines (37 loc) · 1.46 KB
/
ScheduledStatus.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace A17\Twill\Services\Listings\Columns;
use A17\Twill\Models\Contracts\TwillModelContract;
use A17\Twill\Services\Listings\TableColumn;
use Carbon\Carbon;
class ScheduledStatus extends TableColumn
{
public static function make(): static
{
$column = new static();
$column->field('scheduled_status');
return $column;
}
protected function getRenderValue(TwillModelContract $model): string
{
$this->html = true;
$startDate = $model->publish_start_date ? Carbon::parse($model->publish_start_date) : null;
$endDate = $model->publish_end_date ? Carbon::parse($model->publish_end_date) : null;
$expired = $model->publish_end_date && $endDate->isPast();
$scheduled = $model->publish_start_date && $startDate->isFuture();
$label = null;
if ($scheduled) {
$label = twillTrans('twill::lang.publisher.scheduled');
} elseif ($expired) {
$label = twillTrans('twill::lang.publisher.expired');
}
$format = config('twill.publish_date_display_format', 'F d, Y');
return view('twill::listings.columns.scheduled-data', [
'isScheduled' => $scheduled,
'isExpired' => $expired,
'label' => $label,
'hasStartDate' => $model->publish_start_date ?? false,
'startDate' => $startDate?->format($format),
'endDate' => $endDate?->format($format),
])->render();
}
}