From d81fc881af68819baf70020f21fefe649158cfab Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Sun, 21 Mar 2021 14:41:22 +0100 Subject: [PATCH] count linked objects in merge person side panel --- .../Controller/PersonDuplicateController.php | 26 +++++++++++++++++++ .../views/PersonDuplicate/_sidepane.html.twig | 13 +++++----- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php b/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php index 461475d34..aa2e2768a 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php @@ -16,6 +16,10 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Translation\TranslatorInterface; +use Chill\ActivityBundle\Entity\Activity; +use Chill\DocStoreBundle\Entity\PersonDocument; +use Chill\EventBundle\Entity\Participation; +use Chill\TaskBundle\Entity\SingleTask; class PersonDuplicateController extends Controller { @@ -91,6 +95,9 @@ class PersonDuplicateController extends Controller $person1 = $this->_getPerson($person1_id); $person2 = $this->_getPerson($person2_id); + $person1->counters = $this->_getCounters($person1_id); + $person2->counters = $this->_getCounters($person2_id); + if ($person1 === null) { throw $this->createNotFoundException("Person with id $person1_id not" . " found on this server"); @@ -257,4 +264,23 @@ class PersonDuplicateController extends Controller return [$person1, $person2]; } + + private function _getCounters($id): ?array + { + $em = $this->getDoctrine()->getManager(); + + $nb_activity = $em->getRepository(Activity::class)->findBy(['person'=>$id]); + $nb_document = $em->getRepository(PersonDocument::class)->findBy(['person'=>$id]); + $nb_event = $em->getRepository(Participation::class)->findBy(['person'=>$id]); + $nb_task = $em->getRepository(SingleTask::class)->countByParameters(['person'=>$id]); + $person = $em->getRepository(Person::class)->findOneBy(['id'=>$id]); + + return [ + 'nb_activity' => count($nb_activity), + 'nb_document' => count($nb_document), + 'nb_event' => count($nb_event), + 'nb_task' => $nb_task, + 'nb_addresses' => count($person->getAddresses()) + ]; + } } diff --git a/src/Bundle/ChillPersonBundle/Resources/views/PersonDuplicate/_sidepane.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/PersonDuplicate/_sidepane.html.twig index 972ea212f..e6e294030 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/PersonDuplicate/_sidepane.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/PersonDuplicate/_sidepane.html.twig @@ -35,11 +35,12 @@ {%- macro links(person, options) -%} {% endmacro %} \ No newline at end of file