First cut of Add / Edit / Active / Answered pages
- Centralized UI between UI and Layout classes
This commit is contained in:
49
src/public/request/full.php
Normal file
49
src/public/request/full.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use MyPrayerJournal\{Auth, History, Layout, Note, Request, RequestAction, UI};
|
||||
|
||||
require '../../start.php';
|
||||
if ($_SERVER['REQUEST_METHOD'] <> 'GET') not_found();
|
||||
|
||||
Auth::requireUser();
|
||||
|
||||
$req = Request::byId($_GET['id']);
|
||||
if (!$req) not_found();
|
||||
|
||||
$answered = $req->isAnswered() ? new DateTimeImmutable($req->history[0]->asOf) : null;
|
||||
$prayed = sizeof(array_filter($req->history, fn(History $hist) => $hist->action == RequestAction::Prayed));
|
||||
$daysOpen =
|
||||
(($answered ?? new DateTimeImmutable('now'))->getTimestamp()
|
||||
- (new DateTimeImmutable(end($req->history)->asOf))->getTimestamp()) / 86400;
|
||||
|
||||
$logs = array_merge(
|
||||
array_map(fn(Note $note) => [new DateTimeImmutable($note->asOf), 'Notes', $note->text], $req->notes),
|
||||
array_map(fn(History $hist) => [new DateTimeImmutable($hist->asOf), $hist->action->value, $hist->text ?? ''],
|
||||
$req->history));
|
||||
usort($logs, fn($a, $b) => $a[0] > $b[0] ? -1 : 1);
|
||||
if ($req->isAnswered()) array_shift($logs);
|
||||
|
||||
Layout::pageHead('Full Request');?>
|
||||
<article class="container mt-3">
|
||||
<div class=card>
|
||||
<h5 class=card-header>Full Prayer Request</h5>
|
||||
<div class=card-body>
|
||||
<h6 class="card-subtitle text-muted mb-2"><?php
|
||||
if (!is_null($answered)) { ?>
|
||||
Answered <?=$answered->format('F j, Y')?> (<?php UI::relativeDate($req->history[0]->asOf); ?>)
|
||||
•<?php
|
||||
} ?>
|
||||
Prayed <?=number_format($prayed)?> times • Open <?=number_format($daysOpen)?> days
|
||||
</h6>
|
||||
<p class=card-text><?=htmlentities($req->currentText())?>
|
||||
</div>
|
||||
<ul class="list-group list-group-flush"><?php
|
||||
foreach ($logs as $log) { ?>
|
||||
<li class=list-group-item>
|
||||
<p class=m-0><?=$log[1]?> <small><em><?=$log[0]->format('F j, Y')?></em></small><?php
|
||||
if ($log[2] <> '') echo '<p class="mt-2 mb-0">' . htmlentities($log[2]);
|
||||
} ?>
|
||||
</ul>
|
||||
</div>
|
||||
</article><?php
|
||||
Layout::pageFoot();
|
||||
Reference in New Issue
Block a user