From 75b3778dccccddb5cc90b2b4e0a3f958826ad8ba Mon Sep 17 00:00:00 2001 From: winter Date: Wed, 15 Jan 2025 20:33:38 +0000 Subject: implement home timeline --- Digitigrade/Timeline/HomeTimelineItem.php | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Digitigrade/Timeline/HomeTimelineItem.php (limited to 'Digitigrade/Timeline/HomeTimelineItem.php') diff --git a/Digitigrade/Timeline/HomeTimelineItem.php b/Digitigrade/Timeline/HomeTimelineItem.php new file mode 100644 index 0000000..cb2b6e4 --- /dev/null +++ b/Digitigrade/Timeline/HomeTimelineItem.php @@ -0,0 +1,52 @@ +userAccount = $user; + $reason = $item->getReason(); + if ($reason != null) { + $hti->reasonKind = $reason::class; + $hti->reasonData = json_encode($reason->toJsonReference()); + } + $object = $item->getObject(); + $hti->itemKind = $object::class; + $hti->itemData = json_encode($object->toJsonReference()); + $hti->modified = new \DateTimeImmutable(); + return $hti; + } + + public function toTimelineItem(): TimelineItem { + $reason = null; + if (isset($this->reasonKind)) { + $reason = $this->reasonKind::fromJsonReference(json_decode($this->reasonData)); + } + $object = $this->itemKind::fromJsonReference(json_decode($this->itemData)); + return new TimelineItem($object, $reason); + } + + public static function findAllForUser(UserAccount $user, ?int $limit = null, int $offset = 0, ?\DateTimeInterface $since = null) { + $where = 'user_account = ?'; + $params = [$user->id]; + if (isset($since)) { + $where .= ' AND modified > ?'; + $params[] = $since->format('c'); + } + return self::findAllWhere($where, $params, $limit, $offset, 'id DESC'); + } +} \ No newline at end of file -- cgit v1.3