diff options
author | Jonas Kohl | 2024-10-17 10:56:01 +0200 |
---|---|---|
committer | Jonas Kohl | 2024-10-17 10:56:01 +0200 |
commit | fe0f414dc0211a4014581dc03fcfd514ed7ed02d (patch) | |
tree | cd86fc00cd9b7a97eabb9668e0a39e2b4b3e5357 /src/application/actions/viewtopic/get.php | |
parent | e0e89b9fdbf301e0ead944636023947a67aca57d (diff) |
Transition templating to Twig
Diffstat (limited to 'src/application/actions/viewtopic/get.php')
-rw-r--r-- | src/application/actions/viewtopic/get.php | 37 |
1 files changed, 13 insertions, 24 deletions
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, +]); |