Commit 2f7305fd authored by VoidOutput's avatar VoidOutput Committed by Emma

Recents comments for a given forum

parent e00c6f85
Pipeline #52486726 passed with stage
in 58 seconds
......@@ -36,6 +36,13 @@ delete_forum:
path: /f/{forum_name}/delete
methods: [GET, POST]
forum_comments:
controller: App\Controller\ForumController::comments
defaults: { page: 1 }
path: /f/{forum_name}/comments/{page}
methods: [GET]
requirements: { page: \d+ }
forum_appearance:
controller: App\Controller\ForumController::appearance
path: /f/{forum_name}/appearance
......
......@@ -16,6 +16,7 @@ use App\Form\Model\ForumWebhookData;
use App\Form\Model\ModeratorData;
use App\Form\ModeratorType;
use App\Form\PasswordConfirmType;
use App\Repository\CommentRepository;
use App\Repository\ForumBanRepository;
use App\Repository\ForumCategoryRepository;
use App\Repository\ForumLogEntryRepository;
......@@ -202,6 +203,13 @@ final class ForumController extends AbstractController {
]);
}
public function comments(CommentRepository $comments, Forum $forum, int $page): Response {
return $this->render('forum/comments.html.twig', [
'comments' => $comments->findRecentPaginatedInForum($forum, $page),
'forum' => $forum,
]);
}
/**
* @IsGranted("ROLE_USER")
*
......
......@@ -3,6 +3,7 @@
namespace App\Repository;
use App\Entity\Comment;
use App\Entity\Forum;
use App\Entity\Submission;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;
......@@ -60,6 +61,30 @@ class CommentRepository extends ServiceEntityRepository {
return $pager;
}
/**
* @param Forum $forum
* @param int $page
* @param int $maxPerPage
*
* @return Pagerfanta|Comment[]
*/
public function findRecentPaginatedInForum(Forum $forum, int $page, int $maxPerPage = 25) {
$query = $this->createQueryBuilder('c')
->join('c.submission', 's')
->where('s.forum = :forum')
->setParameter('forum', $forum)
->andWhere('c.softDeleted = FALSE')
->orderBy('c.id', 'DESC');
$pager = new Pagerfanta(new DoctrineORMAdapter($query, false, false));
$pager->setMaxPerPage($maxPerPage);
$pager->setCurrentPage($page);
$this->hydrateComments(\iterator_to_array($pager));
return $pager;
}
private function hydrateComments(array $comments): void {
// hydrate parent and parent's author
$this->createQueryBuilder('c')
......
......@@ -73,6 +73,11 @@
{# sorted nav items #}
{% with { items: {} } %}
{% set item %}
<li><a href="{{ path('forum_comments', {forum_name: forum.name}) }}">{{ 'nav.recent_comments'|trans }}</a></li>
{% endset %}
{% set items = items|merge({('nav.recent_comments'|trans): item}) %}
{% set item %}
<li><a href="{{ path('forum_bans', {forum_name: forum.name}) }}">{{ 'nav.bans'|trans }}</a></li>
{% endset %}
......
{% extends 'forum/base.html.twig' %}
{% from 'comment/_macros.html.twig' import comment %}
{% block page_classes 'comment-list-page' %}
{% block title 'title.recent_comments_forum'|trans({'%forum%': '/f/'~forum.name}) %}
{% block head %}
{{ include('_includes/meta_pagination.html.twig', {pager: comments}, with_context=false) }}
{% endblock %}
{% block body %}
<h1 class="page-heading">{{ 'title.recent_comments_forum'|trans({
'%forum%': '<a href="%s">/f/%s</a>'|format(path('forum', {forum_name: forum.name})|e, forum.name|e)
})|raw }}</h1>
{% if comments|length > 0 %}
{% for comment in comments %}
{{ comment(comment, {show_context: true}) }}
{% endfor %}
{% else %}
<p><small class="dimmed">{{ 'flash.no_entries_to_display'|trans }}</small></p>
{% endif %}
{{ include('_includes/pagination.html.twig', {pager: comments}, with_context=false) }}
{% endblock %}
......@@ -385,6 +385,7 @@ nav:
webhooks: Webhooks
add_webhook: Add webhook
hidden_forums: Hidden forums
recent_comments: Recent comments
placeholder:
default: (default)
......@@ -484,6 +485,7 @@ title:
block_list: Block list
blocking_user: Blocking %user%
recent_comments: Recent comments
recent_comments_forum: Recent comments in %forum%
history_for_theme: Showing history for theme %theme%
viewing_theme_source: Viewing source of %theme%
messages: Messages
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment