mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,29 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Controller;
|
||||
|
||||
use Chill\ActivityBundle\Entity\Activity;
|
||||
use Chill\DocStoreBundle\Entity\PersonDocument;
|
||||
use Chill\EventBundle\Entity\Participation;
|
||||
use Chill\PersonBundle\Actions\Remove\PersonMove;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\PersonNotDuplicate;
|
||||
use Chill\PersonBundle\Form\PersonConfimDuplicateType;
|
||||
use Chill\PersonBundle\Form\PersonFindManuallyDuplicateType;
|
||||
use Chill\PersonBundle\Privacy\PrivacyEvent;
|
||||
use Chill\PersonBundle\Repository\PersonNotDuplicateRepository;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
use Chill\PersonBundle\Search\SimilarPersonMatcher;
|
||||
use Chill\TaskBundle\Entity\SingleTask;
|
||||
use http\Exception\InvalidArgumentException;
|
||||
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\PersonBundle\Repository\PersonNotDuplicateRepository;
|
||||
use Chill\TaskBundle\Entity\SingleTask;
|
||||
|
||||
class PersonDuplicateController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
|
||||
*/
|
||||
private $eventDispatcher;
|
||||
|
||||
/**
|
||||
* @var \Chill\PersonBundle\Actions\Remove\PersonMove
|
||||
*/
|
||||
private $personMove;
|
||||
|
||||
/**
|
||||
* @var \Chill\PersonBundle\Repository\PersonRepository
|
||||
*/
|
||||
private $personRepository;
|
||||
|
||||
/**
|
||||
* @var \Chill\PersonBundle\Search\SimilarPersonMatcher
|
||||
*/
|
||||
@@ -34,27 +55,12 @@ class PersonDuplicateController extends Controller
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
/**
|
||||
* @var \Chill\PersonBundle\Repository\PersonRepository
|
||||
*/
|
||||
private $personRepository;
|
||||
|
||||
/**
|
||||
* @var \Chill\PersonBundle\Actions\Remove\PersonMove
|
||||
*/
|
||||
private $personMove;
|
||||
|
||||
/**
|
||||
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
|
||||
*/
|
||||
private $eventDispatcher;
|
||||
|
||||
public function __construct(
|
||||
SimilarPersonMatcher $similarPersonMatcher,
|
||||
TranslatorInterface $translator,
|
||||
PersonRepository $personRepository,
|
||||
PersonMove $personMove,
|
||||
EventDispatcherInterface $eventDispatcher
|
||||
SimilarPersonMatcher $similarPersonMatcher,
|
||||
TranslatorInterface $translator,
|
||||
PersonRepository $personRepository,
|
||||
PersonMove $personMove,
|
||||
EventDispatcherInterface $eventDispatcher
|
||||
) {
|
||||
$this->similarPersonMatcher = $similarPersonMatcher;
|
||||
$this->translator = $translator;
|
||||
@@ -63,29 +69,6 @@ class PersonDuplicateController extends Controller
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
}
|
||||
|
||||
public function viewAction($person_id, PersonNotDuplicateRepository $personNotDuplicateRepository)
|
||||
{
|
||||
$person = $this->_getPerson($person_id);
|
||||
if ($person === null) {
|
||||
throw $this->createNotFoundException("Person with id $person_id not"
|
||||
. " found on this server");
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_DUPLICATE', $person,
|
||||
"You are not allowed to see this person.");
|
||||
|
||||
$duplicatePersons = $this->similarPersonMatcher->
|
||||
matchPerson($person, $personNotDuplicateRepository, 0.5, SimilarPersonMatcher::SIMILAR_SEARCH_ORDER_BY_ALPHABETICAL);
|
||||
|
||||
$notDuplicatePersons = $personNotDuplicateRepository->findNotDuplicatePerson($person);
|
||||
|
||||
return $this->render('ChillPersonBundle:PersonDuplicate:view.html.twig', [
|
||||
'person' => $person,
|
||||
'duplicatePersons' => $duplicatePersons,
|
||||
'notDuplicatePersons' => $notDuplicatePersons,
|
||||
]);
|
||||
}
|
||||
|
||||
public function confirmAction($person1_id, $person2_id, Request $request)
|
||||
{
|
||||
if ($person1_id === $person2_id) {
|
||||
@@ -98,17 +81,20 @@ class PersonDuplicateController extends Controller
|
||||
$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");
|
||||
if (null === $person1) {
|
||||
throw $this->createNotFoundException("Person with id {$person1_id} not"
|
||||
. ' found on this server');
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_DUPLICATE', $person1,
|
||||
"You are not allowed to see this person.");
|
||||
$this->denyAccessUnlessGranted(
|
||||
'CHILL_PERSON_DUPLICATE',
|
||||
$person1,
|
||||
'You are not allowed to see this person.'
|
||||
);
|
||||
|
||||
if ($person2 === null) {
|
||||
throw $this->createNotFoundException("Person with id $person2_id not"
|
||||
. " found on this server");
|
||||
if (null === $person2) {
|
||||
throw $this->createNotFoundException("Person with id {$person2_id} not"
|
||||
. ' found on this server');
|
||||
}
|
||||
|
||||
$form = $this->createForm(PersonConfimDuplicateType::class);
|
||||
@@ -116,10 +102,10 @@ class PersonDuplicateController extends Controller
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$event = new PrivacyEvent($person1, array(
|
||||
$event = new PrivacyEvent($person1, [
|
||||
'element_class' => Person::class,
|
||||
'action' => 'move'
|
||||
));
|
||||
'action' => 'move',
|
||||
]);
|
||||
$event->addPerson($person2);
|
||||
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
|
||||
|
||||
@@ -128,7 +114,8 @@ class PersonDuplicateController extends Controller
|
||||
$connection = $this->getDoctrine()->getConnection();
|
||||
|
||||
$connection->beginTransaction();
|
||||
foreach($sqls as $sql) {
|
||||
|
||||
foreach ($sqls as $sql) {
|
||||
$connection->executeQuery($sql);
|
||||
}
|
||||
$connection->commit();
|
||||
@@ -143,15 +130,68 @@ class PersonDuplicateController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function findManuallyDuplicateAction($person_id, Request $request)
|
||||
{
|
||||
$person = $this->_getPerson($person_id);
|
||||
|
||||
if (null === $person) {
|
||||
throw $this->createNotFoundException("Person with id {$person_id} not"
|
||||
. ' found on this server');
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted(
|
||||
'CHILL_PERSON_DUPLICATE',
|
||||
$person,
|
||||
'You are not allowed to see this person.'
|
||||
);
|
||||
|
||||
$form = $this->createForm(PersonFindManuallyDuplicateType::class);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$person2 = $form->get('person')->getData();
|
||||
|
||||
if (null === $person2) {
|
||||
throw $this->createNotFoundException("Person with id {$person2->getId}() not"
|
||||
. ' found on this server');
|
||||
}
|
||||
|
||||
$direction = $form->get('direction')->getData();
|
||||
|
||||
if ('starting' === $direction) {
|
||||
$params = [
|
||||
'person1_id' => $person->getId(),
|
||||
'person2_id' => $person2->getId(),
|
||||
];
|
||||
} else {
|
||||
$params = [
|
||||
'person1_id' => $person2->getId(),
|
||||
'person2_id' => $person->getId(),
|
||||
];
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('chill_person_duplicate_confirm', $params);
|
||||
}
|
||||
|
||||
return $this->render('ChillPersonBundle:PersonDuplicate:find_manually.html.twig', [
|
||||
'person' => $person,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function notDuplicateAction($person1_id, $person2_id)
|
||||
{
|
||||
[$person1, $person2] = $this->_getPersonsByPriority($person1_id, $person2_id);
|
||||
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_DUPLICATE', $person1,
|
||||
"You are not allowed to see this person.");
|
||||
$this->denyAccessUnlessGranted(
|
||||
'CHILL_PERSON_DUPLICATE',
|
||||
$person1,
|
||||
'You are not allowed to see this person.'
|
||||
);
|
||||
|
||||
$personNotDuplicate = $this->getDoctrine()->getRepository(PersonNotDuplicate::class)
|
||||
->findOneBy(['person1' => $person1, 'person2' => $person2]);
|
||||
->findOneBy(['person1' => $person1, 'person2' => $person2]);
|
||||
|
||||
if (!$personNotDuplicate instanceof PersonNotDuplicate) {
|
||||
$personNotDuplicate = new PersonNotDuplicate();
|
||||
@@ -170,11 +210,14 @@ class PersonDuplicateController extends Controller
|
||||
{
|
||||
[$person1, $person2] = $this->_getPersonsByPriority($person1_id, $person2_id);
|
||||
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_DUPLICATE', $person1,
|
||||
"You are not allowed to see this person.");
|
||||
$this->denyAccessUnlessGranted(
|
||||
'CHILL_PERSON_DUPLICATE',
|
||||
$person1,
|
||||
'You are not allowed to see this person.'
|
||||
);
|
||||
|
||||
$personNotDuplicate = $this->getDoctrine()->getRepository(PersonNotDuplicate::class)
|
||||
->findOneBy(['person1' => $person1, 'person2' => $person2]);
|
||||
->findOneBy(['person1' => $person1, 'person2' => $person2]);
|
||||
|
||||
if ($personNotDuplicate instanceof PersonNotDuplicate) {
|
||||
$this->getDoctrine()->getManager()->remove($personNotDuplicate);
|
||||
@@ -184,54 +227,56 @@ class PersonDuplicateController extends Controller
|
||||
return $this->redirectToRoute('chill_person_duplicate_view', ['person_id' => $person1->getId()]);
|
||||
}
|
||||
|
||||
public function findManuallyDuplicateAction($person_id, Request $request)
|
||||
public function viewAction($person_id, PersonNotDuplicateRepository $personNotDuplicateRepository)
|
||||
{
|
||||
$person = $this->_getPerson($person_id);
|
||||
if ($person === null) {
|
||||
throw $this->createNotFoundException("Person with id $person_id not"
|
||||
. " found on this server");
|
||||
|
||||
if (null === $person) {
|
||||
throw $this->createNotFoundException("Person with id {$person_id} not"
|
||||
. ' found on this server');
|
||||
}
|
||||
|
||||
$this->denyAccessUnlessGranted('CHILL_PERSON_DUPLICATE', $person,
|
||||
"You are not allowed to see this person.");
|
||||
$this->denyAccessUnlessGranted(
|
||||
'CHILL_PERSON_DUPLICATE',
|
||||
$person,
|
||||
'You are not allowed to see this person.'
|
||||
);
|
||||
|
||||
$form = $this->createForm(PersonFindManuallyDuplicateType::class);
|
||||
$duplicatePersons = $this->similarPersonMatcher->
|
||||
matchPerson($person, $personNotDuplicateRepository, 0.5, SimilarPersonMatcher::SIMILAR_SEARCH_ORDER_BY_ALPHABETICAL);
|
||||
|
||||
$form->handleRequest($request);
|
||||
$notDuplicatePersons = $personNotDuplicateRepository->findNotDuplicatePerson($person);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$person2 = $form->get('person')->getData();
|
||||
|
||||
if ($person2 === null) {
|
||||
throw $this->createNotFoundException("Person with id $person2->getId() not"
|
||||
. " found on this server");
|
||||
}
|
||||
|
||||
$direction = $form->get('direction')->getData();
|
||||
|
||||
if ($direction === 'starting') {
|
||||
$params = [
|
||||
'person1_id' => $person->getId(),
|
||||
'person2_id' => $person2->getId(),
|
||||
];
|
||||
} else {
|
||||
$params = [
|
||||
'person1_id' => $person2->getId(),
|
||||
'person2_id' => $person->getId(),
|
||||
];
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('chill_person_duplicate_confirm', $params);
|
||||
}
|
||||
|
||||
return $this->render('ChillPersonBundle:PersonDuplicate:find_manually.html.twig', [
|
||||
return $this->render('ChillPersonBundle:PersonDuplicate:view.html.twig', [
|
||||
'person' => $person,
|
||||
'form' => $form->createView(),
|
||||
'duplicatePersons' => $duplicatePersons,
|
||||
'notDuplicatePersons' => $notDuplicatePersons,
|
||||
]);
|
||||
}
|
||||
|
||||
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()),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* easy getting a person by his id
|
||||
* easy getting a person by his id.
|
||||
*
|
||||
* @param mixed $id
|
||||
*/
|
||||
private function _getPerson($id): ?Person
|
||||
{
|
||||
@@ -252,35 +297,16 @@ class PersonDuplicateController extends Controller
|
||||
$person2 = $this->_getPerson($person2_id);
|
||||
}
|
||||
|
||||
if ($person1 === null) {
|
||||
throw $this->createNotFoundException("Person with id $person1_id not"
|
||||
. " found on this server");
|
||||
if (null === $person1) {
|
||||
throw $this->createNotFoundException("Person with id {$person1_id} not"
|
||||
. ' found on this server');
|
||||
}
|
||||
|
||||
if ($person2 === null) {
|
||||
throw $this->createNotFoundException("Person with id $person2_id not"
|
||||
. " found on this server");
|
||||
if (null === $person2) {
|
||||
throw $this->createNotFoundException("Person with id {$person2_id} not"
|
||||
. ' found on this server');
|
||||
}
|
||||
|
||||
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())
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user