From 1a03203d012eb184e1b337e532d166b20cbb505e Mon Sep 17 00:00:00 2001 From: flifloo Date: Sat, 16 Jan 2021 16:04:30 +0100 Subject: [PATCH] Base of admin panel --- src/Controller/AdminController.php | 24 ------------------- src/Controller/CategoryController.php | 7 +++--- src/Controller/CommentController.php | 7 +++--- src/Controller/PostController.php | 11 +++++++++ templates/admin/index.html.twig | 15 +----------- templates/admin/posts.html.twig | 7 ++++++ templates/category/categories.html.twig | 7 ++++++ .../{ => category}/category_summary.html.twig | 0 templates/category/index.html.twig | 20 ---------------- templates/comment/comments.html.twig | 7 ++++++ templates/comment/index.html.twig | 20 ---------------- .../{ => comment}/recent_comment.html.twig | 0 12 files changed, 41 insertions(+), 84 deletions(-) create mode 100644 templates/admin/posts.html.twig create mode 100644 templates/category/categories.html.twig rename templates/{ => category}/category_summary.html.twig (100%) delete mode 100644 templates/category/index.html.twig create mode 100644 templates/comment/comments.html.twig delete mode 100644 templates/comment/index.html.twig rename templates/{ => comment}/recent_comment.html.twig (100%) diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index 4b0934f..953aa55 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -17,28 +17,4 @@ class AdminController extends AbstractController 'controller_name' => 'AdminController', ]); } - - /** - * @Route("/admin/posts", name="posts") - */ - public function posts(): Response - { - - } - - /** - * @Route("/admin/categories", name="categories") - */ - public function categories(): Response - { - - } - - /** - * @Route("/admin/comments", name="comments") - */ - public function comments(): Response - { - - } } diff --git a/src/Controller/CategoryController.php b/src/Controller/CategoryController.php index 76c1de7..46cd11b 100644 --- a/src/Controller/CategoryController.php +++ b/src/Controller/CategoryController.php @@ -10,18 +10,19 @@ use Symfony\Component\Routing\Annotation\Route; class CategoryController extends AbstractController { /** - * @Route("/category", name="category") + * @Route("/admin/categories", name="categories") */ public function index(): Response { - return $this->render('category/index.html.twig', [ + return $this->render('category/categories.html.twig', [ 'controller_name' => 'CategoryController', + 'categories' => $this->getDoctrine()->getRepository(Category::class)->findAll() ]); } public function categorySummary(): Response { - return $this->render('category_summary.html.twig', [ + return $this->render('category/category_summary.html.twig', [ 'controller_name' => 'CategoryController', 'Categories' => array_filter($this->getDoctrine()->getRepository(Category::class)->findAll(), static function ($c) {return count($c->getPosts())>=1;}) ]); diff --git a/src/Controller/CommentController.php b/src/Controller/CommentController.php index d02dc53..cbcb38a 100644 --- a/src/Controller/CommentController.php +++ b/src/Controller/CommentController.php @@ -10,18 +10,19 @@ use Symfony\Component\Routing\Annotation\Route; class CommentController extends AbstractController { /** - * @Route("/comment", name="comment") + * @Route("/admin/comments", name="comments") */ public function index(): Response { - return $this->render('comment/index.html.twig', [ + return $this->render('comment/comments.html.twig', [ 'controller_name' => 'CommentController', + 'comments' => $this->getDoctrine()->getRepository(Comment::class)->findAll() ]); } public function recentComment(): Response { - return $this->render('recent_comment.html.twig', [ + return $this->render('comment/recent_comment.html.twig', [ 'controller_name' => 'CommentController', 'comments' => $this->getDoctrine()->getRepository(Comment::class)->findBy(array('valid' => true), array('createdAt' => 'DESC'), 5, 0) ]); diff --git a/src/Controller/PostController.php b/src/Controller/PostController.php index 01cdf43..18b8cce 100644 --- a/src/Controller/PostController.php +++ b/src/Controller/PostController.php @@ -40,6 +40,17 @@ class PostController extends AbstractController ]); } + /** + * @Route("/admin/posts", name="posts") + */ + public function posts(): Response + { + return $this->render('post/posts.html.twig', [ + 'controller_name' => 'PostController', + 'posts' => $this->getDoctrine()->getRepository(Post::class)->findAll() + ]); + } + private function formGenerator(Post $post) : FormInterface { $comment = new Comment(); diff --git a/templates/admin/index.html.twig b/templates/admin/index.html.twig index 234e045..769c702 100644 --- a/templates/admin/index.html.twig +++ b/templates/admin/index.html.twig @@ -3,18 +3,5 @@ {% block title %}Hello AdminController!{% endblock %} {% block body %} - - -
-

Hello {{ controller_name }}! ✅

- - This friendly message is coming from: - -
+

Admin panel

{% endblock %} diff --git a/templates/admin/posts.html.twig b/templates/admin/posts.html.twig new file mode 100644 index 0000000..2b9eca2 --- /dev/null +++ b/templates/admin/posts.html.twig @@ -0,0 +1,7 @@ +{% extends 'admin/base-admin.html.twig' %} + +{% block title %}Hello AdminController!{% endblock %} + +{% block body %} + +{% endblock %} diff --git a/templates/category/categories.html.twig b/templates/category/categories.html.twig new file mode 100644 index 0000000..2b9eca2 --- /dev/null +++ b/templates/category/categories.html.twig @@ -0,0 +1,7 @@ +{% extends 'admin/base-admin.html.twig' %} + +{% block title %}Hello AdminController!{% endblock %} + +{% block body %} + +{% endblock %} diff --git a/templates/category_summary.html.twig b/templates/category/category_summary.html.twig similarity index 100% rename from templates/category_summary.html.twig rename to templates/category/category_summary.html.twig diff --git a/templates/category/index.html.twig b/templates/category/index.html.twig deleted file mode 100644 index 126e408..0000000 --- a/templates/category/index.html.twig +++ /dev/null @@ -1,20 +0,0 @@ -{% extends 'base.html.twig' %} - -{% block title %}Hello CategoryController!{% endblock %} - -{% block body %} - - -
-

Hello {{ controller_name }}! ✅

- - This friendly message is coming from: - -
-{% endblock %} diff --git a/templates/comment/comments.html.twig b/templates/comment/comments.html.twig new file mode 100644 index 0000000..2b9eca2 --- /dev/null +++ b/templates/comment/comments.html.twig @@ -0,0 +1,7 @@ +{% extends 'admin/base-admin.html.twig' %} + +{% block title %}Hello AdminController!{% endblock %} + +{% block body %} + +{% endblock %} diff --git a/templates/comment/index.html.twig b/templates/comment/index.html.twig deleted file mode 100644 index 64bed2e..0000000 --- a/templates/comment/index.html.twig +++ /dev/null @@ -1,20 +0,0 @@ -{% extends 'base.html.twig' %} - -{% block title %}Hello CommentController!{% endblock %} - -{% block body %} - - -
-

Hello {{ controller_name }}! ✅

- - This friendly message is coming from: - -
-{% endblock %} diff --git a/templates/recent_comment.html.twig b/templates/comment/recent_comment.html.twig similarity index 100% rename from templates/recent_comment.html.twig rename to templates/comment/recent_comment.html.twig