diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseCommentController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseCommentController.php new file mode 100644 index 000000000..c5b8ed878 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseCommentController.php @@ -0,0 +1,86 @@ +setAccompanyingPeriod($accompanyingCourse); + + $form = $this->createCommentForm($newComment, 'new'); + + if ($request->query->has('edit')) { + foreach ($accompanyingCourse->getComments() as $comment) { + if ($comment->getId() === $request->query->getInt('edit')) { + $editForm = $this->createCommentForm($comment, 'edit'); + $commentEditId = $comment->getId(); + } + } + $pinnedComment = $accompanyingCourse->getPinnedComment(); + if ($pinnedComment->getId() === $request->query->getInt('edit')) { + $editForm = $this->createCommentForm($pinnedComment, 'edit'); + $commentEditId = $pinnedComment->getId(); + } + } + + if ($request->getMethod() === Request::METHOD_POST) { + if (array_key_exists('edit', $request->request->all()[$editForm->getName()])) { + $currentForm = $editForm->handleRequest($request); + $isEditingNew = false; + } else { + $currentForm = $form->handleRequest($request); + $isEditingNew = true; + } + + if ($currentForm->isSubmitted() && $currentForm->isValid()) { + $em = $this->getDoctrine()->getManager(); + if ($isEditingNew) { + $em->persist($newComment); + } + $em->flush(); + } + + return $this->redirectToRoute('chill_person_accompanying_period_comment_list', [ + 'accompanying_period_id' => $accompanyingCourse->getId() + ]); + } + + return $this->render('@ChillPerson/AccompanyingCourse/comment_list.html.twig', [ + 'accompanyingCourse' => $accompanyingCourse, + 'form' => $form->createView(), + 'edit_form' => isset($editForm) ? $editForm->createView() : null, + 'commentEditId' => $commentEditId ?? null, + ]); + } + + private function createCommentForm(AccompanyingPeriod\Comment $comment, string $step): FormInterface + { + $form = $this->createForm(AccompanyingCourseCommentType::class, $comment); + + if ('edit' === $step) { + $form->add('edit', HiddenType::class, ['mapped' => false ]); + } + + return $form; + } +} diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php index 78f0bad7e..7d0e841cf 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseController.php @@ -14,7 +14,6 @@ namespace Chill\PersonBundle\Controller; use Chill\ActivityBundle\Entity\Activity; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Person; -use Chill\PersonBundle\Form\AccompanyingCourseCommentType; use Chill\PersonBundle\Form\AccompanyingCourseType; use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; @@ -110,34 +109,6 @@ class AccompanyingCourseController extends Controller ]); } - /** - * Comments page of Accompanying Course section. - * - * @Route("/{_locale}/parcours/{accompanying_period_id}/comments", name="chill_person_accompanying_period_comment_list") - * @ParamConverter("accompanyingCourse", options={"id": "accompanying_period_id"}) - */ - public function commentAction(AccompanyingPeriod $accompanyingCourse, Request $request): Response - { - $comment = new AccompanyingPeriod\Comment(); - - $form = $this->createForm(AccompanyingCourseCommentType::class, $comment, []); - $form->handleRequest($request); - - if ($form->isSubmitted() && $form->isValid()) { - $em = $this->getDoctrine()->getManager(); - - $em->persist($comment); - $em->flush(); - - return $this->redirectToRoute($route); - } - - return $this->render('@ChillPerson/AccompanyingCourse/comment_list.html.twig', [ - 'accompanyingCourse' => $accompanyingCourse, - 'form' => $form->createView(), - ]); - } - /** * Edit page of Accompanying Course section. * diff --git a/src/Bundle/ChillPersonBundle/Menu/AccompanyingCourseMenuBuilder.php b/src/Bundle/ChillPersonBundle/Menu/AccompanyingCourseMenuBuilder.php index 6c34c8a2e..60455b201 100644 --- a/src/Bundle/ChillPersonBundle/Menu/AccompanyingCourseMenuBuilder.php +++ b/src/Bundle/ChillPersonBundle/Menu/AccompanyingCourseMenuBuilder.php @@ -73,14 +73,12 @@ class AccompanyingCourseMenuBuilder implements LocalMenuBuilderInterface ], ]) ->setExtras(['order' => 40]); - /* $menu->addChild($this->translator->trans('Accompanying Course Comment'), [ 'route' => 'chill_person_accompanying_period_comment_list', 'routeParameters' => [ 'accompanying_period_id' => $period->getId(), ], ]) ->setExtras(['order' => 50]); - */ $workflow = $this->registry->get($period, 'accompanying_period_lifecycle'); diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/comment_list.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/comment_list.html.twig index 2238b152b..9fc9a1c77 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/comment_list.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourse/comment_list.html.twig @@ -1,63 +1,92 @@ {% extends '@ChillPerson/AccompanyingCourse/layout.html.twig' %} +{% block title %} + {{ 'Accompanying Course Comment list'|trans }} +{% endblock %} + {% macro show_comment(comment, options) %}
{{ comment.content }}+
{{ comment.content|chill_markdown_to_html }}
{{ block('title') }}
- ---
-
- {#
-
- #}
-
-
- - {{ form_end(form) }} -{{ 'Write a new comment'|trans }}
+ {{ _self.form_comment('new', form) }}