Skip to content

Commit 075029f

Browse files
authored
v2.2.3 (#221)
2 parents eb5ed6d + a820cb6 commit 075029f

File tree

6 files changed

+59
-21
lines changed

6 files changed

+59
-21
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.2.2
1+
2.2.3

src/classes/helpers/arr.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public static function map(array $array, ?callable $callback = null): array
149149
*
150150
* @template T
151151
* @param T[] $array Array to search.
152-
* @param callable|null $callback Callback function (should return bool),
152+
* @param callable(T):bool|null $callback Callback function (should return bool),
153153
* @return T[] Array of matching elements.
154154
*/
155155
public static function match(array $array, ?callable $callback = null): array

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
}

src/pages/events/events.class.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Events extends Endpoint
3131
public function ics_get(): ICalendar
3232
{
3333
// get events
34-
$query = self::get_query();
34+
$query = self::get_query(Request::$get->all());
3535
$events = Cache::get_events($query, fn(string $q) => self::get_events($q));
3636

3737
// create calendar
@@ -49,7 +49,7 @@ public function ics_get(): ICalendar
4949
public function json_get(): Json
5050
{
5151
// get events
52-
$events = Cache::get_events(self::get_query(), fn(string $q) => self::get_events($q));
52+
$events = Cache::get_events(self::get_query(Request::$get->all()), fn(string $q) => self::get_events($q));
5353

5454
// return JSON action
5555
return new Json($events);
@@ -58,16 +58,17 @@ public function json_get(): Json
5858
/**
5959
* Get Church Suite compatible query options.
6060
*
61-
* @return string URL-encoded query (using http_build_query()).
61+
* @param array<string, mixed> $values Query values.
62+
* @return string URL-encoded query (using http_build_query()).
6263
*/
63-
private static function get_query(): string
64+
private static function get_query(array $values): string
6465
{
6566
// get query options
6667
$query = array(
67-
"category" => Request::$get->int("cat"),
68-
"date_start" => Request::$get->string("start"),
69-
"date_end" => Request::$get->string("end"),
70-
"q" => Request::$get->string("q"),
68+
"category" => Arr::get_integer($values, "cat"),
69+
"date_start" => Arr::get($values, "start"),
70+
"date_end" => Arr::get($values, "end"),
71+
"q" => Arr::get($values, "q"),
7172
);
7273

7374
// return encoded query
@@ -77,13 +78,16 @@ private static function get_query(): string
7778
/**
7879
* Get events from Church Suite matching the query.
7980
*
80-
* @param string $query URL-encoded query (e.g. using http_build_query()).
81-
* @return Event[] Array of matching events.
81+
* @param array<string, mixed>|string $query Array of query values, or URL-encoded query (e.g. using http_build_query()).
82+
* @return Event[] Array of matching events.
8283
*/
83-
public static function get_events(string $query): array
84+
public static function get_events(array|string $query): array
8485
{
86+
// build query string
87+
$query_values = is_array($query) ? self::get_query($query) : $query;
88+
8589
// create curl request
86-
$url = sprintf(self::CALENDAR_HREF, C::$churchsuite->org, $query);
90+
$url = sprintf(self::CALENDAR_HREF, C::$churchsuite->org, $query_values);
8791
$handle = curl_init($url);
8892
if ($handle === false) {
8993
_l("Unable to create cURL request for %s.", $url);
@@ -139,6 +143,9 @@ public static function get_events(string $query): array
139143
);
140144
}
141145

146+
// sort events by start time
147+
usort($events, fn($a, $b) => ($a->start < $b->start) ? -1 : 1);
148+
142149
// return events
143150
return $events;
144151
}

src/pages/refresh/index-view.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@
5050
<?php else : ?>
5151
<p>There are no Bible readings for today.</p>
5252
<?php endif; ?>
53+
<h3 class="mt-3">Events &amp; Groups</h3>
54+
<?php if ($model->today->events): ?>
55+
<p class="small text-muted">The following events, groups and ministries are taking place today.</p>
56+
<?php foreach ($model->today->events as $e): ?>
57+
<p><?php _h("%s %s", $e->start->format(C::$formats->display_time), $e->title); ?></p>
58+
<?php endforeach; ?>
59+
<?php elseif ($model->today->date->format("N") == 7) : ?>
60+
<p>Ask God to bless today&rsquo;s services.</p>
61+
<?php else: ?>
62+
<p>There are no groups or events today.</p>
63+
<?php endif; ?>
5364
</div>
5465

5566
<div class="col-12 col-md-4 mb-2">

0 commit comments

Comments
 (0)