Skip to content

Commit 3280475

Browse files
committed
Adding events to refresh loader - #220
1 parent 37646f9 commit 3280475

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/classes/refresh/day.class.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Obadiah\App;
77
use Obadiah\Bible\Day as Readings;
88
use Obadiah\Cache\Cache;
9+
use Obadiah\Calendar\Event;
910
use Obadiah\Config\Config as C;
1011
use Obadiah\Helpers\Arr;
1112
use Obadiah\Helpers\Psalms;
@@ -18,21 +19,23 @@ class Day
1819
/**
1920
* Create Day object.
2021
*
21-
* @param DateTimeImmutable $date The date.
22-
* @param Person[]|string[] $people Array of people.
23-
* @param Readings|null $readings Bible readings.
22+
* @param DateTimeImmutable $date The date.
23+
* @param Person[]|string[] $people Array of people.
24+
* @param Event[] $events Array of people.
25+
* @param Readings|null $readings Bible readings.
2426
* @return void
2527
*/
2628
public function __construct(
2729
public readonly DateTimeImmutable $date,
2830
public readonly array $people,
31+
public readonly array $events,
2932
public readonly ?Readings $readings
3033
) {}
3134

3235
/**
3336
* Build event summary.
3437
*
35-
* @return string Event summary.
38+
* @return string Event summary.
3639
*/
3740
public function get_summary(): string
3841
{
@@ -42,8 +45,8 @@ public function get_summary(): string
4245
/**
4346
* Build event description.
4447
*
45-
* @param string $separator Line separator.
46-
* @return string Event description.
48+
* @param string $separator Line separator.
49+
* @return string Event description.
4750
*/
4851
public function get_description(string $separator = "\\n"): string
4952
{
@@ -68,6 +71,14 @@ public function get_description(string $separator = "\\n"): string
6871
$description[] = "";
6972
}
7073

74+
// add events
75+
if (!empty($this->events)) {
76+
$description[] = "= Events & Groups =";
77+
$events = Arr::map($this->events, fn($e) => sprintf("%s - %s", $e->start->format(C::$formats->display_time), $e->title));
78+
$description[] = join($separator, $events);
79+
$description[] = "";
80+
}
81+
7182
// add Collects
7283
if (($collect = Cache::get_lectionary()->get_collect($this->date)) !== null) {
7384
$lines = preg_split("/\n/", $collect);

src/classes/refresh/refresh.class.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Obadiah\App;
99
use Obadiah\Cache\Cache;
1010
use Obadiah\Config\Config as C;
11+
use Obadiah\Helpers\Arr;
12+
use Obadiah\Pages\Events\Events;
1113
use Obadiah\Prayer\Prayer_Calendar;
1214

1315
App::check();
@@ -46,6 +48,10 @@ public function __construct()
4648

4749
// get data from caches
4850
$bible = Cache::get_bible_plan();
51+
$events = Events::get_events(array(
52+
"start" => $period->start->format(C::$formats->sortable_date),
53+
"end" => $period->end->format(C::$formats->sortable_date)
54+
));
4955

5056
// get readings and people for each day
5157
$days = [];
@@ -58,9 +64,12 @@ public function __construct()
5864

5965
// create day object
6066
$immutable = DateTimeImmutable::createFromInterface($value);
67+
$date = $immutable->format(C::$formats->sortable_date);
68+
$date_events = Arr::match($events, fn ($e) => $e->start->format(C::$formats->sortable_date) == $date);
6169
$day = new Day(
6270
date: $immutable,
6371
people: Prayer_Calendar::get_day($immutable, Prayer_Calendar::RETURN_OBJECT),
72+
events: $date_events,
6473
readings: $bible->get_day($immutable)
6574
);
6675

@@ -77,6 +86,6 @@ public function __construct()
7786
$this->days = $days;
7887

7988
// if today has not been set, create an empty one for today
80-
$this->today = $today_value ?: new Day($today, people: [], readings: null);
89+
$this->today = $today_value ?: new Day($today, people: [], events: [], readings: null);
8190
}
8291
}

0 commit comments

Comments
 (0)