-
-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathTimelineCollection.php
More file actions
25 lines (20 loc) · 849 Bytes
/
TimelineCollection.php
File metadata and controls
25 lines (20 loc) · 849 Bytes
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
<?php
namespace Cachet\Collections;
use Cachet\Contracts\Support\Sequencable;
use Illuminate\Support\Collection;
class TimelineCollection extends Collection
{
public function getSorted($startDate, $endDate, $onlyDisruptedDays = false)
{
return $this->sortByDesc(fn (Sequencable $item) => $item->getSequenceTimestamp())
->groupBy(fn (Sequencable $item) => $item->getSequenceTimestamp()->toDateString())
->union(
// Back-fill any missing dates...
collect($endDate->toPeriod($startDate))
->keyBy(fn ($period) => $period->toDateString())
->map(fn ($period) => collect())
)
->when($onlyDisruptedDays, fn ($collection) => $collection->filter(fn ($items) => $items->isNotEmpty()))
->sortKeysDesc();
}
}