diff options
Diffstat (limited to 'src/application/actions/viewtopic/get.php')
-rw-r--r-- | src/application/actions/viewtopic/get.php | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/application/actions/viewtopic/get.php b/src/application/actions/viewtopic/get.php index 636d791..56308bf 100644 --- a/src/application/actions/viewtopic/get.php +++ b/src/application/actions/viewtopic/get.php @@ -1,9 +1,12 @@ <?php /** @var Post[] $posts */ +/** @var ?User $currentUser */ +/** @var \mystic\forum\Database $db */ use mystic\forum\orm\Attachment; use mystic\forum\orm\Post; +use mystic\forum\orm\Subscription; use mystic\forum\orm\TopicLogMessage; use mystic\forum\orm\User; @@ -58,8 +61,20 @@ $allItems = array_map(function(Post|TopicLogMessage $item) use (&$db, &$topicAut } }, $allItems); +$subscription = null; +if ($currentUser !== null) { + $subscription = new Subscription; + $subscription->userId = $currentUser->id; + $subscription->topicId = $topic->id; + if (!$db->fetchWhere($subscription, ["user_id", "topic_id"])) { + $subscription = null; + } +} + render("view_topic.twig", [ "topic" => $topic, "topicAuthor" => $topicAuthor, "allItems" => &$allItems, + "subscription" => $subscription, + "subscription_count" => count($db->fetchCustom(Subscription::class, "WHERE topic_id = $1", [ $topic->id ])), ]); |