From fe0f414dc0211a4014581dc03fcfd514ed7ed02d Mon Sep 17 00:00:00 2001 From: Jonas Kohl Date: Thu, 17 Oct 2024 10:56:01 +0200 Subject: Transition templating to Twig --- src/application/actions/viewtopic/get.php | 37 +++++++++++-------------------- 1 file changed, 13 insertions(+), 24 deletions(-) (limited to 'src/application/actions/viewtopic') diff --git a/src/application/actions/viewtopic/get.php b/src/application/actions/viewtopic/get.php index 45dc824..636d791 100644 --- a/src/application/actions/viewtopic/get.php +++ b/src/application/actions/viewtopic/get.php @@ -6,7 +6,6 @@ use mystic\forum\orm\Attachment; use mystic\forum\orm\Post; use mystic\forum\orm\TopicLogMessage; use mystic\forum\orm\User; -use mystic\forum\utils\RequestUtils; $posts = $db->fetchCustom(Post::class, 'WHERE topic_id = $1 ORDER BY post_date', [ $topicId ]); /** @var TopicLogMessage[] $logMessages */ @@ -25,13 +24,7 @@ if ($topic->createdBy !== null) { $allItems = [...$posts, ...$logMessages]; usort($allItems, fn(Post|TopicLogMessage $a, Post|TopicLogMessage $b): int => $a->postDate <=> $b->postDate); -_view("template_start", ["_title" => $topic->title]); -_view("template_navigation_start"); -_view("template_navigation", ["user" => RequestUtils::getAuthorizedUser($db)]); -_view("template_navigation_end"); -_view("view_topic_start", ["topic" => $topic, "topicAuthor" => $topicAuthor]); - -foreach ($allItems as $item) { +$allItems = array_map(function(Post|TopicLogMessage $item) use (&$db, &$topicAuthor, &$topic): array { /** @var ?User $postAuthor */ $postAuthor = null; if ($item->authorId !== null && !isset($userCache[$item->authorId])) { @@ -46,31 +39,27 @@ foreach ($allItems as $item) { if ($item instanceof Post) { $attachments = $db->fetchCustom(Attachment::class, 'WHERE post_id = $1', [ $item->id ]); - _view("view_post", [ + return [ + "type" => "post", "post" => $item, "postAuthor" => $postAuthor, "topicAuthor" => $topicAuthor, "attachments" => $attachments, "topic" => $topic, - ]); + ]; } else { - _view("view_topiclog", [ + return [ + "type" => "logMessage", "logMessage" => $item, "postAuthor" => $postAuthor, "topicAuthor" => $topicAuthor, "topic" => $topic, - ]); + ]; } -} - -_view("view_topic_end"); - -if ($topic->isLocked) { - _view("view_topic_locked"); -} elseif ($currentUser) { - _view("form_addpost"); -} else { - _view("view_logintoreply"); -} +}, $allItems); -_view("template_end", [...getThemeAndLangInfo()]); +render("view_topic.twig", [ + "topic" => $topic, + "topicAuthor" => $topicAuthor, + "allItems" => &$allItems, +]); -- cgit v1.2.3