diff --git a/src/Controller/Blog/CommentAdminController.php b/src/Controller/Blog/CommentAdminController.php new file mode 100644 index 0000000..2b14f7c --- /dev/null +++ b/src/Controller/Blog/CommentAdminController.php @@ -0,0 +1,137 @@ +updateFilters($request, $session); + + $pager = $query + ->orderBy('.id', 'DESC') + ->useFilters($this->filters) + ->paginate($page) + ; + + return $this->render('blog/comment_admin/index.html.twig', [ + 'pager' => $pager, + 'hasFilters' => !empty($this->filters), + ]); + } + + /** + * @Route("/edit/{entity}", name="admin_blog_comment_edit") + */ + public function edit(Entity $entity, EntityManager $entityManager, Request $request): Response + { + $form = $this->createForm(EntityType::class, $entity); + + if ($request->isMethod('POST')) { + $form->handleRequest($request); + + if ($form->isValid()) { + $entityManager->update($entity); + $this->addFlash('success', 'The form is not valid.'); + + return $this->redirectToRoute('admin_blog_comment_edit', [ + 'entity' => $entity->getId(), + ]); + } + $this->addFlash('warning', 'The form is not valid.'); + } + + return $this->render('blog/comment_admin/edit.html.twig', [ + 'form' => $form->createView(), + 'entity' => $entity, + ]); + } + + /** + * @Route("/show/{entity}", name="admin_blog_comment_show") + */ + public function show(Entity $entity): Response + { + return $this->render('blog/comment_admin/show.html.twig', [ + 'entity' => $entity, + ]); + } + + /** + * @Route("/filters", name="admin_blog_comment_filters") + */ + public function filters(Session $session): Response + { + $form = $this->createForm(CommentFilterType::class); + $form->submit($session->get('comment_filter')); + + return $this->render('blog/comment_admin/filters.html.twig', [ + 'form' => $form->createView(), + ]); + } + + /** + * @Route("/delete/{entity}", name="admin_blog_comment_delete", methods={"DELETE"}) + */ + public function delete(Entity $entity, EntityManager $entityManager, Request $request): Response + { + if ($this->isCsrfTokenValid('delete'.$entity->getId(), $request->request->get('_token'))) { + $entityManager->delete($entity); + + $this->addFlash('success', 'The data has been removed.'); + } + + return $this->redirectToRoute('admin_blog_comment_index'); + } + + public function getSection(): string + { + return 'blog_comment'; + } + + protected function updateFilters(Request $request, Session $session) + { + if ($request->query->has('comment_filter')) { + $filters = $request->query->get('comment_filter'); + + if ('0' === $filters) { + $filters = []; + } + } elseif ($session->has('comment_filter')) { + $filters = $session->get('comment_filter'); + } else { + $filters = []; + } + + $form = $this->createForm(CommentFilterType::class); + $form->submit($filters); + + if (empty($filters)) { + $this->filters = $filters; + $session->set('comment_filter', $filters); + } elseif ($form->isValid()) { + $this->filters = $form->getData(); + $session->set('comment_filter', $filters); + } + } +} diff --git a/src/Form/Blog/CommentType.php b/src/Form/Blog/CommentType.php new file mode 100644 index 0000000..dc6f12e --- /dev/null +++ b/src/Form/Blog/CommentType.php @@ -0,0 +1,145 @@ +add( + 'author', + TextType::class, + [ + 'required' => true, + 'label' => 'Auteur', + 'attr' => [ + ], + 'constraints' => [ + new NotBlank(), + ], + ] + ); + + $builder->add( + 'website', + UrlType::class, + [ + 'required' => false, + 'label' => 'Site web', + 'attr' => [ + ], + 'constraints' => [ + new Url(), + ], + ] + ); + + $builder->add( + 'email', + EmailType::class, + [ + 'label' => 'E-mail (non publié)', + 'required' => false, + 'attr' => [ + ], + 'constraints' => [ + new Email(), + ], + ] + ); + + $builder->add( + 'content', + TextareaType::class, + [ + 'label' => 'Commentaire', + 'required' => true, + 'attr' => [ + ], + 'constraints' => [ + new NotBlank(), + ], + ] + ); + + $builder->add( + 'post', + EntityType::class, + [ + 'label' => 'Article', + 'class' => Post::class, + 'choice_label' => 'title', + 'required' => true, + 'multiple' => false, + 'attr' => [ + ], + 'query_builder' => function (EntityRepository $repo) { + return $repo->createQueryBuilder('p') + ->orderBy('p.id', 'DESC') + ; + }, + 'constraints' => [ + new NotBlank(), + ], + ] + ); + + $builder->add( + 'parentComment', + EntityType::class, + [ + 'label' => 'Réponse à', + 'class' => Comment::class, + 'choice_label' => 'author', + 'required' => false, + 'multiple' => false, + 'attr' => [ + ], + 'query_builder' => function (EntityRepository $repo) { + return $repo->createQueryBuilder('c') + ->orderBy('c.id', 'DESC') + ; + }, + 'constraints' => [ + ], + ] + ); + + $builder->add( + 'isActive', + CheckboxType::class, + [ + 'label' => 'En ligne', + 'required' => false, + 'attr' => [ + ], + 'constraints' => [ + ], + ] + ); + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => Comment::class, + ]); + } +} diff --git a/src/Form/Blog/Filter/CommentFilterType.php b/src/Form/Blog/Filter/CommentFilterType.php new file mode 100644 index 0000000..c96efad --- /dev/null +++ b/src/Form/Blog/Filter/CommentFilterType.php @@ -0,0 +1,86 @@ +add( + 'author', + TextType::class, + [ + 'required' => false, + 'label' => 'Auteur', + 'attr' => [ + ], + 'constraints' => [ + ], + ] + ); + + $builder->add( + 'website', + TextType::class, + [ + 'required' => false, + 'label' => 'Site web', + 'attr' => [ + ], + 'constraints' => [ + ], + ] + ); + + $builder->add( + 'email', + TextType::class, + [ + 'label' => 'E-mail (non publié)', + 'required' => false, + 'attr' => [ + ], + 'constraints' => [ + ], + ] + ); + + $builder->add( + 'post', + EntityType::class, + [ + 'label' => 'Article', + 'class' => Post::class, + 'choice_label' => 'title', + 'choice_value' => 'id', + 'required' => false, + 'attr' => [ + ], + 'query_builder' => function (EntityRepository $repo) { + return $repo->createQueryBuilder('p') + ->orderBy('p.id', 'DESC') + ; + }, + 'constraints' => [ + ], + ] + ); + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => null, + 'csrf_protection' => false, + ]); + } +} diff --git a/src/Repository/Blog/CommentRepositoryQuery.php b/src/Repository/Blog/CommentRepositoryQuery.php new file mode 100644 index 0000000..5838af6 --- /dev/null +++ b/src/Repository/Blog/CommentRepositoryQuery.php @@ -0,0 +1,44 @@ + + */ +class CommentRepositoryQuery extends RepositoryQuery +{ + public function __construct(CommentRepository $repository, PaginatorInterface $paginator) + { + parent::__construct($repository, 'c', $paginator); + } + + public function useFilters(array $filters) + { + foreach ($filters as $name => $value) { + if (null === $value) { + continue; + } + + if (is_int($value)) { + $this->andWhere('.'.$name.' = :'.$name); + $this->setParameter(':'.$name, $value); + } elseif (is_string($value)) { + $this->andWhere('.'.$name.' LIKE :'.$name); + $this->setParameter(':'.$name, '%'.$value.'%'); + } else { + if ('post' === $name) { + $this + ->andWhere('.post = :postId') + ->setParameter(':postId', $value->getId()); + } + } + } + + return $this; + } +} diff --git a/templates/blog/category_admin/edit.html.twig b/templates/blog/category_admin/edit.html.twig index b7be271..c5ffc0b 100644 --- a/templates/blog/category_admin/edit.html.twig +++ b/templates/blog/category_admin/edit.html.twig @@ -1,5 +1,7 @@ {% extends '@Core/admin/layout.html.twig' %} +{% block title %}{{ 'Catégories'|trans }} - {{ parent() }}{% endblock %} + {% block body %}
Auteur | +Date | +Statut | +Actions | +
---|---|---|---|
+ + {{ item.author }} + + + Dans {{ item.post.title }} + | ++ + + {{ item.updatedAt|date('d/m/Y H:i') }} + + | ++ + | ++ + + + + + + | +
+
+
+
+
+ Aucun résultat
+
+ |
+