Add AsOf trait for sortable items

This commit is contained in:
danieljsummers committed 2023-08-23 19:58:31 -04:00
1 parent 0ec4fd017f
commit 9491359b52
5 files changed
+48 -24

No files matched your search

+3 -5
View File
@@ -4,7 +4,7 @@ declare(strict_types=1);
namespace MyPrayerJournal;
use BitBadger\PgSQL\Documents\{ Configuration, Definition, Document, DocumentIndex, Query };
use MyPrayerJournal\Domain\{ History, JournalRequest, Note, Request, RequestAction };
use MyPrayerJournal\Domain\{ AsOf, History, JournalRequest, Note, Request, RequestAction };
class Data
{
@@ -114,8 +114,7 @@ class Data
public static function getAnsweredRequests(string $userId): array
{
$answered = Data::getJournalByAnswered($userId, '==');
usort($answered,
fn (JournalRequest $a, JournalRequest $b) => $a->asOf == $b->asOf ? 0 : ($a->asOf > $b->asOf ? -1 : 1));
usort($answered, AsOf::newestToOldest(...));
return $answered;
}
@@ -128,8 +127,7 @@ class Data
public static function getJournal(string $userId): array
{
$reqs = data::getJournalByAnswered($userId, '<>');
usort($reqs,
fn (JournalRequest $a, JournalRequest $b) => $a->asOf == $b->asOf ? 0 : ($a->asOf < $b->asOf ? -1 : 1));
usort($reqs, AsOf::oldestToNewest(...));
return $reqs;
}
}