Skip to content

Commit

Permalink
v1.6.0 (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
bfren authored Aug 23, 2023
2 parents 698d2b0 + 74ebb44 commit f842d28
Show file tree
Hide file tree
Showing 34 changed files with 396 additions and 229 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.2
1.6.0
2 changes: 1 addition & 1 deletion VERSION_MINOR
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5
1.6
14 changes: 8 additions & 6 deletions src/classes/bible/bible-plan.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ public function __construct()
App::die("Unable to read the file: %s.", $file_info->getRealPath());
}

// read each row
// build array of days
$days = array();
$trim = fn ($input) => trim(str_replace("\"", "", $input));

while (!$file_obj->eof()) {
// read the next line
$line = $file_obj->fgets();
Expand All @@ -56,11 +58,11 @@ public function __construct()

// read values
$days[$values[0]] = new Day(
ot_psalms: trim($values[1]),
ot_1: trim($values[2]),
ot_2: trim($values[3]),
nt_gospels: trim($values[4]),
nt_epistles: trim($values[5])
ot_psalms: $trim($values[1]),
ot_1: $trim($values[2]),
ot_2: $trim($values[3]),
nt_gospels: $trim($values[4]),
nt_epistles: $trim($values[5])
);
}

Expand Down
31 changes: 30 additions & 1 deletion src/classes/prayer/month.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Feeds\Prayer;

use DateInterval;
use DateTimeImmutable;
use Feeds\Admin\Result;
use Feeds\App;
Expand Down Expand Up @@ -50,12 +51,40 @@ public function get_first_day_of_month(): ?DateTimeImmutable
return new DateTimeImmutable(sprintf("%s-01", $this->id));
}

/**
* Get last Month's prayer calendar.
*
* Returns blank if the calendar does not exist.
*
* @return Month Last month's prayer calendar.
*/
public function get_last_month(): Month
{
$first_day = $this->get_first_day_of_month();
$last_month = $first_day->sub(new DateInterval("P1M"));
return Month::load($last_month->format(C::$formats->prayer_month_id));
}

/**
* Get next Month's prayer calendar.
*
* Returns blank if the calendar does not exist.
*
* @return Month Next month's prayer calendar.
*/
public function get_next_month(): Month
{
$first_day = $this->get_first_day_of_month();
$next_month = $first_day->add(new DateInterval("P1M"));
return Month::load($next_month->format(C::$formats->prayer_month_id));
}

/**
* Return a formatted date string of this month.
*
* @return null|string This month e.g. 'January 2022'.
*/
public function get_display_month(): ?string
public function get_display_text(): ?string
{
$dt = $this->get_first_day_of_month();
if ($dt) {
Expand Down
20 changes: 10 additions & 10 deletions src/classes/refresh/day.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class Day
* Create Day object.
*
* @param DateTimeImmutable $date The date.
* @param null|Readings $readings Bible readings.
* @param string[] $people Array of people.
* @param null|Readings $readings Bible readings.
* @return void
*/
public function __construct(
public readonly DateTimeImmutable $date,
public readonly ?Readings $readings,
public readonly array $people
public readonly array $people,
public readonly ?Readings $readings
) {
}

Expand All @@ -46,6 +46,13 @@ public function get_description(string $separator = "\\n"): string
{
$description = array();

// add people
if (!empty($this->people)) {
$description[] = "= People =";
$description[] = join($separator, $this->people);
$description[] = "";
}

// add readings
if ($this->readings) {
$description[] = "= Readings =";
Expand All @@ -57,13 +64,6 @@ public function get_description(string $separator = "\\n"): string
$description[] = "";
}

// add people
if (!empty($this->people)) {
$description[] = "= People =";
$description[] = join($separator, $this->people);
$description[] = "";
}

// return description
return join($separator, $description);
}
Expand Down
6 changes: 3 additions & 3 deletions src/classes/refresh/refresh.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public function __construct()
// create day object
$day = new Day(
date: $value,
readings: $bible->get_day($value),
people: $prayer->get_day($value)
people: $prayer->get_day($value),
readings: $bible->get_day($value)
);

// set today
Expand All @@ -76,7 +76,7 @@ public function __construct()

// if today has not been set, create an empty one for today
if (!isset($this->today)) {
$this->today = new Day($today, null, array());
$this->today = new Day($today, people: array(), readings: null);
}
}
}
9 changes: 7 additions & 2 deletions src/pages/home/home.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,19 @@ public function index_get(): View
"end" => $today->add(new DateInterval("P7D"))->format(C::$formats->sortable_date)
);

$refresh = array(
$refresh_print = array(
"month" => $today->format(C::$formats->prayer_month_id)
);

$refresh_feed = array(
"api" => C::$login->api
);

return new View("home", model: new Index_Model(
this_week: $this_week,
upcoming: Rota::upcoming_sundays(),
refresh: $refresh
refresh_print: $refresh_print,
refresh_feed: $refresh_feed
));
}
}
7 changes: 4 additions & 3 deletions src/pages/home/index-model.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ class Index_Model
*
* @param array $this_week Rota filter values to show this week's services.
* @param array $upcoming Rota filter values to show upcoming Sunday services.
* @param array $refresh Query values to enable refresh ICS feed.
* @return void
* @param array $refresh_print Query values to link to printable version of this month's refresh calendar.
* @param array $refresh_feed Query values to enable refresh ICS feed.
*/
public function __construct(
public readonly array $this_week,
public readonly array $upcoming,
public readonly array $refresh
public readonly array $refresh_print,
public readonly array $refresh_feed
) {
}
}
11 changes: 7 additions & 4 deletions src/pages/home/index-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,27 @@
/** @var View $this */
/** @var Index_Model $model */

// get refresh links
$refresh_print_uri = sprintf("/refresh/print/?%s", http_build_query($model->refresh_print));
$refresh_feed_uri = sprintf("/refresh/ics/?%s", http_build_query($model->refresh_feed));

// output header
$this->header(new Header_Model("Home", subtitle: "These pages house the various feeds generated from Church Suite."));

?>

<h2>Rota</h2>
<p>To view this week&rsquo;s services, please click <a href="/rota/?<?php _e(http_build_query($model->this_week)); ?>">here</a>.</p>

<h3>Printable</h3>
<p>The following links will give you quick and printable rotas for upcoming services.</p>
<p><a href="/rota/notices/?<?php _e(http_build_query($model->upcoming)); ?>">Sunday services for the next four weeks</a></p>

<h2>Refresh</h2>
<p>Use <a href="/refresh/ics/?<?php _e(http_build_query($model->refresh)); ?>">this link</a> to subscribe to the Refresh calendar feed.</p>
<p>View a printable version of this month&rsquo;s refresh calendar <a href="<?php _e($refresh_print_uri); ?>" target="_blank">here</a>.</p>
<p>Use <a href="<?php _e($refresh_feed_uri); ?>">this link</a> to subscribe to the Refresh calendar feed.</p>

<?php if (Request::$session->is_admin) : ?>
<h2>Caches</h2>
<p><a href="/preload">Refresh</a> Bible reading plan, prayer calendar, lectionary and rota caches.</p>
<p><a href="/preload">Reload</a> Bible reading plan, prayer calendar, lectionary and rota caches.</p>
<?php endif; ?>

<?php
Expand Down
3 changes: 1 addition & 2 deletions src/pages/parts/footer/prayer-part.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
</div><!-- primary container -->
</main>

<footer class="footer footer-prayer mt-2 py-1 bg-light">
<footer class="footer footer-prayer mt-2">
<div class="container-fluid">
<small class="text-muted">
<p>These names come from our church address book. If you don&rsquo;t wish to be included, you can remove yourself in Church Suite or by contacting the office.</p>
<p class="d-flex justify-content-between">
<span><a href="https://www.christchurchb29.org/privacy-policy" target="_blank">www.christchurchb29.org/privacy-policy</a></span>
<span>Generated on <?php _e($today->format("r")); ?></span>
Expand Down
1 change: 0 additions & 1 deletion src/pages/parts/header/header-model.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class Header_Model
* @param null|string $subtitle Optional page subtitle.
* @param null|string $class Optional class for HTML tag.
* @param bool $overflow_scroll Enable overflow scroll for this page.
* @return void
*/
public function __construct(
public readonly string $title,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Feeds\Pages\Rota;
namespace Feeds\Pages\Parts\Reading;

use Feeds\App;
use Feeds\Config\Config as C;
Expand All @@ -19,4 +19,4 @@

?>

<a href="<?php _e($url) ?>" target="_blank"><?php _e($model) ?></a>
<a href="<?php _e($url) ?>" target="_blank"><?php _h(str_replace(" ", "&nbsp;", $model)) ?></a>
10 changes: 6 additions & 4 deletions src/pages/prayer/index-model.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
class Index_Model
{
/**
* Create Index model.
*
* @param null|Result $result
* @param string[] $months
* @return void
* @param null|Result $result Operation result.
* @param string[] $months Array of months in the cache.
* @param string $next_month Month ID of next month.
*/
public function __construct(
public readonly ?Result $result,
public readonly array $months
public readonly array $months,
public readonly string $next_month
)
{

Expand Down
4 changes: 2 additions & 2 deletions src/pages/prayer/index-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
$delete_query = array("file" => sprintf("%s.month", $month));
?>
<li>
<a href="/prayer/print/?<?php _e(http_build_query($view_query)); ?>"><?php _e($month); ?></a>
<a href="/refresh/print/?<?php _e(http_build_query($view_query)); ?>" target="_blank"><?php _e($month); ?></a>
<?php if (Request::$session->is_admin) : ?>
<a class="badge rounded-pill text-bg-warning fw-bold" href="/prayer/edit/?<?php _e(http_build_query($edit_query)); ?>">edit</a>
<a class="badge rounded-pill text-bg-danger fw-bold check-first" href="/prayer/delete/?<?php _e(http_build_query($delete_query)); ?>">delete</a>
Expand All @@ -49,7 +49,7 @@
<form class="row row-cols-lg-auto g-3 mb-3 align-items-center needs-validation" method="GET" action="/prayer/edit/" novalidate>
<div class="col-12 position-relative">
<label class="visually-hidden" for="for">Month</label>
<input type="text" class="form-control" id="for" name="for" placeholder="Month e.g. '2022-12'" required />
<input type="text" class="form-control" id="for" name="for" placeholder="Month e.g. '<?php _e($model->next_month); ?>'" required />
<div class="invalid-tooltip">Please enter the month to create a prayer calendar for.</div>
</div>
<div class="col-12">
Expand Down
22 changes: 5 additions & 17 deletions src/pages/prayer/prayer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Feeds\Admin\Result;
use Feeds\App;
use Feeds\Cache\Cache;
use Feeds\Config\Config as C;
use Feeds\Prayer\Month;
use Feeds\Request\Request;
use Feeds\Response\Action;
Expand All @@ -32,9 +33,11 @@ class Prayer
*/
public function index_get(): View
{
$next_month = new DateTimeImmutable("next month");
return new View("prayer", model: new Index_Model(
result: $this->result,
months: Cache::get_prayer_calendar()->get_months()
months: Cache::get_prayer_calendar()->get_months(),
next_month: $next_month->format(C::$formats->prayer_month_id)
));
}

Expand Down Expand Up @@ -79,6 +82,7 @@ public function edit_get(): Action
return $this->index_get();
}

// create edit view
return new View("prayer", name: "edit", model: new Edit_Model(
result: $this->result,
prayer: $prayer_calendar,
Expand All @@ -104,20 +108,4 @@ public function delete_get(): View
// return index page
return $this->index_get();
}

/**
* GET: /prayer/print
*
* @return View
*/
public function print_get(): View
{
// get requested month
$month_id = Request::$get->string("month");
$month = Month::load($month_id);

return new View("prayer", name: "print", model: new Print_Model(
month: $month
));
}
}
16 changes: 0 additions & 16 deletions src/pages/prayer/print-model.class.php

This file was deleted.

Loading

0 comments on commit f842d28

Please sign in to comment.