From 08bf5f9922b6dfe35e975c640624fb3230800f66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 9 Sep 2021 16:53:48 +0200 Subject: [PATCH] [person duplicate] fix direction in page confirm --- .../Controller/PersonDuplicateController.php | 39 ++++++++++++------- .../Resources/config/routing.yml | 2 +- .../views/PersonDuplicate/confirm.html.twig | 19 +++++---- .../views/PersonDuplicate/view.html.twig | 6 +-- 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php b/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php index 0d46055ac..bdd26f717 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php @@ -83,11 +83,12 @@ class PersonDuplicateController extends Controller ]); } - public function confirmAction($person1_id, $person2_id, Request $request) + public function confirmAction($personIdFrom, $personIdTo, Request $request) { - [$person1, $person2] = $this->_getPersonsByPriority($person1_id, $person2_id); + $personFrom = $this->personRepository->find($personIdFrom); + $personTo = $this->personRepository->find($personIdTo); - $this->denyAccessUnlessGranted('CHILL_PERSON_DUPLICATE', $person1, + $this->denyAccessUnlessGranted('CHILL_PERSON_DUPLICATE', $personFrom, "You are not allowed to see this person."); $form = $this->createForm(PersonConfimDuplicateType::class); @@ -95,14 +96,14 @@ class PersonDuplicateController extends Controller $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $event = new PrivacyEvent($person1, array( + $event = new PrivacyEvent($personFrom, array( 'element_class' => Person::class, 'action' => 'move' )); - $event->addPerson($person2); + $event->addPerson($personTo); $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); - $sqls = $this->personMove->getSQL($person2, $person1); + $sqls = $this->personMove->getSQL($personFrom, $personTo); $connection = $this->getDoctrine()->getConnection(); @@ -114,17 +115,17 @@ class PersonDuplicateController extends Controller $this->addFlash('success', $this->translator->trans('The de-duplicate operation success')); - return $this->redirectToRoute('chill_person_duplicate_view', ['person_id' => $person1->getId()]); + return $this->redirectToRoute('chill_person_duplicate_view', ['person_id' => $personTo->getId()]); } return $this->render('ChillPersonBundle:PersonDuplicate:confirm.html.twig', [ - 'person' => $person1, - 'person2' => $person2, + 'personFrom' => $personFrom, + 'personTo' => $personTo, 'form' => $form->createView(), ]); } - public function notDuplicateAction($person1_id, $person2_id) + public function notDuplicateAction($person1_id, $person2_id, Request $request) { [$person1, $person2] = $this->_getPersonsByPriority($person1_id, $person2_id); @@ -144,10 +145,14 @@ class PersonDuplicateController extends Controller $this->getDoctrine()->getManager()->flush(); } + if ($request->query->has('returnPath')) { + return $this->redirect($request->query->get('returnPath')); + } + return $this->redirectToRoute('chill_person_duplicate_view', ['person_id' => $person1->getId()]); } - public function removeNotDuplicateAction($person1_id, $person2_id) + public function removeNotDuplicateAction($person1_id, $person2_id, Request $request) { [$person1, $person2] = $this->_getPersonsByPriority($person1_id, $person2_id); @@ -162,6 +167,10 @@ class PersonDuplicateController extends Controller $this->getDoctrine()->getManager()->flush(); } + if ($request->query->has('returnPath')) { + return $this->redirect($request->query->get('returnPath')); + } + return $this->redirectToRoute('chill_person_duplicate_view', ['person_id' => $person1->getId()]); } @@ -198,13 +207,13 @@ class PersonDuplicateController extends Controller if ($direction === 'starting') { $params = [ - 'person1_id' => $person->getId(), - 'person2_id' => $person2->getId(), + 'personIdFrom' => $person->getId(), + 'personIdTo' => $person2->getId(), ]; } else { $params = [ - 'person1_id' => $person2->getId(), - 'person2_id' => $person->getId(), + 'personIdFrom' => $person2->getId(), + 'personIdTo' => $person->getId(), ]; } diff --git a/src/Bundle/ChillPersonBundle/Resources/config/routing.yml b/src/Bundle/ChillPersonBundle/Resources/config/routing.yml index 856c76596..fc7aac239 100644 --- a/src/Bundle/ChillPersonBundle/Resources/config/routing.yml +++ b/src/Bundle/ChillPersonBundle/Resources/config/routing.yml @@ -94,7 +94,7 @@ chill_person_duplicate_view: controller: Chill\PersonBundle\Controller\PersonDuplicateController::viewAction chill_person_duplicate_confirm: - path: /{_locale}/person/{person1_id}/duplicate/{person2_id}/confirm + path: /{_locale}/person/{personIdFrom}/duplicate/{personIdTo}/confirm controller: Chill\PersonBundle\Controller\PersonDuplicateController::confirmAction chill_person_duplicate_not_duplicate: diff --git a/src/Bundle/ChillPersonBundle/Resources/views/PersonDuplicate/confirm.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/PersonDuplicate/confirm.html.twig index d7cc55950..0da9b61f7 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/PersonDuplicate/confirm.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/PersonDuplicate/confirm.html.twig @@ -3,8 +3,7 @@ {% set activeRouteKey = 'chill_person_duplicate' %} {% import '@ChillPerson/PersonDuplicate/_sidepane.html.twig' as sidepane %} -{% block title %}{{ 'Person duplicate'|trans|capitalize ~ ' ' ~ person.firstName|capitalize ~ -' ' ~ person.lastName }}{% endblock %} +{% block title %}{{ 'Person duplicate'|trans|capitalize ~ ' ' ~ personFrom|chill_entity_render_string }}{% endblock %} {% block content %}