diff --git a/src/Bundle/ChillPersonBundle/.editorconfig b/src/Bundle/ChillPersonBundle/.editorconfig new file mode 100644 index 000000000..d769b46a4 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/.editorconfig @@ -0,0 +1,19 @@ +; top-most EditorConfig file +root = true + +; Unix-style newlines +[*] +charset = utf-8 +end_of_line = LF +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{php,html,twig}] +indent_style = space +indent_size = 4 + +[*.md] +max_line_length = 80 + +[COMMIT_EDITMSG] +max_line_length = 0 diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php b/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php index 6263cd13f..461475d34 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonDuplicateController.php @@ -7,6 +7,7 @@ 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\PersonRepository; use Chill\PersonBundle\Search\SimilarPersonMatcher; @@ -83,10 +84,25 @@ class PersonDuplicateController extends Controller public function confirmAction($person1_id, $person2_id, Request $request) { - [$person1, $person2] = $this->_getPersonsByPriority($person1_id, $person2_id); + if ($person1_id === $person2_id) { + throw new InvalidArgumentException('Can not merge same person'); + } + + $person1 = $this->_getPerson($person1_id); + $person2 = $this->_getPerson($person2_id); + + if ($person1 === null) { + 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."); + "You are not allowed to see this person."); + + if ($person2 === null) { + throw $this->createNotFoundException("Person with id $person2_id not" + . " found on this server"); + } $form = $this->createForm(PersonConfimDuplicateType::class); @@ -94,8 +110,8 @@ class PersonDuplicateController extends Controller if ($form->isSubmitted() && $form->isValid()) { $event = new PrivacyEvent($person1, array( - 'element_class' => Person::class, - 'action' => 'move' + 'element_class' => Person::class, + 'action' => 'move' )); $event->addPerson($person2); $this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event); @@ -161,6 +177,52 @@ class PersonDuplicateController extends Controller return $this->redirectToRoute('chill_person_duplicate_view', ['person_id' => $person1->getId()]); } + public function findManuallyDuplicateAction($person_id, Request $request) + { + $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."); + + $form = $this->createForm(PersonFindManuallyDuplicateType::class); + + $form->handleRequest($request); + + 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', [ + 'person' => $person, + 'form' => $form->createView(), + ]); + } + /** * easy getting a person by his id */ diff --git a/src/Bundle/ChillPersonBundle/Form/PersonFindManuallyDuplicateType.php b/src/Bundle/ChillPersonBundle/Form/PersonFindManuallyDuplicateType.php new file mode 100644 index 000000000..0a91e8fc6 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Form/PersonFindManuallyDuplicateType.php @@ -0,0 +1,40 @@ +add('person', PickPersonType::class, [ + 'label' => 'Find duplicate', + 'mapped' => false, + ]) + ->add('direction', ChoiceType::class, [ + 'choices' => [ + 'Starting' => 'starting', + 'Arrival' => 'arrival', + ], + ]) + ; + } + + /** + * @return string + */ + public function getBlockPrefix() + { + return 'chill_personbundle_person_find_manually_duplicate'; + } +} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/PersonDuplicate/confirm.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/PersonDuplicate/confirm.html.twig index f6155eead..56b1a6837 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/PersonDuplicate/confirm.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/PersonDuplicate/confirm.html.twig @@ -21,7 +21,7 @@