src/Controller/PersonController.php line 682

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Person;
  4. use App\Entity\PersonLink;
  5. use App\Entity\PersonReference;
  6. use App\Entity\Reference;
  7. use App\Entity\User;
  8. use App\Form\PersonFormType;
  9. use App\Helper\CompareHelper;
  10. use App\Logic\Leecher;
  11. use App\Logic\SyntaxLogic;
  12. use App\Logic\TreeLogic;
  13. use App\Repository\BibleBooksRepository;
  14. use App\Repository\FolkRepository;
  15. use App\Repository\PersonLinkRepository;
  16. use App\Repository\PersonRepository;
  17. use App\Service\UploaderHelper;
  18. use App\Validator\UncertainNumberValidator;
  19. use Doctrine\Common\Collections\ArrayCollection;
  20. use Doctrine\ORM\EntityManager;
  21. use Doctrine\ORM\EntityManagerInterface;
  22. use Knp\Component\Pager\PaginatorInterface;
  23. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  24. use Symfony\Component\HttpFoundation\File\UploadedFile;
  25. use Symfony\Component\HttpFoundation\Request;
  26. use Symfony\Component\Routing\Annotation\Route;
  27. use Symfony\Component\Routing\RouterInterface;
  28. use Symfony\Component\Validator\Constraints\File;
  29. use Symfony\Component\Validator\Constraints\NotBlank;
  30. use Symfony\Component\Validator\ConstraintViolation;
  31. use Symfony\Component\Validator\Validator\ValidatorInterface;
  32. class PersonController extends BaseController
  33. {
  34.     /**
  35.      * @var PersonRepository
  36.      */
  37.     private $personRepository;
  38.     /**
  39.      * @var BibleBooksRepository
  40.      */
  41.     private $bibleBooksRepository;
  42.     /**
  43.      * @var RouterInterface
  44.      */
  45.     private $router;
  46.     /**
  47.      * @var FolkRepository
  48.      */
  49.     private $folkRepository;
  50.     /**
  51.      * @var PersonLinkRepository
  52.      */
  53.     private $personLinkRepository;
  54.     public function __construct(BibleBooksRepository $bibleBooksRepositoryPersonRepository $personRepository,
  55.         FolkRepository $folkRepositoryPersonLinkRepository $personLinkRepositoryRouterInterface $router)
  56.     {
  57.         $this->personRepository $personRepository;
  58.         $this->bibleBooksRepository $bibleBooksRepository;
  59.         $this->router $router;
  60.         $this->folkRepository $folkRepository;
  61.         $this->personLinkRepository $personLinkRepository;
  62.     }
  63.     /**
  64.      * @Route("/persons", name="persons_list")
  65.      */
  66.     public function list(Request $requestPaginatorInterface $paginator)
  67.     {
  68.         $sort = ['field' => 'p.name''direction' => 'asc'];
  69.         $q $request->query->get('q');
  70.         $queryBuilder =  $this->personRepository->filterByUser('p'$this->getUser());
  71.         $queryBuilder $this->personRepository->addSearchQuery($queryBuilder'p'$qfalse);
  72.         $pagination $paginator->paginate(
  73.             $queryBuilder/* query NOT result */
  74.             $request->query->getInt('page'1)/*page number*/,
  75.             20/*limit per page*/, [
  76.                 'defaultSortFieldName' => $sort['field'],
  77.                 'defaultSortDirection' => $sort['direction'],
  78.             ]
  79.         );
  80.         $pagination->setCustomParameters([
  81.             'align' => 'left'# center|right (for template: twitter_bootstrap_v4_pagination and foundation_v6_pagination)
  82.             'size' => 'small'# small|large (for template: twitter_bootstrap_v4_pagination)
  83.             'style' => 'bottom',
  84.             'span_class' => 'whatever',
  85.         ]);
  86.         $pagination->setPageRange(1);
  87.        /* $p = $this->personRepository->findOneBy(['id'=>3]);
  88.         //$p->getDifference($p->getFather());
  89.         $compareHelper = new CompareHelper();
  90.         $changes = [];
  91.         foreach($p->getUpdates() as $update) {
  92.             $changes[$update->getId()] = $compareHelper->cmp($p, $update);
  93.         }
  94.         dd($changes);*/
  95.         return $this->render(
  96.             'person/list.html.twig', [
  97.             'pagination' => $pagination,
  98.         ]);
  99.     }
  100.     /**
  101.      * @Route("/person/test", name="person_test")
  102.      */
  103.     public function test() {
  104.         dd("test");
  105.     }
  106.     /**
  107.      * @Route ("/leech", name ="leech")
  108.      * @IsGranted("ROLE_ADMIN")
  109.      */
  110.     public function leech(EntityManagerInterface $emLeecher $leecher)
  111.     {
  112.         //$leecher->leechLocations($em);
  113.         $leecher->leechFolks($em);
  114.         //$leecher->leechPersons($em);
  115.     }
  116.     /**
  117.      * @Route ("/person/recalc/ages", name ="recalc_ages")
  118.      * @IsGranted("ROLE_ADMIN")
  119.      */
  120.     public function recalcAges(EntityManagerInterface $emTreeLogic $treeLogic)
  121.     {
  122.         $treeLogic->estimateAgesAction($em$this->getUser());
  123.     }
  124.     /**
  125.      * @Route ("/person/recalc/tree", name ="recalc_tree")
  126.      * @IsGranted("ROLE_ADMIN")
  127.      */
  128.     public function recalcTree(EntityManagerInterface $emTreeLogic $treeLogic)
  129.     {
  130.         $treeLogic->calcLeafAction($em$this->getUser());
  131.     }
  132.     /**
  133.      * @Route ("/person/recalc/gender", name ="recalc_gender")
  134.      * @IsGranted("ROLE_ADMIN")
  135.      */
  136.     public function recalcGender(EntityManagerInterface $emSyntaxLogic $syntaxLogic)
  137.     {
  138.         $syntaxLogic->genderHelper($em);
  139.     }
  140.     /**
  141.      * @Route ("/person/recalc/treesyntax", name ="recalc_tree_syntax")
  142.      * @IsGranted("ROLE_ADMIN")
  143.      */
  144.     public function recalcChildren(EntityManagerInterface $emSyntaxLogic $syntaxLogic)
  145.     {
  146.         $syntaxLogic->childrenHelper($em);
  147.     }
  148.     /**
  149.      * @Route ("/person/recalc/folks", name ="recalc_folks")
  150.      * @IsGranted("ROLE_ADMIN")
  151.      */
  152.     public function recalcFolks(EntityManagerInterface $emSyntaxLogic $syntaxLogic)
  153.     {
  154.         $syntaxLogic->folkHelper($em);
  155.     }
  156.     /**
  157.      * @Route ("/person/new", name ="add_person")
  158.      * @IsGranted("ROLE_EDIT_ENTITY")
  159.      */
  160.     public function new(EntityManagerInterface $emRequest $requestUploaderHelper $uploaderHelperTreeLogic $treeLogicValidatorInterface $validator)
  161.     {
  162.         $user $this->getUser();
  163.         $form $this->createForm(PersonFormType::class , null, [
  164.             'user' => $user,
  165.         ]);
  166.         $form->handleRequest($request);
  167.         if($form->isSubmitted() && $form->isValid()) {
  168.             /** @var Person $person */
  169.             $person $form->getData();
  170.             /** @var UploadedFile $uploadedFile */
  171.             $uploadedFile =  $form['imageFile']->getData();
  172.             if ($uploadedFile) {
  173.                 $violations $validator->validate(
  174.                     $uploadedFile, [
  175.                         new NotBlank(
  176.                             ['Please select a File']
  177.                         ) ,
  178.                         new File([
  179.                             'maxSize' => '2M',
  180.                             'mimeTyp es' => [
  181.                                 'image/*',
  182.                             ],
  183.                         ]),
  184.                     ]
  185.                 );
  186.                 if($violations->count()>0) {
  187.                     /** @var ConstraintViolation $violation */
  188.                     $violation $violations[0];
  189.                     $this->addFlash('error'$violation->getMessage());
  190.                     return $this->redirectToRoute('add_person', [
  191.                     ]);
  192.                 }
  193.                 $newFilename $uploaderHelper->uploadPersonImage($uploadedFile);
  194.                 $person->setImage($newFilename);
  195.             }
  196.             $person->setOwner($user);
  197.             $user->countChange(User::PERSON);
  198.             $em->persist($user);
  199.             if (!in_array('ROLE_ACCEPT_CHANGES'$user->getRoles() )) {
  200.              /*   $change = new EntityChange();
  201.                 $change->setChangedBy($user)->setModificationType('new');//->setPerson($person);
  202.                 $person->addChange($change);
  203.                 $person->setUpdateOf($change);*/
  204.                 $person->setApproved(false);
  205.                 $em->persist($person);
  206.               //  $em->persist($change);
  207.             } else {
  208.                 $person->setApproved(true);
  209.                 $em->persist($person);
  210.             }
  211.             $em->flush();
  212.     // TODO put in again        $treeLogic->calcLeafAction($em);
  213.         //    $treeLogic->estimateAgesAction($em, $this->getUser());
  214.             $this->addFlash('success''Person created');
  215.             //return $this->redirectToRoute('admin_person_list');
  216.             return $this->redirectToRoute('person_edit', [
  217.                 'id' => $person->getId(),
  218.             ]);
  219.         }
  220.         return $this->render('person/new.html.twig', [
  221.             'personForm' => $form->createView(),
  222.         ]);
  223.     }
  224.     /**
  225.      * @Route ("/person/{id}/delete", name="person_delete")
  226.      * @IsGranted("ROLE_EDIT_ENTITY", subject="person")
  227.      */
  228.     public function delete(Person $personRequest $request)
  229.     {
  230.         $user $this->getUser();
  231.         $accceptsChanges $user->acceptsChanges();
  232.         $deleteOwnUnaccepted = !$person->getApproved() && $person->getOwner() == $user;
  233.         if($accceptsChanges || $deleteOwnUnaccepted){
  234.             $person->PrepareDelete($user$this->em);
  235.             $this->em->persist($person);
  236.             $this->em->remove($person);
  237.         } else {
  238.             $person->setTaggedForDeleteBy($user);
  239.             $this->em->persist($person);
  240.         }
  241.         $this->em->flush();
  242.         return $this->redirectToRoute('persons_list', [
  243.         ]);
  244.     }
  245.     /**
  246.      * @Route ("/person/{id}/deny", name="person_deny")
  247.      * @IsGranted("ROLE_ACCEPT_CHANGES", subject="person")
  248.      * /
  249.     public function deny(Person $person, EntityManagerInterface $em)
  250.     {
  251.         foreach ($person->getChanges() as $change) {
  252.            if($change->getModificationType() == "new") {
  253.                $em->remove($change);
  254.                $person->removeChange($change);
  255.                $em->remove($person);
  256.                $em->flush();
  257.                $this->addFlash('success', 'Person removed');
  258.                return $this->redirectToRoute('persons_list', [
  259.                ]);
  260.            }
  261.         }
  262.         $this->addFlash('success', 'Person reset');
  263.         return $this->redirectToRoute('person_edit', [
  264.             'id' => $person->getId(),
  265.         ]);
  266.     }
  267.     /**
  268.      * @Route ("/person/{id}/accept", name="person_accept")
  269.      * @IsGranted("ROLE_ACCEPT_CHANGES", subject="person")
  270.      * /
  271.     public function accept(Person $person, EntityManagerInterface $em)
  272.     {
  273.         foreach ($person->getChanges() as $change) {
  274.             if($change->getModificationType() == "new") {
  275.                 $em->remove($change);
  276.                 $person->removeChange($change);
  277.                 $person->setApproved(true);
  278.                 $em->persist($person);
  279.                 $em->flush();
  280.                 $this->addFlash('success', 'new Person accepted');
  281.                 break;
  282.             }
  283.         }
  284.         return $this->redirectToRoute('person_edit', [
  285.             'id' => $person->getId(),
  286.         ]);
  287.     }*/
  288.     /**
  289.      * @Route ("/person/{id}/edit", name="person_edit")
  290.      * @IsGranted("ROLE_EDIT_ENTITY", subject="person")
  291.      */
  292.     public function edit(Person $personRequest $requestEntityManagerInterface $emUploaderHelper $uploaderHelper,
  293.         UncertainNumberValidator $uncertainNumberValidatorTreeLogic $treeLogic)
  294.     {
  295.         $user $this->getUser();
  296.         $person $person->getUpdate($user);
  297.         if ($request->getMethod() === 'POST' && $request->get('person_form')) {
  298.             $cloneNeeded $person->isCloneNeeded($user);
  299.             if($cloneNeeded)
  300.             {
  301.                 $personClone = clone $this->personRepository->find($request->get('id'));
  302.                 $personClone->setUpdateOf($person);
  303.                 $personClone->setApproved(false);
  304.                 $personClone->setOwner($user);
  305.                /* $referenceList = $person->getReferenceList();
  306.                 /** @var PersonReference $reference * /
  307.                 foreach ($referenceList as $reference){
  308.                     $referenceClone = clone($reference);
  309.                     $personClone->addPersonReference($referenceClone);
  310.                     $em->persist();
  311.                 }*/
  312.                 $em->persist($personClone);
  313.                 $em->flush();
  314.                 $person $personClone;
  315.             }
  316.         }
  317.         $form $this->createForm(PersonFormType::class, $person,
  318.             [
  319.                 'user' => $user,
  320.             ]
  321.         );
  322.         $form->handleRequest($request);
  323.         if($form->isSubmitted() && $form->isValid()) {
  324. // new
  325.            /* if (!$this->isGranted('ROLE_MANAGER', $this->getUser())) {
  326.                 $this->CheckChanges($old, $windingWorkstepForm, $em, 'windingWorkstep', $article->getWindingWorkstep());
  327.             }*/
  328.             /** @var UploadedFile $uploadedFile */
  329.             $uploadedFile =  $form['imageFile']->getData();
  330.             if($uploadedFile) {
  331.                 $newFilename $uploaderHelper->uploadPersonImage($uploadedFile$person->getImage());
  332.                 $person->setImage($newFilename);
  333.             }
  334.             $uow $em->getUnitOfWork();
  335.             $uow->computeChangeSet($em->getClassMetadata(get_class($person)), $form->getViewData());
  336.             $changeSet $uow->getEntityChangeSet($form->getData());
  337.             $em->persist($person);
  338.             $em->flush();
  339.             if(isset($changeSet['gender'])) {
  340.                 foreach ($person->getChildren() as $child) {
  341.                     dd("??");
  342.                     $person->removeChild($child);
  343.                 }
  344.             }
  345.             $born null;
  346.             $died null;
  347.             $bornUncertain $form['uncertainBorn']->getData();
  348.             $diedUncertain $form['uncertainDied']->getData();
  349.             $isBornUncertain false;
  350.             $isDiedUncertain false;
  351.             if($bornUncertain) {
  352.                 $born $uncertainNumberValidator->getValue($bornUncertain);
  353.                 if($uncertainNumberValidator->isUncertain($bornUncertain)) {
  354.                     $person->setBornEstimated($born);
  355.                     $person->setBorn(null);
  356.                     $isBornUncertain true;
  357.                 } else {
  358.                     $person->setBorn($born);
  359.                     $person->setBornEstimated($born);
  360.                 }
  361.             } else {
  362.                 $person->setBorn(null);
  363.                 $person->setBornEstimated(null);
  364.             }
  365.             if($diedUncertain) {
  366.                 $died $uncertainNumberValidator->getValue($diedUncertain);
  367.                 if($uncertainNumberValidator->isUncertain($diedUncertain)) {
  368.                     $person->setDiedEstimated($died);
  369.                     $person->setDied(null);
  370.                     $isDiedUncertain true;
  371.                 } else {
  372.                     $person->setDied($died);
  373.                     $person->setDiedEstimated($died);
  374.                 }
  375.             } else {
  376.                 $person->setDied(null);
  377.                 $person->setDiedEstimated(null);
  378.             }
  379.             $em->persist($person);
  380.             $em->flush();
  381.             $age $form['age']->getData();
  382.             if($age!=null) {
  383.                 if($born == null) {
  384.                     if($died != null) {
  385.                         if ($isDiedUncertain) {
  386.                             $person->setBornEstimated($born $died $age);
  387.                         } else {
  388.                             $person->setBorn($born $died $age);
  389.                         }
  390.                         $em->persist($person);
  391.                         $em->flush();
  392.                     }
  393.                 }
  394.                 if($died == null) {
  395.                     if($born != null) {
  396.                         if ($isBornUncertain) {
  397.                             $person->setDiedEstimated($born $age);
  398.                         } else {
  399.                             $person->setDied($born $age);
  400.                         }
  401.                         $em->persist($person);
  402.                         $em->flush();
  403.                     }
  404.                 }
  405.             }
  406.             if (in_array('ROLE_ACCEPT_CHANGES'$this->getUser()->getRoles())) {
  407.                 if(isset($changeSet['uncertainBorn']) || isset($changeSet['uncertainDied']) || isset($changeSet['age']) || isset($changeSet['livedAtTimeOfPerson'])) {
  408.                     $treeLogic->estimateAgesAction($em$this->getUser());
  409.                 }
  410.                 if(isset($changeSet['father']) || isset($changeSet['mother']) || isset($changeSet['children'])) {
  411.                 }
  412.             }
  413.             $this->addFlash('success''Person updated');
  414.         }
  415.         $addChildren = [];
  416.         $q $request->query->get('q');
  417.         if(strlen($q) > 0) {
  418.             $addChildren $this->personRepository->findAllPossibleChildren($this->getUser(), $person$q);
  419.             $existingChildren $person->getChildren();//$user);
  420.             $addChildren = new ArrayCollection(array_diff(
  421.                 $addChildren,
  422.                 $existingChildren->toArray()
  423.             ));
  424.         }
  425.         return $this->render(
  426.             'person/edit.html.twig', [
  427.             'personForm' => $form->createView(),
  428.             'person' => $person,
  429.             'addChildren'=> $addChildren,
  430.         ]);
  431.     }
  432.     public function CreateClone(EntityManager $emPerson $originPerson,User $user) : Person{
  433.         dd("deprecated");
  434.         $personClone = clone $originPerson;
  435.        // $change = new EntityChange();
  436.         //$change->setPerson($personClone)->setModificationType("edit")->setChangedBy($user);
  437.        // $em->persist($change);
  438.         //$originPerson->addChange($change);
  439.        // $em->persist($change);
  440.         $em->persist($originPerson);
  441.         $personClone->setUpdateOf($change);
  442.         $personClone->setApproved(false);
  443.         $personClone->setOwner($user);
  444.         $em->persist($personClone);
  445.         $em->flush();
  446.         return $personClone;
  447.     }
  448.     /**
  449.      * @Route("/person/remove_link/{parent}/{child}", name="removeLink")
  450.      * @IsGranted("ROLE_EDIT_ENTITY")
  451.      * @param EntityManagerInterface $em
  452.      * @param Person $parent
  453.      * @param Person $child
  454.      * @return \Symfony\Component\HttpFoundation\RedirectResponse
  455.      */
  456.     public function removeLinkAction(EntityManagerInterface $emPerson $parentPerson $child): \Symfony\Component\HttpFoundation\RedirectResponse
  457.     {
  458.         $user $this->getUser();
  459.         $existingLinks $parent->getChildLinks($user);
  460.         /** @var PersonLink $existingLink */
  461.         foreach ($existingLinks as $existingLink) {
  462.             if($existingLink->getChild() == $child && $existingLink->getParent() == $parent->getUpdateOf()){
  463.                 if(!$existingLink->getApproved() && $existingLink->getOwner() == $user) {
  464.                     $em->remove($existingLink);
  465.                 } else {
  466.                     $existingLink->setTaggedForDeleteBy($user);
  467.                 }
  468.             }
  469.         }
  470.         $em->flush();
  471.         return $this->redirect($this->generateUrl('person_edit',
  472.             ['id' => $parent->getId()]));
  473.     }
  474.     /**
  475.      * @Route("/person/remove_reference/{person}/{id}", name="remove_reference")
  476.      *  @IsGranted("ROLE_EDIT_ENTITY")
  477.      */
  478.     public function removeReference(EntityManagerInterface $emPerson $personPersonReference $personReference)
  479.     {
  480.         $user $this->getUser();
  481.         if ($user && in_array('ROLE_ADMIN'$user->getRoles() )) {
  482.             $person->removePersonReference($personReference);
  483.             $em->remove($personReference);
  484.             $em->persist($person);
  485.         } else {
  486.             $personReference->setTaggedForDeleteBy($user);
  487.             $em->persist($personReference);
  488.         }
  489.         $em->flush();
  490.         return $this->redirectToRoute('person_edit', [
  491.             'id' => $person->getId(),
  492.         ]);
  493.     }
  494.     /**
  495.      * @Route("/person/add_reference/{person}", name="add_reference")
  496.      * @IsGranted("ROLE_EDIT_ENTITY")
  497.      */
  498.     public function addReferenceAction(BibleBooksUtilityController $bibleBooksUtilityControllerRequest $requestPerson $person)
  499.     {
  500.         $type $request->request->get('reftype');
  501.         $term $request->request->get('submit_param');
  502.         $valid $bibleBooksUtilityController->checkIsValid($term);
  503.         if($valid['fullReference']!="") {
  504.             $em $this->getDoctrine()->getManager();
  505.             $reference $em->getRepository("App:Reference")->findOneBy([
  506.                 'url' => $valid['fullReference'],
  507.             ]);
  508.             if($reference == null) {
  509.                 $reference = new Reference();
  510.                 $reference->setUrl($valid['fullReference']);
  511.                 $reference->setIsBibleRef($valid['book']!="");
  512.                 $em->persist($reference);
  513.             }
  514.             $personReference = new PersonReference();
  515.             $personReference->setType($type);
  516.             $personReference->setPerson($person);
  517.             $personReference->setReference($reference);
  518.             $user $this->getUser();
  519.             if($user->acceptsChanges()) {
  520.                 $personReference->setApproved(true);
  521.             } else {
  522.                 $personReference->setApproved(false);
  523.                 $personReference->setOwner($user);
  524.             }
  525.             $em->persist($personReference);
  526.             $person->addPersonReference($personReference);
  527.             $em->persist($person);
  528.             $em->flush();
  529.             $this->addFlash('success''Reference added');
  530.         }else {
  531.             $this->addFlash('error''Data not valid');
  532.         }
  533.         return $this->redirectToRoute('person_edit', [
  534.             'id' => $person->getId(),
  535.         ]);
  536.     }
  537.     /**
  538.      * @Route("/person/add_link/{parent}/{child}", name="addLink")
  539.      * @IsGranted("ROLE_EDIT_ENTITY")
  540.      * @param EntityManagerInterface $em
  541.      * @param Person $parent
  542.      * @param Person $child
  543.      * @return \Symfony\Component\HttpFoundation\RedirectResponse
  544.      */
  545.     public function addLinkAction(EntityManagerInterface $emPerson $parentPerson $child): \Symfony\Component\HttpFoundation\RedirectResponse
  546.     {
  547.         $user $this->getUser();
  548.         $child $child->getUpdateOf() ?? $child;
  549.         $parent $parent->getUpdateOf() ?? $parent;
  550.         $parent->getGender() == 'w'
  551.             $child->setMotherParent($em$parent$user)
  552.             : $child->setFatherParent($em$parent$user);
  553.         $em $this->getDoctrine()->getManager();
  554.         $em->persist($child);
  555.         $em->persist($parent);
  556.         $em->flush();
  557.         $this->addFlash('success''Child link added');
  558.         return $this->redirectToRoute('person_edit', [
  559.             'id' => $parent->getId(),
  560.         ]);
  561.     }
  562.     /**
  563.      * @Route("/person/{id}", name="person_show")
  564.      */
  565.     public function show(Person $person)
  566.     {
  567.         $user $this->getUser();
  568.         if ($user && in_array('ROLE_ADMIN'$user->getRoles() )) {
  569.         };
  570.         /* $addChildren = [];
  571.          $q = $request->query->get('q');
  572.          if(strlen($q) > 2) {
  573.              $addChildren = $repository->findAllPossibleChildren($person, $q);
  574.          }*/
  575.         /* if(sizeof($person->getReference()) > 0)
  576.         {
  577.             /** @var Reference $reference* /
  578.             $reference = $person->getReferenceL()->toArray()[0];
  579.             $reference->generateBibleServerUrl();
  580.         }*/
  581.         return $this->render('person/show.html.twig', [
  582.             'person' => $person,
  583.             // 'addchildren' => $addChildren,
  584.         ]);
  585.     }
  586.     /**
  587.      * @Route("/pedigree", name="pedigree")
  588.      */
  589.     public function pedigree()
  590.     {
  591.         $nodeEntities $this->personRepository->getNodes($this->getUser());
  592.       //  dd($nodes);
  593.         $nodes = [];
  594.         $links = [];
  595.         $nodesImages = [];
  596.         $i 0;
  597.         /** @var Person $node */
  598.         foreach ($nodeEntities as $node){
  599.             if($node->getUpdateOf() && $node->getUpdateOf() != $node// omit, because we get them by getUpdate
  600.             {
  601.                 continue;
  602.             }
  603.             $node $node->getUpdate($this->getUser());
  604.             $nodeArray['id'] = $node->getId();
  605.             $spacePos strpos($node->getName(), " ");
  606.             $nodeArray['name'] = $spacePos substr($node->getName(), 0$spacePos) : $node->getName();
  607.             $nodeArray['full_name'] = $node->getName();
  608.             $nodeArray['gender'] = $node->getGender();
  609.             $nodeArray['level'] = $node->getLeafLevel();
  610.             $nodeArray['born'] = $node->getBorn(truetrue);
  611.             $nodeArray['died'] = $node->getDied(truetrue) ?? $nodeArray['born']  + 80;
  612.             $nodeArray['fuzzyBegin'] = $node->getBorn() !== null 'd' : ($node->getBorn(true) ? 'e' 'c');
  613.             $nodeArray['fuzzyEnd'] = $node->getDied() != null 'd' : ($node->getBorn(true) ? 'e' 'c');
  614.             $nodeArray['image'] = $node->getImage();
  615.             $nodesImages[$node->getId()] = $node->getImage();
  616.             $nodes[] = $nodeArray;
  617.         }
  618.         $linkEntities $this->personLinkRepository->getLinks($this->getUser());
  619.         /** @var PersonLink $iink */
  620.         foreach ($linkEntities as $iink) {
  621.             $linkArray = [];
  622.             $linkArray['source'] = $iink->getParent()->getUpdate($this->getUser())->getId();
  623.             $linkArray['target'] = $iink->getChild()->getUpdate($this->getUser())->getId();
  624.             $links[] = $linkArray;
  625.         }
  626.        // dd($links, $nodes);
  627.        // $nodesImages = $this->personRepository->getNodesImageList($this->getUser());
  628.         $books $this->bibleBooksRepository->getJSONNodes();
  629.         $folkNodes $this->folkRepository->getNodes();
  630.         $folkLinks =  $this->folkRepository->getLinks();
  631.       //  $getAllUserChanges()
  632.         // dd($nodes, $folkNodes);
  633.         //dd($links);
  634.         $nodes array_merge($nodes$folkNodes);
  635.         usort($nodes, function($a$b){
  636.             return ($a['born'] < $b['born']) ? -1;
  637.         });
  638.        // dd($nodes);
  639.        // dd(json_encode(array_merge($links,$folkLinks)));
  640.         return $this->render('person/pedigree.html.twig', [
  641.             'nodes' => json_encode($nodes),
  642.             'images' => $nodesImages,
  643.             'links'=>json_encode(array_merge($links,$folkLinks)),
  644.             //   'links'=>json_encode($links),
  645.             'books'=>$books,
  646.             'person_info_url' => $this->router->generate('person_utility_info'),
  647.         ]);
  648.     }
  649. }