Render requests (crudely)

This commit is contained in:
2023-11-19 20:15:29 -05:00
parent 5f425adc1d
commit f8b5902aa1
11 changed files with 57 additions and 54 deletions

View File

@@ -8,10 +8,8 @@ use DateTimeImmutable, DateTimeZone;
/**
* A prayer request, along with calculated fields, for use in displaying journal lists
*/
class JournalRequest
class JournalRequest extends AsOf
{
use AsOf;
/** The ID of the prayer request */
public string $id = '';
@@ -22,7 +20,7 @@ class JournalRequest
public string $text = '';
/** The date/time this request was last marked as prayed */
public DateTimeImmutable $lastPrayed;
public ?DateTimeImmutable $lastPrayed = null;
/** The last action taken on this request */
public RequestAction $lastAction = RequestAction::Created;
@@ -60,8 +58,8 @@ class JournalRequest
public function __construct(?Request $req = null, bool $full = false)
{
if (is_null($req)) {
$this->asOf = new DateTimeImmutable('1/1/1970', new DateTimeZone('Etc/UTC'));
$this->lastPrayed = new DateTimeImmutable('1/1/1970', new DateTimeZone('Etc/UTC'));
$this->asOf = unix_epoch();
$this->lastPrayed = null;
} else {
$this->id = $req->id;
$this->userId = $req->userId;
@@ -71,9 +69,11 @@ class JournalRequest
$this->recurrence = $req->recurrence;
usort($req->history, AsOf::newestToOldest(...));
$this->asOf = $req->history[0]->asOf;
$this->lastPrayed = array_values(
array_filter($req->history, fn (History $it) => $it->isPrayed()))[0]?->asOf;
$this->asOf = $req->history[array_key_first($req->history)]->asOf;
$lastText = array_filter($req->history, fn (History $it) => !is_null($it->text));
$this->text = $lastText[array_key_first($lastText)]->text;
$lastPrayed = array_filter($req->history, fn (History $it) => $it->isPrayed());
if ($lastPrayed) $this->lastPrayed = $lastPrayed[array_key_first($lastPrayed)]->asOf;
if ($full) {
usort($req->notes, AsOf::newestToOldest(...));