2222use phpMyFAQ \Core \Exception ;
2323use phpMyFAQ \Entity \CommentType ;
2424use phpMyFAQ \Enums \PermissionType ;
25+ use phpMyFAQ \Filter ;
26+ use phpMyFAQ \Pagination ;
2527use phpMyFAQ \Session \Token ;
2628use phpMyFAQ \Twig \Extensions \FaqTwigExtension ;
2729use Symfony \Component \HttpFoundation \Request ;
@@ -43,20 +45,48 @@ public function index(Request $request): Response
4345 {
4446 $ this ->userHasPermission (PermissionType::COMMENT_DELETE );
4547
48+ $ page = Filter::filterVar ($ request ->query ->get (key: 'page ' ), FILTER_VALIDATE_INT );
49+ $ page = max (1 , $ page );
50+
4651 $ comment = $ this ->container ->get (id: 'phpmyfaq.comments ' );
4752
48- $ faqComments = $ comment ->getAllComments ();
49- $ newsComments = $ comment ->getAllComments (CommentType::NEWS );
53+ $ itemsPerPage = 10 ;
54+ $ allFaqComments = $ comment ->getAllComments ();
55+ $ allNewsComments = $ comment ->getAllComments (CommentType::NEWS );
56+
57+ $ faqComments = array_slice ($ allFaqComments , ($ page - 1 ) * $ itemsPerPage , $ itemsPerPage );
58+ $ newsComments = array_slice ($ allNewsComments , ($ page - 1 ) * $ itemsPerPage , $ itemsPerPage );
59+
60+ $ baseUrl = sprintf ('%sadmin/comments?page=%d ' , $ this ->configuration ->getDefaultUrl (), $ page );
61+
62+ $ faqCommentsPagination = new Pagination ([
63+ 'baseUrl ' => $ baseUrl ,
64+ 'total ' => is_countable ($ allFaqComments ) ? count ($ allFaqComments ) : 0 ,
65+ 'perPage ' => $ itemsPerPage ,
66+ ]);
67+
68+ $ newsCommentsPagination = new Pagination ([
69+ 'baseUrl ' => $ baseUrl ,
70+ 'total ' => is_countable ($ allNewsComments ) ? count ($ allNewsComments ) : 0 ,
71+ 'perPage ' => $ itemsPerPage ,
72+ ]);
5073
5174 $ this ->addExtension (new IntlExtension ());
5275 $ this ->addExtension (new AttributeExtension (FaqTwigExtension::class));
53- return $ this ->render ('@admin/content/comments.twig ' , [
54- ...$ this ->getHeader ($ request ),
55- ...$ this ->getFooter (),
56- 'currentLocale ' => $ this ->configuration ->getLanguage ()->getLanguage (),
57- 'faqComments ' => $ faqComments ,
58- 'newsComments ' => $ newsComments ,
59- 'csrfToken ' => Token::getInstance ($ this ->container ->get (id: 'session ' ))->getTokenString ('delete-comment ' ),
60- ]);
76+ return $ this ->render (
77+ file: '@admin/content/comments.twig ' ,
78+ context: [
79+ ...$ this ->getHeader ($ request ),
80+ ...$ this ->getFooter (),
81+ 'currentLocale ' => $ this ->configuration ->getLanguage ()->getLanguage (),
82+ 'faqComments ' => $ faqComments ,
83+ 'newsComments ' => $ newsComments ,
84+ 'faqCommentsPagination ' => $ faqCommentsPagination ->render (),
85+ 'newsCommentsPagination ' => $ newsCommentsPagination ->render (),
86+ 'csrfToken ' => Token::getInstance ($ this ->container ->get (id: 'session ' ))->getTokenString (
87+ page: 'delete-comment ' ,
88+ ),
89+ ],
90+ );
6191 }
6292}
0 commit comments