src/Controller/FossildbController.php line 1163

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Knp\Component\Pager\PaginatorInterface;
  8. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  9. use Symfony\Contracts\Translation\TranslatorInterface;
  10. use Symfony\Component\Filesystem\Filesystem;
  11. use Symfony\Component\Routing\RouterInterface;
  12. use Symfony\Component\HttpFoundation\JsonResponse;
  13. use App\Form\FossildbSearchFormType;
  14. use App\Form\FossildbModeratorSearchFormType;
  15. use App\Form\FossildbFossilFormType;
  16. use App\Form\FossildbFossilEditFormType;
  17. use App\Form\FossildbFossilModeratorEditFormType;
  18. use App\Form\FossildbReviewsFormType;
  19. use App\Form\FossildbFossilAddPhotoFormType;
  20. use App\Repository\TaxanomyRepository;
  21. use App\Repository\LocationsFossilRepository;
  22. use App\Repository\StratigraphyUnitsRepository;
  23. use App\Repository\FossildbFossilRepository;
  24. use App\Entity\LocationsFossil;
  25. use App\Entity\StratigraphyUnits;
  26. use App\Entity\Taxanomy;
  27. use App\Entity\FossildbFossil;
  28. use App\Entity\FossildbFossilEdits;
  29. use App\Entity\FossildbPhotos;
  30. use App\Entity\FossildbReviews;
  31. use App\Entity\Literature;
  32. use App\Entity\UploadQueue;
  33. use App\Entity\Newsfeed;
  34. use App\Entity\User;
  35. use App\Entity\UserProfile;
  36. use App\Entity\SearchItems;
  37. class FossildbController extends AbstractController
  38. {
  39.     private $session;
  40.     private $translator;
  41.     private $em;
  42.     private $router;
  43.     public function __construct(SessionInterface $sessionTranslatorInterface $translatorEntityManagerInterface $emRouterInterface $router)
  44.     {
  45.         $this->session $session;
  46.         $this->em $em;
  47.         $this->translator $translator;
  48.         $this->router $router;
  49.     }
  50.     private function taxanomy_tree(?int $idEntityManagerInterface $em) {
  51.         if($id != null) {
  52.             $qb $em->createQueryBuilder('f')
  53.                 ->from('App\Entity\Taxanomy''f')
  54.                 ->addSelect('f')
  55.                 ->andWhere("f.id = (:id)")
  56.                 ->orderBy('f.id','ASC')
  57.                 ->setParameter('id'$id)
  58.                 ->setMaxResults(1)
  59.             ;
  60.             $db_result $qb->getQuery()->getResult();
  61.             if ($db_result[0]->getParentId() != '0' || $db_result[0]->getParentId() != null) {
  62.                 $tree $this->taxanomy_tree($db_result[0]->getParentId(),$em);
  63.                 $tree[] = $db_result[0];
  64.             } else {
  65.                 $tree = array($db_result[0]);
  66.             }
  67.             return $tree;
  68.         }
  69.     }
  70.     /**
  71.      * @Route("/fossildb", name="fossildb")
  72.      */
  73.     public function index(Request $requestEntityManagerInterface $emPaginatorInterface $paginator)
  74.     {
  75.         $form $this->createForm(FossildbSearchFormType::class);
  76.         $form->handleRequest($request);
  77.         $taxanomy = array();
  78.         $location = array();
  79.         $era = array();
  80.         $genus = array();
  81.         $species = array();
  82.         $user = array();
  83.         if ($form->isSubmitted() && $form->isValid()){
  84.             $filter $form->getData();
  85.             $page 1;
  86.         } else {
  87.             if(!$request->query->get('page')){
  88.                 $filter=array(
  89.                     'taxanomy'=> '[]',
  90.                     'location' => '[]',
  91.                     'era' => '[]',
  92.                     'genus' => '[]',
  93.                     'species' => '[]',
  94.                     'user' => '[]',
  95.                     'id' => null
  96.                 );
  97.                 $form->get('taxanomy')->setData("");
  98.                 $form->get('location')->setData("");
  99.                 $form->get('era')->setData("");
  100.                 $form->get('genus')->setData("");
  101.                 $form->get('species')->setData("");
  102.                 $form->get('id')->setData(null);
  103.                 $form->get('user')->setData("");
  104.                 $page false;
  105.             } elseif($request->query->get('filter') && $request->query->get('page')) {
  106.                 $page $request->query->get('page');
  107.                 $filter $request->query->get('filter');
  108.                 if(isset($filter['taxanomy']) && $filter['taxanomy'] != '[""]') { $form->get('taxanomy')->setData($filter['taxanomy']); } else { $form->get('taxanomy')->setData(''); $filter['taxanomy'] = null; };
  109.                 if(isset($filter['location']) && $filter['location'] != '[""]') { $form->get('location')->setData($filter['location']); } else { $form->get('location')->setData(''); $filter['location'] = null; };
  110.                 if(isset($filter['era']) && $filter['era'] != '[""]') { $form->get('era')->setData($filter['era']); } else { $form->get('era')->setData(''); $filter['era'] = null; };
  111.                 if(isset($filter['genus']) && $filter['genus'] != '[""]') { $form->get('genus')->setData($filter['genus']); } else { $form->get('genus')->setData(null); $filter['genus'] = null;};
  112.                 if(isset($filter['species']) && $filter['species'] != '[""]') { $form->get('species')->setData($filter['species']); } else { $form->get('species')->setData(null); $filter['species'] = null;};
  113.                 if(isset($filter['id']) && $filter['id'] != '') { $form->get('id')->setData($filter['id']); } else { $form->get('id')->setData(null); $filter['id'] = null;};
  114.                 if(isset($filter['user']) && $filter['user'] != '[""]') { $form->get('user')->setData($filter['user']); } else { $form->get('user')->setData(''); $filter['user'] = null; };
  115.             } else {
  116.                 dd("Unexpected Error");
  117.             }
  118.         }
  119.         $filter_taxanomy json_decode($filter['taxanomy']);
  120.         $filter_location json_decode($filter['location']);
  121.         $filter_era json_decode($filter['era']);
  122.         $filter_genus json_decode($filter['genus']);
  123.         $filter_species json_decode($filter['species']);
  124.         $filter_user json_decode($filter['user']);
  125.         if(is_array($filter_taxanomy)) {
  126.             foreach($filter_taxanomy as $id => $item) {
  127.                 $taxanomy[] = $item->id;
  128.             }
  129.         }
  130.         if(is_array($filter_location)) {
  131.             foreach($filter_location as $id => $item) {
  132.                 $location[] = $item->id;
  133.             }
  134.         }
  135.         if(is_array($filter_era)) {
  136.             foreach($filter_era as $id => $item) {
  137.                 $era[] = $item->id;
  138.             }
  139.         }
  140.         if(is_array($filter_genus)) {
  141.             foreach($filter_genus as $id => $item) {
  142.                 $genus[] = $item->value;
  143.             }
  144.         }
  145.         if(is_array($filter_species)) {
  146.             foreach($filter_species as $id => $item) {
  147.                 $species[] = $item->value;
  148.             }
  149.         }
  150.         if(is_array($filter_user)) {
  151.             foreach($filter_user as $id => $item) {
  152.                 $user[] = $item->id;
  153.             }
  154.         }
  155.         if(is_null($filter['taxanomy'])) { $filter['taxanomy'] = '[""]'; }
  156.         if(is_null($filter['location'])) { $filter['location'] = '[""]'; }
  157.         if(is_null($filter['era'])) { $filter['era'] = '[""]'; }
  158.         if(!is_numeric($filter['id'])) { $filter['id'] = null; }
  159.         if(is_null($filter['genus'])) { $filter['genus'] = '[""]'; }
  160.         if(is_null($filter['species'])) { $filter['species'] = '[""]'; }
  161.         if(is_null($filter['user'])) { $filter['user'] = '[""]'; }
  162.         $qb $em->createQueryBuilder('f')
  163.             ->from('App\Entity\FossildbFossil''f')
  164.             ->addSelect('f')
  165.             ->andWhere('f.approved = 1')
  166.             ->orderBy('f.id','DESC')
  167.         ;
  168.         if(!empty($taxanomy)) {
  169.             $qb->andWhere("f.taxanomy IN (:taxanomy)")
  170.                 ->setParameter('taxanomy'array_values($taxanomy))
  171.             ;
  172.         }
  173.         if(!empty($location)) {
  174.             $qb->andWhere("f.location_fossil IN (:location)")
  175.                 ->setParameter('location'array_values($location))
  176.             ;
  177.         }
  178.         if(!empty($era)) {
  179.             $qb->andWhere("f.era IN (:era)")
  180.                 ->setParameter('era'array_values($era))
  181.             ;
  182.         }
  183.         if(!empty($filter['id'])) {
  184.             $qb->andWhere("f.id = :id")
  185.                 ->setParameter('id'$filter['id'])
  186.             ;
  187.         }
  188.         if(!empty($genus)) {
  189.             $qb->andWhere("f.genus IN (:genus)")
  190.                 ->setParameter('genus'array_values($genus))
  191.             ;
  192.         }
  193.         if(!empty($species)) {
  194.             $qb->andWhere("f.species IN (:species)")
  195.                 ->setParameter('species'array_values($species))
  196.             ;
  197.         }
  198.         if(!empty($user)) {
  199.             $qb->andWhere("f.user_id IN (:user)")
  200.                 ->setParameter('user'array_values($user))
  201.             ;
  202.         }
  203.         $result $paginator->paginate(
  204.             $qb/* query NOT result */
  205.             $request->query->getInt('page'1), /*page number*/
  206.             10 /*limit per page*/
  207.         );
  208.         $result->setParam('filter'$filter);
  209.         $result->setCustomParameters([
  210.             'align' => 'right'# center|right (for template: twitter_bootstrap_v4_pagination)
  211.         ]);
  212.         foreach($result as $id => $object) {
  213.             if($object->getTaxanomy() && is_null($object->getTaxanomyTree())) {
  214.                 $constructed_taxanomy_tree=$this->taxanomy_tree($object->getTaxanomy()->getId(), $em);
  215.                 $taxanomy_tree = array();
  216.                 foreach($constructed_taxanomy_tree as $item => $object) {
  217.                     $taxanomy_tree[$item]['namescientific'] = $object->getNameScientific();
  218.                     $taxanomy_tree[$item]['namescientificclarification'] = $object->getNameScientificClarification();
  219.                     $taxanomy_tree[$item]['namenl'] = $object->getNameNl();
  220.                     $taxanomy_tree[$item]['nameen'] = $object->getNameEn();
  221.                     $taxanomy_tree[$item]['author'] = $object->getAuthor();
  222.                     $taxanomy_tree[$item]['authoryear'] = $object->getAuthorYear();
  223.                     if($object->getGlossary()){
  224.                         $taxanomy_tree[$item]['glossary']['id'] = $object->getGlossary()->getId();
  225.                         $taxanomy_tree[$item]['glossary']['url'] = $object->getGlossary()->getUrl();
  226.                         $taxanomy_tree[$item]['glossary']['titlenl'] = $object->getGlossary()->getTitleNl();
  227.                         $taxanomy_tree[$item]['glossary']['titleen'] = $object->getGlossary()->getTitleEn();
  228.                     } else {
  229.                         $taxanomy_tree[$item]['glossary'] = null;
  230.                     }
  231.                     $taxanomy_tree[$item]['taxanomyrank']['namescientific'] = $object->getTaxanomyRank()->getNameScientific();
  232.                     $taxanomy_tree[$item]['taxanomyrank']['namenl'] = $object->getTaxanomyRank()->getNameNl();
  233.                     $taxanomy_tree[$item]['taxanomyrank']['nameen'] = $object->getTaxanomyRank()->getNameEn();
  234.                 }
  235.                 $result[$id]->setTaxanomyTree(array_reverse($taxanomy_tree));
  236.                 $em->persist($result[$id]);
  237.                 $em->flush();
  238.             }
  239.         }
  240.         return $this->render('fossildb.html.twig', [
  241.             'form' => $form->createView(),
  242.             'filter' => $filter,
  243.             'result' => $result,
  244.             'page' => $page,
  245.         ]);
  246.     }
  247.     /**
  248.      * @Route("/fossildb/fossil/{id}", name="fossildb_item")
  249.      */
  250.     public function fossildb_item(FossildbFossil $id)
  251.     {
  252.         return $this->render('fossildb_single.html.twig', [
  253.             'item' => $id,
  254.         ]);
  255.     }
  256.     /**
  257.      * @Route("/fossildb/add", name="fossildb_add")
  258.      */
  259.     public function fossildb_add(Request $requestEntityManagerInterface $emTranslatorInterface $translator)
  260.     {
  261.         $this->denyAccessUnlessGranted('ROLE_USER');
  262.         if($_ENV['DISABLE_FORMS'] == "true") { return $this->render('maintenance_form_disabled.html.twig'); }
  263.         $filter = array( 'genus' => '[""]''species' => '[""]''publication' => '[""]''literature' => '[""]''location' => '[""]''taxanomy' => '[""]''era' => '[""]''epoch' => '[""]''stage' => '[""]');
  264.         $form $this->createForm(FossildbFossilFormType::class);
  265.         $form->handleRequest($request);
  266.         if ($form->isSubmitted() && $form->isValid()){
  267.             $fossil $form->getData();
  268.             if(!is_null($fossil['location_fossil'])) {
  269.                 $repository $this->getDoctrine()->getRepository(LocationsFossil::class);
  270.                 $location_fossil $repository->findOneBy(array('id' => json_decode($fossil['location_fossil'])[0]->id));
  271.             } else {
  272.                 $location_fossil=null;
  273.             }
  274.             if(!is_null($fossil['taxanomy'])) {
  275.                 $repository $this->getDoctrine()->getRepository(Taxanomy::class);
  276.                 $taxanomy $repository->findOneBy(array('id' => json_decode($fossil['taxanomy'])[0]->id));
  277.             } else {
  278.                 $taxanomy=null;
  279.             }
  280.             if(!is_null($fossil['era'])) {
  281.                 $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  282.                 $era $repository->findOneBy(array('id' => json_decode($fossil['era'])[0]->id));
  283.             } else {
  284.                 $era=null;
  285.             }
  286.             if(!is_null($fossil['epoch'])) {
  287.                 $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  288.                 $epoch $repository->findOneBy(array('id' => json_decode($fossil['epoch'])[0]->id));
  289.             } else {
  290.                 $epoch=null;
  291.             }
  292.             if(!is_null($fossil['stage'])) {
  293.                 $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  294.                 $stage $repository->findOneBy(array('id' => json_decode($fossil['stage'])[0]->id));
  295.             } else {
  296.                 $stage=null;
  297.             }
  298.             if(!is_null($fossil['formation'])) {
  299.                 $formation_item json_decode($fossil['formation'])[0];
  300.                 if (property_exists($formation_item'id')) {
  301.                     $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  302.                     $formation $repository->findOneBy(array('id' => $formation_item->id));
  303.                 } else {
  304.                     $new_formation_item = new StratigraphyUnits;
  305.                     $new_formation_item->setType("member");
  306.                     $new_formation_item->setNameNl($formation_item->value);
  307.                     $new_formation_item->setNameEn($formation_item->value);
  308.                     $em->persist($new_formation_item);
  309.                     $em->flush();
  310.                     $formation $new_formation_item->getId();
  311.                 }
  312.             } else {
  313.                 $formation=null;
  314.             }
  315.             if(!is_null($fossil['member'])) {
  316.                 $member_item json_decode($fossil['member'])[0];
  317.                 if (property_exists($member_item'id')) {
  318.                     $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  319.                     $member $repository->findOneBy(array('id' => $member_item->id));
  320.                 } else {
  321.                     $new_member_item = new StratigraphyUnits;
  322.                     $new_member_item->setType("member");
  323.                     $new_member_item->setNameNl($member_item->value);
  324.                     $new_member_item->setNameEn($member_item->value);
  325.                     $em->persist($new_member_item);
  326.                     $em->flush();
  327.                     $member $new_member_item;
  328.                 }
  329.             } else {
  330.                 $member=null;
  331.             }
  332.  
  333.             if(!is_null($fossil['literature'])) {
  334.                 $repository $this->getDoctrine()->getRepository(Literature::class);
  335.                 $literature $repository->findOneBy(array('id' => json_decode($fossil['literature'])[0]->id));
  336.             } else {
  337.                 $literature=null;
  338.             }
  339.             $fossildbFossil = new FossildbFossil;
  340.             if(json_decode($fossil['genus'])[0]) {
  341.                 $fossildbFossil->setGenus(json_decode($fossil['genus'])[0]->value);
  342.             }
  343.             if(json_decode($fossil['species'])[0]) {
  344.                 $fossildbFossil->setSpecies(json_decode($fossil['species'])[0]->value);
  345.             }
  346.             if(json_decode($fossil['publication'])[0]) {
  347.                 $fossildbFossil->setPublication(json_decode($fossil['publication'])[0]->value);
  348.             }
  349.             $fossildbFossil->setLocationFossil($location_fossil);
  350.             $fossildbFossil->setTaxanomy($taxanomy);
  351.             $fossildbFossil->setEra($era);
  352.             $fossildbFossil->setEpoch($epoch);
  353.             $fossildbFossil->setStage($stage);
  354.             $fossildbFossil->setFormation($formation);
  355.             $fossildbFossil->setMember($member);
  356.             $fossildbFossil->setDateYear($fossil['date_year']);
  357.             $fossildbFossil->setDateMonth($fossil['date_month']);
  358.             $fossildbFossil->setDateDay($fossil['date_day']);
  359.             $fossildbFossil->setCommentNl($fossil['comment_nl']);
  360.             $fossildbFossil->setCommentEn($fossil['comment_en']);
  361.             $fossildbFossil->setUserNumber($fossil['user_number']);
  362.             $fossildbFossil->setLiterature($literature);
  363.             $constructed_taxanomy_tree=$this->taxanomy_tree(json_decode($fossil['taxanomy'])[0]->id$em);
  364.             $taxanomy_tree = array();
  365.             foreach($constructed_taxanomy_tree as $item => $object) {
  366.                 $taxanomy_tree[$item]['namescientific'] = $object->getNameScientific();
  367.                 $taxanomy_tree[$item]['namescientificclarification'] = $object->getNameScientificClarification();
  368.                 $taxanomy_tree[$item]['namenl'] = $object->getNameNl();
  369.                 $taxanomy_tree[$item]['nameen'] = $object->getNameEn();
  370.                 $taxanomy_tree[$item]['author'] = $object->getAuthor();
  371.                 $taxanomy_tree[$item]['authoryear'] = $object->getAuthorYear();
  372.                 if($object->getGlossary()){
  373.                     $taxanomy_tree[$item]['glossary']['id'] = $object->getGlossary()->getId();
  374.                     $taxanomy_tree[$item]['glossary']['url'] = $object->getGlossary()->getUrl();
  375.                     $taxanomy_tree[$item]['glossary']['titlenl'] = $object->getGlossary()->getTitleNl();
  376.                     $taxanomy_tree[$item]['glossary']['titleen'] = $object->getGlossary()->getTitleEn();
  377.                 } else {
  378.                     $taxanomy_tree[$item]['glossary'] = null;
  379.                 }
  380.                 $taxanomy_tree[$item]['taxanomyrank']['namescientific'] = $object->getTaxanomyRank()->getNameScientific();
  381.                 $taxanomy_tree[$item]['taxanomyrank']['namenl'] = $object->getTaxanomyRank()->getNameNl();
  382.                 $taxanomy_tree[$item]['taxanomyrank']['nameen'] = $object->getTaxanomyRank()->getNameEn();
  383.             }
  384.             $fossildbFossil->setTaxanomyTree(array_reverse($taxanomy_tree));
  385.             $fossildbFossil->setAdded(new \DateTime());
  386.             $fossildbFossil->setUserId($this->getUser()->getId());
  387.             $fossildbFossil->setUsername($this->getUser()->getUsername());
  388.             $fossildbFossil->setApproved(0);
  389.             $fossildbFossil->setNumReviews(0);
  390.             $fossildbFossil->setNumNewPhotos(0);
  391.             $fossildbFossil->setHasEdits(0);
  392.             $em->persist($fossildbFossil);
  393.             $em->flush();
  394.             
  395.             if(!is_null($fossil['upload'])) {
  396.                 $upload json_decode($fossil['upload']);
  397.                 foreach($upload as $id => $item) {
  398.                     if(!is_null($item)) {
  399.                         $repository $this->getDoctrine()->getRepository(UploadQueue::class);
  400.                         $queuefile $repository->findOneBy(array('system' => 'fossildb','filename' => $item->name));
  401.                         if(!is_null($queuefile)) {
  402.                             $fossildbPhoto = new FossildbPhotos;
  403.                             $fossildbPhoto->setFossildbFossil($fossildbFossil);
  404.                             $fossildbPhoto->setType('fossil');
  405.                             $fossildbPhoto->setFilename($item->name);
  406.                             $fossildbPhoto->setAdded(new \DateTime());
  407.                             $fossildbPhoto->setUserId($this->getUser()->getId());
  408.                             $fossildbPhoto->setUsername($this->getUser()->getUsername());
  409.                             $fossildbPhoto->setApproved(0);
  410.     
  411.                             $fp $em->createQueryBuilder('fp')
  412.                                 ->from('App\Entity\FossildbPhotos''fp')
  413.                                 ->addSelect('count(fp.id)')
  414.                                 ->andWhere("fp.is_primary = 1")
  415.                                 ->andWhere("fp.FossildbFossil = (:id)")
  416.                                 ->setParameter('id'$fossildbFossil->getId())
  417.                                 ->getQuery()
  418.                                 ->getSingleScalarResult();
  419.                             ;
  420.                             if($fp == 0) {
  421.                                 $fossildbPhoto->setIsPrimary(1);
  422.                             } else {
  423.                                 $fossildbPhoto->setIsPrimary(0);
  424.                             }
  425.                             $em->persist($fossildbPhoto);
  426.                             $em->remove($queuefile);
  427.                             $fossildbFossil->setNumNewPhotos($fossildbFossil->getNumNewPhotos()+1);
  428.                             $em->persist($fossildbFossil);
  429.                             $em->flush();
  430.                         }
  431.                     }
  432.                 }
  433.             }
  434.             $this->addFlash('success'$translator->trans("Toegevoegd aan Fossielendatabase"));
  435.             if($fossil["add_new_as_this"] === true) {
  436.                 $filter = array( 'genus' => $fossil['genus'], 'species' => $fossil['species'], 'publication' => $fossil['publication'], 'literature' => $fossil['literature'], 'location' => $fossil['location_fossil'], 'taxanomy' => $fossil['taxanomy'], 'era' => $fossil['era'], 'epoch' => $fossil['epoch'], 'stage' => $fossil['stage']);
  437.             } else {
  438.                 return $this->redirectToRoute('fossildb');
  439.             }
  440.         }
  441.         if(is_null($filter['genus'])) {$filter['genus'] = '[""]';}
  442.         if(is_null($filter['species'])) {$filter['species'] = '[""]';}
  443.         if(is_null($filter['publication'])) {$filter['publication'] = '[""]';}
  444.         if(is_null($filter['literature'])) {$filter['literature'] = '[""]';}
  445.         if(is_null($filter['location'])) {$filter['location'] = '[""]';}
  446.         if(is_null($filter['taxanomy'])) {$filter['taxanomy'] = '[""]';}
  447.         if(is_null($filter['era'])) {$filter['era'] = '[""]';}
  448.         if(is_null($filter['epoch'])) {$filter['epoch'] = '[""]';}
  449.         if(is_null($filter['stage'])) {$filter['stage'] = '[""]';}
  450.         return $this->render('fossildb_edit.html.twig', [
  451.             'filter' => $filter,
  452.             'formname' => 'fossildb_fossil_form',
  453.             'title' => $translator->trans("Fossiel toevoegen"),
  454.             'button_text' => $translator->trans("Insturen"),
  455.             'form' => $form->createView()
  456.         ]);
  457.     }
  458.     /**
  459.      * @Route("/fossildb/fossil/{item}/edit", name="fossildb_edit")
  460.      */
  461.     public function fossildb_edit(FossildbFossil $itemRequest $requestEntityManagerInterface $emTranslatorInterface $translator)
  462.     {
  463.         $this->denyAccessUnlessGranted('ROLE_USER');
  464.         if($_ENV['DISABLE_FORMS'] == "true") { return $this->render('maintenance_form_disabled.html.twig'); }
  465.         if($this->getUser()->getId() == $item->getUserId()){
  466.             $filter = array( 'genus' => '[""]''species' => '[""]''publication' => '[""]''literature' => '[""]''location' => '[""]''taxanomy' => '[""]''era' => '[""]''epoch' => '[""]''stage' => '[""]');
  467.             $fossil=array();
  468.             $fossil['id'] = $item->getId();
  469.             $repository $this->getDoctrine()->getRepository(FossildbFossilEdits::class);
  470.             $edited_fossil $repository->findOneBy(array('fossil' => $item->getId()));
  471.             if($edited_fossil){
  472.                 $edited 1;
  473.             } else {
  474.                 $edited 0;
  475.             }
  476.             if ($edited == && ($edited_fossil->getGenus() != $item->getGenus())){
  477.                 $fossil['genus'] = json_encode(array(array('value' => $edited_fossil->getGenus())));
  478.                 $fossil['edited']['genus'] = 1;
  479.             } else {
  480.                 $fossil['genus'] = json_encode(array(array('value' => $item->getGenus())));
  481.                 $fossil['edited']['genus'] = 0;
  482.             }
  483.             if ($edited == && ($edited_fossil->getSpecies() != $item->getSpecies())){
  484.                 $fossil['species'] = json_encode(array(array('value' => $edited_fossil->getSpecies())));
  485.                 $fossil['edited']['species'] = 1;
  486.             } else {
  487.                 $fossil['species'] = json_encode(array(array('value' => $item->getSpecies())));
  488.                 $fossil['edited']['species'] = 0;
  489.             }
  490.             if ($edited == && ($edited_fossil->getPublication() != $item->getPublication())){
  491.                 $fossil['publication'] = json_encode(array(array('value' => $edited_fossil->getPublication())));
  492.                 $fossil['edited']['publication'] = 1;
  493.             } else {
  494.                 $fossil['publication'] = json_encode(array(array('value' => $item->getPublication())));
  495.                 $fossil['edited']['publication'] = 0;
  496.             }
  497.             if ($edited == && ($edited_fossil->getTaxanomy() != $item->getTaxanomy())){
  498.                 if($translator->getLocale() == 'nl') {
  499.                     $name $edited_fossil->getTaxanomy()->getNameNl();
  500.                 } else {
  501.                     $name $edited_fossil->getTaxanomy()->getNameEn();
  502.                 }
  503.                 if($edited_fossil->getTaxanomy()->getNameScientificClarification() != '' || is_null($edited_fossil->getTaxanomy()->getNameScientificClarification())) {
  504.                     $scientific $edited_fossil->getTaxanomy()->getNameScientific() . " " $edited_fossil->getTaxanomy()->getNameScientificClarification();
  505.                     $filename $edited_fossil->getTaxanomy()->getNameScientific() . $edited_fossil->getTaxanomy()->getNameScientificClarification();
  506.                 } else {
  507.                     $scientific $edited_fossil->getTaxanomy()->getNameScientific();
  508.                     $filename $edited_fossil->getTaxanomy()->getNameScientific();
  509.                 }
  510.                 $fossil['taxanomy'] = json_encode(array(array(
  511.                     'id' => $edited_fossil->getTaxanomy()->getId(),
  512.                     'value' => $name." (".$scientific.")",
  513.                     'filename' => $filename,
  514.                 )));
  515.                 $fossil['edited']['taxanomy'] = 1;
  516.             } else {
  517.                 if(!is_null($item->getTaxanomy())) {
  518.                     if($translator->getLocale() == 'nl') {
  519.                         $name $item->getTaxanomy()->getNameNl();
  520.                     } else {
  521.                         $name $item->getTaxanomy()->getNameEn();
  522.                     }
  523.                     if($item->getTaxanomy()->getNameScientificClarification() != '' || is_null($item->getTaxanomy()->getNameScientificClarification())) {
  524.                         $scientific $item->getTaxanomy()->getNameScientific() . " " $item->getTaxanomy()->getNameScientificClarification();
  525.                         $filename $item->getTaxanomy()->getNameScientific() . $item->getTaxanomy()->getNameScientificClarification();
  526.                     } else {
  527.                         $scientific $item->getTaxanomy()->getNameScientific();
  528.                         $filename $item->getTaxanomy()->getNameScientific();
  529.                     }
  530.                     $fossil['taxanomy'] = json_encode(array(array(
  531.                         'id' => $item->getTaxanomy()->getId(),
  532.                         'value' => $name." (".$scientific.")",
  533.                         'filename' => $filename,
  534.                     )));
  535.                 } else { $fossil['taxanomy'] = json_encode(array()); }
  536.                 $fossil['edited']['taxanomy'] = 0;
  537.             }
  538.     
  539.             if ($edited == && ($edited_fossil->getLocationFossil() != $item->getLocationFossil())){
  540.                 if(!is_null($edited_fossil->getLocationFossil())) {
  541.                     $fossil['location_fossil'] = json_encode(array(array(
  542.                         'id' => $edited_fossil->getLocationFossil()->getId(),
  543.                         'value' => $edited_fossil->getLocationFossil()->getNameNl(),
  544.                         'name_en' => $edited_fossil->getLocationFossil()->getNameEn(),
  545.                         'location' => $edited_fossil->getLocationFossil()->getLocation()
  546.                     )));
  547.                 } else { $fossil['location_fossil'] = json_encode(array()); }
  548.                 $fossil['edited']['location_fossil'] = 0;
  549.             } else {
  550.                 if(!is_null($item->getLocationFossil())) {
  551.                     $fossil['location_fossil'] = json_encode(array(array(
  552.                         'id' => $item->getLocationFossil()->getId(),
  553.                         'value' => $item->getLocationFossil()->getNameNl(),
  554.                         'name_en' => $item->getLocationFossil()->getNameEn(),
  555.                         'location' => $item->getLocationFossil()->getLocation()
  556.                     )));
  557.                 } else { $fossil['location_fossil'] = json_encode(array()); }
  558.                 $fossil['edited']['location_fossil'] = 0;
  559.             }
  560.     
  561.             if ($edited == && ($edited_fossil->getEra() != $item->getEra())){
  562.                 if(!is_null($edited_fossil->getEra())) {
  563.                     $fossil['era'] = json_encode(array(array(
  564.                         'id' => $edited_fossil->getEra()->getId(),
  565.                         'age_start' => $edited_fossil->getEra()->getAgeStart(),
  566.                         'age_end' => $edited_fossil->getEra()->getAgeEnd(),
  567.                         'value' => $edited_fossil->getEra()->getNameNl(),
  568.                         'name_en' => $edited_fossil->getEra()->getNameEn(),
  569.                         'color' => $edited_fossil->getEra()->getColor()
  570.                     )));
  571.                 } else { $fossil['era'] = json_encode(array()); }
  572.                 $fossil['edited']['era'] = 1;
  573.             } else {
  574.                 if(!is_null($item->getEra())) {
  575.                     $fossil['era'] = json_encode(array(array(
  576.                         'id' => $item->getEra()->getId(),
  577.                         'age_start' => $item->getEra()->getAgeStart(),
  578.                         'age_end' => $item->getEra()->getAgeEnd(),
  579.                         'value' => $item->getEra()->getNameNl(),
  580.                         'name_en' => $item->getEra()->getNameEn(),
  581.                         'color' => $item->getEra()->getColor()
  582.                     )));
  583.                 } else { $fossil['era'] = json_encode(array()); }
  584.                 $fossil['edited']['era'] = 0;
  585.             }
  586.     
  587.             if ($edited == && ($edited_fossil->getEpoch() != $item->getEpoch())){
  588.                 if(!is_null($item->getEpoch())) {
  589.                     $fossil['epoch'] = json_encode(array(array(
  590.                         'id' => $edited_fossil->getEpoch()->getId(),
  591.                         'age_start' => $edited_fossil->getEpoch()->getAgeStart(),
  592.                         'age_end' => $edited_fossil->getEpoch()->getAgeEnd(),
  593.                         'value' => $edited_fossil->getEpoch()->getNameNl(),
  594.                         'name_en' => $edited_fossil->getEpoch()->getNameEn(),
  595.                         'color' => $edited_fossil->getEpoch()->getColor()
  596.                     )));
  597.                 } else { $fossil['epoch'] = json_encode(array()); }
  598.                 $fossil['edited']['epoch'] = 1;
  599.             } else {
  600.                 if(!is_null($item->getEpoch())) {
  601.                     $fossil['epoch'] = json_encode(array(array(
  602.                         'id' => $item->getEpoch()->getId(),
  603.                         'age_start' => $item->getEpoch()->getAgeStart(),
  604.                         'age_end' => $item->getEpoch()->getAgeEnd(),
  605.                         'value' => $item->getEpoch()->getNameNl(),
  606.                         'name_en' => $item->getEpoch()->getNameEn(),
  607.                         'color' => $item->getEpoch()->getColor()
  608.                     )));
  609.                 } else { $fossil['epoch'] = json_encode(array()); }
  610.                 $fossil['edited']['epoch'] = 0;
  611.             }
  612.     
  613.             if ($edited == && ($edited_fossil->getStage() != $item->getStage())){
  614.                 if(!is_null($item->getStage())) {
  615.                     $fossil['stage'] = json_encode(array(array(
  616.                         'id' => $edited_fossil->getStage()->getId(),
  617.                         'age_start' => $edited_fossil->getStage()->getAgeStart(),
  618.                         'age_end' => $edited_fossil->getStage()->getAgeEnd(),
  619.                         'value' => $edited_fossil->getStage()->getNameNl(),
  620.                         'name_en' => $edited_fossil->getStage()->getNameEn(),
  621.                         'color' => $edited_fossil->getStage()->getColor()
  622.                     )));
  623.                 } else { $fossil['stage'] = json_encode(array()); }
  624.                 $fossil['edited']['stage'] = 1;
  625.             } else {
  626.                 if(!is_null($item->getStage())) {
  627.                     $fossil['stage'] = json_encode(array(array(
  628.                         'id' => $item->getStage()->getId(),
  629.                         'age_start' => $item->getStage()->getAgeStart(),
  630.                         'age_end' => $item->getStage()->getAgeEnd(),
  631.                         'value' => $item->getStage()->getNameNl(),
  632.                         'name_en' => $item->getStage()->getNameEn(),
  633.                         'color' => $item->getStage()->getColor()
  634.                     )));
  635.                 } else { $fossil['stage'] = json_encode(array()); }
  636.                 $fossil['edited']['stage'] = 0;
  637.             }
  638.     
  639.             if ($edited == && ($edited_fossil->getFormation() != $item->getFormation())){
  640.                 if(!is_null($item->getFormation())) {
  641.                     $fossil['formation'] = json_encode(array(array(
  642.                         'id' => $edited_fossil->getFormation()->getId(),
  643.                         'age_start' => $edited_fossil->getFormation()->getAgeStart(),
  644.                         'age_end' => $edited_fossil->getFormation()->getAgeEnd(),
  645.                         'value' => $edited_fossil->getFormation()->getNameNl(),
  646.                         'name_en' => $edited_fossil->getFormation()->getNameEn(),
  647.                         'color' => $edited_fossil->getFormation()->getColor()
  648.                     )));
  649.                 } else { $fossil['formation'] = json_encode(array()); }
  650.                 $fossil['edited']['formation'] = 1;
  651.             } else {
  652.                 if(!is_null($item->getFormation())) {
  653.                     $fossil['formation'] = json_encode(array(array(
  654.                         'id' => $item->getFormation()->getId(),
  655.                         'age_start' => $item->getFormation()->getAgeStart(),
  656.                         'age_end' => $item->getFormation()->getAgeEnd(),
  657.                         'value' => $item->getFormation()->getNameNl(),
  658.                         'name_en' => $item->getFormation()->getNameEn(),
  659.                         'color' => $item->getFormation()->getColor()
  660.                     )));
  661.                 } else { $fossil['formation'] = json_encode(array()); }
  662.                 $fossil['edited']['formation'] = 0;
  663.             }
  664.     
  665.             if ($edited == && ($edited_fossil->getMember() != $item->getMember())){
  666.                 if(!is_null($item->getMember())) {
  667.                     $fossil['member'] = json_encode(array(array(
  668.                         'id' => $edited_fossil->getMember()->getId(),
  669.                         'age_start' => $edited_fossil->getMember()->getAgeStart(),
  670.                         'age_end' => $edited_fossil->getMember()->getAgeEnd(),
  671.                         'value' => $edited_fossil->getMember()->getNameNl(),
  672.                         'name_en' => $edited_fossil->getMember()->getNameEn(),
  673.                         'color' => $edited_fossil->getMember()->getColor()
  674.                     )));
  675.                 } else { $fossil['member'] = json_encode(array()); }
  676.                 $fossil['edited']['member'] = 1;
  677.             } else {
  678.                 if(!is_null($item->getMember())) {
  679.                     $fossil['member'] = json_encode(array(array(
  680.                         'id' => $item->getMember()->getId(),
  681.                         'age_start' => $item->getMember()->getAgeStart(),
  682.                         'age_end' => $item->getMember()->getAgeEnd(),
  683.                         'value' => $item->getMember()->getNameNl(),
  684.                         'name_en' => $item->getMember()->getNameEn(),
  685.                         'color' => $item->getMember()->getColor()
  686.                     )));
  687.                 } else { $fossil['member'] = json_encode(array()); }
  688.                 $fossil['edited']['member'] = 0;
  689.             }
  690.     
  691.             if ($edited == && ($edited_fossil->getDateYear() != $item->getDateYear())){
  692.                 $fossil['date_year'] = $edited_fossil->getDateYear();
  693.                 $fossil['edited']['date_year'] = 1;
  694.             } else {
  695.                 $fossil['date_year'] = $item->getDateYear();
  696.                 $fossil['edited']['date_year'] = 0;
  697.             }
  698.             if ($edited == && ($edited_fossil->getDateMonth() != $item->getDateMonth())){
  699.                 $fossil['date_month'] = $edited_fossil->getDateMonth();
  700.                 $fossil['edited']['date_month'] = 1;
  701.             } else {
  702.                 $fossil['date_month'] = $item->getDateMonth();
  703.                 $fossil['edited']['date_month'] = 0;
  704.             }
  705.             if ($edited == && $edited_fossil->getDateDay() != $item->getDateDay()){
  706.                 $fossil['date_day'] = $edited_fossil->getDateDay();
  707.                 $fossil['edited']['date_day'] = 1;
  708.             } else {
  709.                 $fossil['date_day'] = $item->getDateDay();
  710.                 $fossil['edited']['date_day'] = 0;
  711.             }
  712.             if ($edited == && ($edited_fossil->getCommentNl() != $item->getCommentNl())){
  713.                 $fossil['comment_nl'] = $edited_fossil->getCommentNl();
  714.                 $fossil['edited']['comment_nl'] = 1;
  715.             } else {                
  716.                 $fossil['comment_nl'] = $item->getCommentNl();
  717.                 $fossil['edited']['comment_nl'] = 0;
  718.             }
  719.             if ($edited == && ($edited_fossil->getCommentEn() != $item->getCommentEn())){
  720.                 $fossil['comment_en'] = $edited_fossil->getCommentEn();
  721.                 $fossil['edited']['comment_en'] = 1;
  722.             } else {
  723.                 $fossil['comment_en'] = $item->getCommentEn();
  724.                 $fossil['edited']['comment_en'] = 0;
  725.             }
  726.             if ($edited == && ($edited_fossil->getUserNumber() != $item->getUserNumber())){
  727.                 $fossil['user_number'] = $edited_fossil->getUserNumber();
  728.                 $fossil['edited']['user_number'] = 1;
  729.             } else {
  730.                 $fossil['user_number'] = $item->getUserNumber();
  731.                 $fossil['edited']['user_number'] = 0;
  732.             }
  733.             if ($edited == && ($edited_fossil->getLiterature() != $item->getLiterature())){
  734.                 if(!is_null($item->getLiterature())) {
  735.                     $fossil['literature'] = json_encode(array(array(
  736.                         'id' => $edited_fossil->getLiterature()->getId(),
  737.                         'value' => $edited_fossil->getLiterature()->getAuthor()." (".$edited_fossil->getLiterature()->getyear().") - ".$edited_fossil->getLiterature()->getTitle(),
  738.                         'title' => $edited_fossil->getLiterature()->getTitle(),
  739.                         'year' => $edited_fossil->getLiterature()->getyear()
  740.                     )));
  741.                 } else { $fossil['literature'] = json_encode(array()); }
  742.                 $fossil['edited']['literature'] = 1;
  743.             } else {
  744.                 if(!is_null($item->getLiterature())) {
  745.                     $fossil['literature'] = json_encode(array(array(
  746.                         'id' => $item->getLiterature()->getId(),
  747.                         'value' => $item->getLiterature()->getAuthor()." (".$item->getLiterature()->getyear().") - ".$item->getLiterature()->getTitle(),
  748.                         'title' => $item->getLiterature()->getTitle(),
  749.                         'year' => $item->getLiterature()->getyear()
  750.                     )));
  751.                 } else { $fossil['literature'] = json_encode(array()); }
  752.                 $fossil['edited']['literature'] = 0;
  753.             }
  754.             $filter = array( 'genus' => $fossil['genus'], 'species' => $fossil['species'], 'publication' => $fossil['publication'], 'taxanomy' => $fossil['taxanomy'], 'location' => $fossil['location_fossil'], 'era' => $fossil['era'], 'epoch' => $fossil['epoch'], 'stage' => $fossil['stage'], 'literature' => $fossil['literature']);
  755.             $fossil['photos'] = $item->getFossildbPhotos();
  756.     
  757.             $form $this->createForm(FossildbFossilEditFormType::class, $fossil);
  758.             $form->handleRequest($request);
  759.             if ($form->isSubmitted() && $form->isValid()){
  760.                 
  761.                 $fossil_old $fossil;
  762.                 $fossil $form->getData();
  763.     
  764.                 if(!is_null($fossil['location_fossil']) && ($fossil_old['location_fossil'] != $fossil['location_fossil'])) {
  765.                     $repository $this->getDoctrine()->getRepository(LocationsFossil::class);
  766.                     $location_fossil $repository->findOneBy(array('id' => json_decode($fossil['location_fossil'])[0]->id));
  767.                 } else {
  768.                     if(!is_null($edited_fossil) && !is_null($edited_fossil->getLocationFossil())) {
  769.                         $location_fossil=$edited_fossil->getLocationFossil();
  770.                     } else {
  771.                         $location_fossil=null;
  772.                     }
  773.                 }
  774.     
  775.                 if(!is_null($fossil['taxanomy']) && ($fossil_old['taxanomy'] != $fossil['taxanomy'])) {
  776.                     $repository $this->getDoctrine()->getRepository(Taxanomy::class);
  777.                     $taxanomy $repository->findOneBy(array('id' => json_decode($fossil['taxanomy'])[0]->id));
  778.                 } else {
  779.                     if(!is_null($edited_fossil) && !is_null($edited_fossil->getTaxanomy()))  {
  780.                         $taxanomy=$edited_fossil->getTaxanomy();
  781.                     } else {
  782.                         $taxanomy=null;
  783.                     }
  784.                 }
  785.     
  786.                 if(!is_null($fossil['era']) && (json_decode($fossil_old['era'])[0]->id != json_decode($fossil['era'])[0]->id)) {
  787.                     $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  788.                     $era $repository->findOneBy(array('id' => json_decode($fossil['era'])[0]->id));
  789.                 } else {
  790.                     if(!is_null($edited_fossil) && !is_null($edited_fossil->getEra()))  {
  791.                         $era=$edited_fossil->getEra();
  792.                     } else {
  793.                         $era=null;
  794.                     }
  795.                 }
  796.     
  797.                 if(!is_null($fossil['epoch']) && (json_decode($fossil_old['epoch'])[0]->id != json_decode($fossil['epoch'])[0]->id)) {
  798.                     $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  799.                     $epoch $repository->findOneBy(array('id' => json_decode($fossil['epoch'])[0]->id));
  800.                 } else {
  801.                     if(!is_null($edited_fossil) && !is_null($edited_fossil->getEpoch()))  {
  802.                         $epoch=$edited_fossil->getEpoch();
  803.                     } else {
  804.                         $epoch=null;
  805.                     }
  806.                 }
  807.     
  808.                 if(!is_null($fossil['stage']) && (json_decode($fossil_old['stage'])[0]->id != json_decode($fossil['stage'])[0]->id)) {
  809.                     $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  810.                     $stage $repository->findOneBy(array('id' => json_decode($fossil['stage'])[0]->id));
  811.                 } else {
  812.                     if(!is_null($edited_fossil) && !is_null($edited_fossil->getStage()))  {
  813.                         $stage=$edited_fossil->getStage();
  814.                     } else {
  815.                         $stage=null;
  816.                     }
  817.                 }
  818.     
  819.                 if(!is_null($fossil['formation']) && ($fossil_old['formation'] != $fossil['formation'])) {
  820.                     $formation_item json_decode($fossil['formation'])[0];
  821.                     if (property_exists($formation_item'id')) {
  822.                         $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  823.                         $formation $repository->findOneBy(array('id' => $formation_item->id));
  824.                     } else {
  825.                         $new_formation_item = new StratigraphyUnits;
  826.                         $new_formation_item->setType("member");
  827.                         $new_formation_item->setNameNl($formation_item->value);
  828.                         $new_formation_item->setNameEn($formation_item->value);
  829.                         $em->persist($new_formation_item);
  830.                         $em->flush();
  831.                         $formation $new_formation_item->getId();
  832.                     }
  833.                 } else {
  834.                     if(!is_null($edited_fossil) && !is_null($edited_fossil->getFormation()))  {
  835.                         $formation=$edited_fossil->getFormation();
  836.                     } else {
  837.                         $formation=null;
  838.                     }
  839.                 }
  840.     
  841.                 if(!is_null($fossil['member']) && ($fossil_old['member'] != $fossil['member'])) {
  842.                     $member_item json_decode($fossil['member'])[0];
  843.                     if (property_exists($member_item'id')) {
  844.                         $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  845.                         $member $repository->findOneBy(array('id' => $member_item->id));
  846.                     } else {
  847.                         $new_member_item = new StratigraphyUnits;
  848.                         $new_member_item->setType("member");
  849.                         $new_member_item->setNameNl($member_item->value);
  850.                         $new_member_item->setNameEn($member_item->value);
  851.                         $em->persist($new_member_item);
  852.                         $em->flush();
  853.                         $member $new_member_item;
  854.                     }
  855.                 } else {
  856.                     if(!is_null($edited_fossil) && !is_null($edited_fossil->getMember()))  {
  857.                         $member=$edited_fossil->getMember();
  858.                     } else {
  859.                         $member=null;
  860.                     }
  861.                 }
  862.                 if(!is_null($fossil['literature']) && ($fossil_old['literature'] != $fossil['literature'])) {
  863.                     $repository $this->getDoctrine()->getRepository(Literature::class);
  864.                     $literature $repository->findOneBy(array('id' => json_decode($fossil['literature'])[0]->id));
  865.                 } else {
  866.                     if(!is_null($edited_fossil) && !is_null($edited_fossil->getLiterature()))  {
  867.                         $literature=$edited_fossil->getLiterature();
  868.                     } else {
  869.                         $literature=null;
  870.                     }
  871.                 }
  872.                 if($fossil_old['date_year'] != $fossil['date_year']) {
  873.                     $date_year=$fossil['date_year'];
  874.                 } else {
  875.                     if(!is_null($edited_fossil) && !is_null($edited_fossil->getDateYear()))  {
  876.                         $date_year=$edited_fossil->getDateYear();
  877.                     } else {
  878.                         $date_year=null;
  879.                     }
  880.                 }
  881.                 if($fossil_old['date_month'] != $fossil['date_month']) {
  882.                     $date_month=$fossil['date_month'];
  883.                 } else {
  884.                     if(!is_null($edited_fossil) && !is_null($edited_fossil->getDateMonth()))  {
  885.                         $date_month=$edited_fossil->getDateMonth();
  886.                     } else {
  887.                         $date_month=null;
  888.                     }
  889.                 }
  890.                 /*if($fossil_old['date_day'] != $fossil['date_day']) {
  891.                     $date_day=$fossil['date_day'];
  892.                 } else {
  893.                     if(!is_null($edited_fossil) && !is_null($edited_fossil->getDateDay()))  {
  894.                         $date_day=$edited_fossil->getDateDay();
  895.                     } else {
  896.                         $date_day=null;
  897.                     }
  898.                 }*/
  899.                 if($fossil_old['date_day'] != $fossil['date_day']) {
  900.                     $date_day=$fossil['date_day'];
  901.                 } else {
  902.                     $date_day=$fossil_old['date_day'];
  903.                 }
  904.                 if($fossil_old['comment_nl'] != $fossil['comment_nl']) {
  905.                     $comment_nl=$fossil['comment_nl'];
  906.                 } else {
  907.                     if(!is_null($edited_fossil) && !is_null($edited_fossil->getCommentNl()))  {
  908.                         $comment_nl=$edited_fossil->getCommentNl();
  909.                     } else {
  910.                         $comment_nl=null;
  911.                     }
  912.                 }
  913.                 if($fossil_old['comment_en'] != $fossil['comment_en']) {
  914.                     $comment_en=$fossil['comment_en'];
  915.                 } else {
  916.                     if(!is_null($edited_fossil) && !is_null($edited_fossil->getCommentEn()))  {
  917.                         $comment_en=$edited_fossil->getCommentEn();
  918.                     } else {
  919.                         $comment_en=null;
  920.                     }
  921.                 }
  922.                 if($fossil_old['user_number'] != $fossil['user_number']) {
  923.                     $user_number=$fossil['user_number'];
  924.                 } else {
  925.                     if(!is_null($edited_fossil) && !is_null($edited_fossil->getUserNumber()))  {
  926.                         $user_number=$edited_fossil->getUserNumber();
  927.                     } else {
  928.                         $user_number=null;
  929.                     }
  930.                 }
  931.                 $repository $this->getDoctrine()->getRepository(FossildbFossilEdits::class);
  932.                 $fossildbFossil $repository->findOneBy(array('fossil' => $item));
  933.                 if(!$fossildbFossil) {
  934.                     $fossildbFossil = new FossildbFossilEdits;
  935.                 }
  936.                 $fossildbFossil->setFossil($item);
  937.                 if(json_decode($fossil['genus'])[0] && ($fossil_old['genus'] != $fossil['genus'])) {
  938.                     $fossildbFossil->setGenus(json_decode($fossil['genus'])[0]->value);
  939.                 } else {
  940.                     if(!is_null($edited_fossil) && !is_null($edited_fossil->getGenus()))  {
  941.                         $fossildbFossil->setGenus($edited_fossil->getGenus());
  942.                     } else {
  943.                         $fossildbFossil->setGenus(null);
  944.                     }
  945.                 }
  946.                 if(json_decode($fossil['species'])[0] && ($fossil_old['species'] != $fossil['species'])) {
  947.                     $fossildbFossil->setSpecies(json_decode($fossil['species'])[0]->value);
  948.                 } else {
  949.                     if(!is_null($edited_fossil) && !is_null($edited_fossil->getSpecies()))  {
  950.                         $fossildbFossil->setSpecies($edited_fossil->getSpecies());
  951.                     } else {
  952.                         $fossildbFossil->setSpecies(null);
  953.                     }
  954.                 }
  955.                 if(json_decode($fossil['publication'])[0] && ($fossil_old['publication'] != $fossil['publication'])) {
  956.                     $fossildbFossil->setPublication(json_decode($fossil['publication'])[0]->value);
  957.                 } else {
  958.                     if(!is_null($edited_fossil) && !is_null($edited_fossil->getPublication()))  {
  959.                         $fossildbFossil->setPublication($edited_fossil->getPublication());
  960.                     } else {
  961.                         $fossildbFossil->setPublication(null);
  962.                     }
  963.                 }
  964.                 $fossildbFossil->setLocationFossil($location_fossil);
  965.                 $fossildbFossil->setTaxanomy($taxanomy);
  966.                 $fossildbFossil->setEra($era);
  967.                 $fossildbFossil->setEpoch($epoch);
  968.                 $fossildbFossil->setStage($stage);
  969.                 $fossildbFossil->setFormation($formation);
  970.                 $fossildbFossil->setMember($member);
  971.                 $fossildbFossil->setDateYear($date_year);
  972.                 $fossildbFossil->setDateMonth($date_month);
  973.                 $fossildbFossil->setDateDay($date_day);
  974.                 $fossildbFossil->setCommentNl($comment_nl);
  975.                 $fossildbFossil->setCommentEn($comment_en);
  976.                 $fossildbFossil->setUserNumber($user_number);
  977.                 $fossildbFossil->setLiterature($literature);
  978.                 if(
  979.                     $fossildbFossil->getLocationFossil() == null &&
  980.                     $fossildbFossil->getTaxanomy() == null &&
  981.                     $fossildbFossil->getGenus() == null &&
  982.                     $fossildbFossil->getSpecies() == null &&
  983.                     $fossildbFossil->getPublication() == null &&
  984.                     $fossildbFossil->getLiterature() == null &&
  985.                     $fossildbFossil->getEra() == null &&
  986.                     $fossildbFossil->getEpoch() == null &&
  987.                     $fossildbFossil->getStage() == null &&
  988.                     $fossildbFossil->getFormation() == null &&
  989.                     $fossildbFossil->getMember() == null &&
  990.                     $fossildbFossil->getDateDay() == null &&
  991.                     $fossildbFossil->getDateMonth() == null &&
  992.                     $fossildbFossil->getDateYear() == null &&
  993.                     $fossildbFossil->getCommentNl() == null &&
  994.                     $fossildbFossil->getCommentEn() == null &&
  995.                     $fossildbFossil->getUserNumber() == null
  996.                 ) {
  997.                     
  998.                 } else {
  999.                     $em->persist($fossildbFossil);
  1000.                     $item->setHasEdits(1);
  1001.                     $em->persist($item);
  1002.                     $em->flush();
  1003.                 }
  1004.                 $fossil_id $item->getId();
  1005.                 if(!is_null($fossil['upload'])) {
  1006.                     $upload json_decode($fossil['upload']);
  1007.                     foreach($upload as $id => $item) {
  1008.                         if(!is_null($item)) {
  1009.                             $repository $this->getDoctrine()->getRepository(FossildbFossil::class);
  1010.                             $fossildbFossil $repository->findOneBy(array('id' => $fossil_old['id']));
  1011.                             $repository $this->getDoctrine()->getRepository(UploadQueue::class);
  1012.                             $queuefile $repository->findOneBy(array('system' => 'fossildb','filename' => $item->name));
  1013.                             if(!is_null($queuefile)) {
  1014.                                 $fossildbPhoto = new FossildbPhotos;
  1015.                                 $fossildbPhoto->setFossildbFossil($fossildbFossil);
  1016.                                 $fossildbPhoto->setType('fossil');
  1017.                                 $fossildbPhoto->setFilename($item->name);
  1018.                                 $fossildbPhoto->setAdded(new \DateTime());
  1019.                                 $fossildbPhoto->setUserId($this->getUser()->getId());
  1020.                                 $fossildbPhoto->setUsername($this->getUser()->getUsername());
  1021.                                 $fossildbPhoto->setApproved(0);
  1022.         
  1023.                                 $fp $em->createQueryBuilder('fp')
  1024.                                     ->from('App\Entity\FossildbPhotos''fp')
  1025.                                     ->addSelect('count(fp.id)')
  1026.                                     ->andWhere("fp.is_primary = 1")
  1027.                                     ->andWhere("fp.FossildbFossil = (:id)")
  1028.                                     ->setParameter('id'$item->id)
  1029.                                     ->getQuery()
  1030.                                     ->getSingleScalarResult();
  1031.                                 ;
  1032.                                 if($fp == 0) {
  1033.                                     $fossildbPhoto->setIsPrimary(1);
  1034.                                 } else {
  1035.                                     $fossildbPhoto->setIsPrimary(0);
  1036.                                 }
  1037.                                 $em->persist($fossildbPhoto);
  1038.                                 $em->remove($queuefile);
  1039.                                 $fossildbFossil->setNumNewPhotos($fossildbFossil->getNumNewPhotos()+1);
  1040.                                 $em->persist($fossildbFossil);
  1041.                                 $em->persist($item);
  1042.                                 $em->flush();
  1043.                             }
  1044.                         }
  1045.                     }
  1046.                 }
  1047.                 $this->addFlash('success'$translator->trans("Fossiel bijgewerkt. De wijzigingen zijn moeten nog goed gekeurd worden."));
  1048.     
  1049.                 return $this->redirectToRoute('fossildb');
  1050.             }
  1051.     
  1052.             if(is_null($filter['genus'])) {$filter['genus'] = '[""]';}
  1053.             if(is_null($filter['species'])) {$filter['species'] = '[""]';}
  1054.             if(is_null($filter['publication'])) {$filter['publication'] = '[""]';}
  1055.             if(is_null($filter['literature'])) {$filter['literature'] = '[""]';}
  1056.             if(is_null($filter['location'])) {$filter['location'] = '[""]';}
  1057.             if(is_null($filter['taxanomy'])) {$filter['taxanomy'] = '[""]';}
  1058.             if(is_null($filter['era'])) {$filter['era'] = '[""]';}
  1059.             if(is_null($filter['epoch'])) {$filter['epoch'] = '[""]';}
  1060.             if(is_null($filter['stage'])) {$filter['stage'] = '[""]';}
  1061.             return $this->render('fossildb_edit.html.twig', [
  1062.                 'filter' => $filter,
  1063.                 'formname' => 'fossildb_fossil_edit_form',
  1064.                 'edit' => true,
  1065.                 'item' => $fossil,
  1066.                 'title' => $translator->trans("Fossiel toevoegen"),
  1067.                 'button_text' => $translator->trans("Bewerken"),
  1068.                 'form' => $form->createView()
  1069.             ]);
  1070.         } else {
  1071.             return $this->render('message.html.twig', [
  1072.                 'title' => $translator->trans("Geen toegang"),
  1073.                 'message' => $translator->trans("Dit fossiel is niet van jou en je kan hem daarom niet bewerken."),
  1074.             ]);
  1075.         }
  1076.     }
  1077.     /**
  1078.      * @Route("/fossildb/fossil/{id}/review", name="fossildb_review_add")
  1079.      */
  1080.     public function fossildb_review_add(FossildbFossil $idRequest $requestEntityManagerInterface $emTranslatorInterface $translator)
  1081.     {
  1082.         $this->denyAccessUnlessGranted('ROLE_USER');
  1083.         if($_ENV['DISABLE_FORMS'] == "true") { return $this->render('maintenance_form_disabled.html.twig'); }
  1084.         $form $this->createForm(FossildbReviewsFormType::class);
  1085.         $form->handleRequest($request);
  1086.         if ($form->isSubmitted() && $form->isValid()){
  1087.             $review $form->getData();
  1088.             $review->setUserId($this->getUser()->getId());
  1089.             $review->setUsername($this->getUser()->getUsername());
  1090.             $review->setFossildbFossil($id);
  1091.             $id->setNumReviews($id->getNumReviews()+1);
  1092.             $em->persist($review);
  1093.             $em->persist($id);
  1094.             $em->flush();
  1095.             $this->addFlash('success'$translator->trans("Feedback doorgegeven"));
  1096.             return $this->redirectToRoute('fossildb_item',array('id' => $id->getId()                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ));
  1097.         }
  1098.         return $this->render('form_edit.html.twig', [
  1099.             'title' => $translator->trans("Feedback doorgeven"),
  1100.             'button_text' => $translator->trans("Insturen"),
  1101.             'form' => $form->createView()
  1102.         ]);
  1103.     }
  1104.     /**
  1105.      * @Route("/moderate/fossildb/{id}/review", name="fossildb_moderate_reviews")
  1106.      */
  1107.     public function moderate_review(FossildbFossil $idEntityManagerInterface $emTranslatorInterface $translator)
  1108.     {
  1109.         $this->denyAccessUnlessGranted('ROLE_MOD_FOSSILDB');
  1110.         return $this->render('fossildbreviews_moderate.html.twig', [
  1111.             'fossildb' => $id,
  1112.         ]);
  1113.     }
  1114.     /**
  1115.      * @Route("/moderate/fossildb/{fossildb}/review/{id}/read", name="fossildbreviews_moderate_read")
  1116.      */
  1117.     public function review_read(FossildbFossil $fossildbFossildbReviews $idEntityManagerInterface $emTranslatorInterface $translator)
  1118.     {
  1119.         $this->denyAccessUnlessGranted('ROLE_MOD_FOSSILDB');
  1120.         return $this->render('fossildbreview.html.twig', [
  1121.             'review' => $id,
  1122.             'fossildb' => $fossildb,
  1123.         ]);
  1124.     }
  1125.     /**
  1126.      * @Route("/moderate/fossildb/{fossildb}/review/{id}/delete", name="fossildbreviews_moderate_delete")
  1127.      */
  1128.     public function review_delete(FossildbFossil $fossildbFossildbReviews $idEntityManagerInterface $emTranslatorInterface $translator)
  1129.     {
  1130.         $this->denyAccessUnlessGranted('ROLE_MOD_FOSSILDB');
  1131.         $fossildb->setNumReviews($fossildb->getNumReviews()-1);
  1132.         $em->persist($fossildb);
  1133.         $em->remove($id);
  1134.         $em->flush();
  1135.         $this->addFlash('success'$translator->trans("Fossiel review verwijderd"));
  1136.         return $this->redirectToRoute('fossildb_moderate_reviews', array('id' => $fossildb->getId(), ));
  1137.     }
  1138.     /**
  1139.      * @Route("/moderate/fossildb/{item}/photos", name="fossildb_moderate_photos")
  1140.      */
  1141.     public function moderate_photos(FossildbFossil $itemEntityManagerInterface $emTranslatorInterface $translator)
  1142.     {
  1143.         $this->denyAccessUnlessGranted('ROLE_MOD_FOSSILDB');
  1144.         return $this->render('fossildbphotos_moderate.html.twig', [
  1145.             'fossildbfossil' => $item,
  1146.         ]);
  1147.     }
  1148.     /**
  1149.      * @Route("/fossildb/fossil/{id}/photo/add", name="fossildb_photo_add")
  1150.      */
  1151.     public function fossildb_photo_add(FossildbFossil $idRequest $requestEntityManagerInterface $emTranslatorInterface $translator)
  1152.     {
  1153.         $this->denyAccessUnlessGranted('ROLE_USER');
  1154.         if($_ENV['DISABLE_FORMS'] == "true") { return $this->render('maintenance_form_disabled.html.twig'); }
  1155.         if ($id->getUserId() == $this->getUser()->getId() || $this->isGranted('ROLE_MOD_FOSSILDB'))
  1156.         {
  1157.             $form $this->createForm(FossildbFossilAddPhotoFormType::class);
  1158.             $form->handleRequest($request);
  1159.             if ($form->isSubmitted() && $form->isValid()){
  1160.                 $fossil $form->getData();
  1161.                 if(!is_null($fossil['upload'])) {
  1162.                     $upload json_decode($fossil['upload']);
  1163.                     foreach($upload as $i => $item) {
  1164.                         if(!is_null($item)) {
  1165.                             $repository $this->getDoctrine()->getRepository(UploadQueue::class);
  1166.                             $queuefile $repository->findOneBy(array('system' => 'fossildb','filename' => $item->name));
  1167.                             if(!is_null($queuefile)) {
  1168.                                 $fossildbPhoto = new FossildbPhotos;
  1169.                                 $fossildbPhoto->setFossildbFossil($id);
  1170.                                 $fossildbPhoto->setType('fossil');
  1171.                                 $fossildbPhoto->setFilename($item->name);
  1172.                                 $fossildbPhoto->setAdded(new \DateTime());
  1173.                                 $fossildbPhoto->setUserId($this->getUser()->getId());
  1174.                                 $fossildbPhoto->setUsername($this->getUser()->getUsername());
  1175.                                 $fossildbPhoto->setApproved(0);
  1176.         
  1177.                                 $fp $em->createQueryBuilder('fp')
  1178.                                     ->from('App\Entity\FossildbPhotos''fp')
  1179.                                     ->addSelect('count(fp.id)')
  1180.                                     ->andWhere("fp.is_primary = 1")
  1181.                                     ->andWhere("fp.FossildbFossil = (:id)")
  1182.                                     ->setParameter('id'$id->getId())
  1183.                                     ->getQuery()
  1184.                                     ->getSingleScalarResult();
  1185.                                 ;
  1186.                                 if($fp == 0) {
  1187.                                     $fossildbPhoto->setIsPrimary(1);
  1188.                                 } else {
  1189.                                     $fossildbPhoto->setIsPrimary(0);
  1190.                                 }
  1191.                                 $em->persist($fossildbPhoto);
  1192.                                 $em->remove($queuefile);
  1193.                                 $id->setNumNewPhotos($id->getNumNewPhotos()+1);
  1194.                                 $em->persist($id);
  1195.                                 $em->flush();
  1196.     
  1197.                             }
  1198.                         }
  1199.                     }
  1200.                 }
  1201.                 $this->addFlash('success'$translator->trans("Foto's toegevoegd"));
  1202.                 return $this->redirectToRoute('fossildb_item', array('id' => $id->getId()));
  1203.             }
  1204.     
  1205.             return $this->render('fossildb_add_photo.html.twig', [
  1206.                 'title' => $translator->trans("Foto's toevoegen aan fossiel"),
  1207.                 'button_text' => $translator->trans("Toevoegen"),
  1208.                 'formname' => 'fossildb_fossil_add_photo_form',
  1209.                 'form' => $form->createView()
  1210.             ]);
  1211.         } else {
  1212.             return $this->render('bundles\TwigBundle\Exception\error403.html.twig', [
  1213.             ]);
  1214.         }
  1215.     }
  1216.     /**
  1217.      * @Route("/moderate/fossildb/{item}/photos/{photo}/approve", name="fossildb_photos_moderate_approve")
  1218.      */
  1219.     public function moderate_photos_approve(FossildbFossil $itemFossildbPhotos $photoEntityManagerInterface $emTranslatorInterface $translator)
  1220.     {
  1221.         $this->denyAccessUnlessGranted('ROLE_MOD_FOSSILDB');
  1222.         $repository $this->getDoctrine()->getRepository(FossildbPhotos::class);
  1223.         $query_primary $repository->findOneBy(array('FossildbFossil' => $item'is_primary' => 1));
  1224.         $photo->setApprovedUserId($this->getUser()->getId());
  1225.         $photo->setApprovedUsername($this->getUser()->getUsername());
  1226.         $photo->setApproved('1');
  1227.         if(!$query_primary) {
  1228.             $photo->setIsPrimary('1');
  1229.         } else {
  1230.             $photo->setIsPrimary('0');
  1231.         }
  1232.         $em->persist($photo);
  1233.         $item->setNumNewPhotos($item->getNumNewPhotos()-1);
  1234.         $em->persist($item);
  1235.         
  1236.         $em->flush();
  1237.         $this->addFlash('success'$translator->trans("Identificatie foto goedgekeurd"));
  1238.         return $this->redirectToRoute('fossildb_moderate_photos', array('item' => $item->getId()) );
  1239.     }
  1240.     /**
  1241.      * @Route("/moderate/fossildb/{item}/photos/{photo}/delete", name="fossildb_photos_moderate_delete")
  1242.      */
  1243.     public function moderate_photo_delete(FossildbFossil $itemFossildbPhotos $photoEntityManagerInterface $emTranslatorInterface $translator)
  1244.     {
  1245.         $this->denyAccessUnlessGranted('ROLE_MOD_FOSSILDB');
  1246.         if($photo->getApproved() == 0){
  1247.             $item->setNumNewPhotos($item->getNumNewPhotos()-1);
  1248.             $em->persist($item);
  1249.         }
  1250.       
  1251.         $filename $this->getParameter('fossildbphoto_directory')."/".substr($photo->getFilename(),0,2)."/".$photo->getFilename();
  1252.         $filename_small_thumbnail $this->getParameter('fossildbphotothumbnail_small_directory')."/".substr($photo->getFilename(),0,2)."/".$photo->getFilename();
  1253.         $filename_tiny_thumbnail $this->getParameter('fossildbphotothumbnail_tiny_directory')."/".substr($photo->getFilename(),0,2)."/".$photo->getFilename();
  1254.         $filesystem = new Filesystem();
  1255.         $filesystem->remove($filename);
  1256.         $filesystem->remove($filename_small_thumbnail);
  1257.         $filesystem->remove($filename_tiny_thumbnail);
  1258.         $em->remove($photo);
  1259.         
  1260.         $em->flush();
  1261.         
  1262.         $this->addFlash('success'$translator->trans("Locatie foto verwijderd"));
  1263.         return $this->redirectToRoute('fossildb_moderate_photos', array('item' => $item->getId()) );
  1264.     }
  1265.     /**
  1266.      * @Route("/moderate/fossildb/", name="fossildb_moderate")
  1267.      */
  1268.     public function fossildb_moderate(Request $requestEntityManagerInterface $emPaginatorInterface $paginator)
  1269.     {
  1270.         $this->denyAccessUnlessGranted('ROLE_MOD_FOSSILDB');
  1271.         $form $this->createForm(FossildbModeratorSearchFormType::class);
  1272.         $form->handleRequest($request);
  1273.         $taxanomy = array();
  1274.         $location = array();
  1275.         $era = array();
  1276.         $genus = array();
  1277.         $species = array();
  1278.         $user = array();
  1279.         
  1280.         if ($form->isSubmitted() && $form->isValid()){
  1281.             $filter $form->getData();
  1282.         } else {
  1283.             if(!$request->query->get('page')){
  1284.                 $filter=array(
  1285.                     'taxanomy'=> '[]',
  1286.                     'location' => '[]',
  1287.                     'era' => '[]',
  1288.                     'genus' => '[]',
  1289.                     'species' => '[]',
  1290.                     'user' => '[]',
  1291.                     'id' => null,
  1292.                     'property' => 'all'
  1293.                 );
  1294.                 $form->get('taxanomy')->setData("");
  1295.                 $form->get('location')->setData("");
  1296.                 $form->get('era')->setData("");
  1297.                 $form->get('genus')->setData("");
  1298.                 $form->get('species')->setData("");
  1299.                 $form->get('user')->setData("");
  1300.                 $form->get('id')->setData(null);
  1301.                 $form->get('property')->setData("all");
  1302.             } elseif($request->query->get('filter') && $request->query->get('page')) {
  1303.                 $filter $request->query->get('filter');
  1304.                 if(isset($filter['taxanomy']) && $filter['taxanomy'] != '[""]') { $form->get('taxanomy')->setData($filter['taxanomy']); } else { $form->get('taxanomy')->setData(''); $filter['taxanomy'] = null; };
  1305.                 if(isset($filter['location']) && $filter['location'] != '[""]') { $form->get('location')->setData($filter['location']); } else { $form->get('location')->setData(''); $filter['location'] = null; };
  1306.                 if(isset($filter['era']) && $filter['era'] != '[""]') { $form->get('era')->setData($filter['era']); } else { $form->get('era')->setData(''); $filter['era'] = null; };
  1307.                 if(isset($filter['genus']) && $filter['genus'] != '[""]') { $form->get('genus')->setData($filter['genus']); } else { $form->get('genus')->setData(null); $filter['genus'] = null;};
  1308.                 if(isset($filter['species']) && $filter['species'] != '[""]') { $form->get('species')->setData($filter['species']); } else { $form->get('species')->setData(null); $filter['species'] = null;};
  1309.                 if(isset($filter['user']) && $filter['user'] != '[""]') { $form->get('user')->setData($filter['user']); } else { $form->get('user')->setData(null); $filter['user'] = null;};
  1310.                 if(isset($filter['id']) && $filter['id'] != '') { $form->get('id')->setData($filter['id']); } else { $form->get('id')->setData(null); $filter['id'] = null;};
  1311.                 if(isset($filter['property']) && $filter['property'] != 'all') { $form->get('property')->setData($filter['property']); } else { $form->get('property')->setData('all'); $filter['property'] = 'all'; };
  1312.             } else {
  1313.                 dd("Unexpected Error");
  1314.             }
  1315.         }
  1316.         $filter_taxanomy json_decode($filter['taxanomy']);
  1317.         $filter_location json_decode($filter['location']);
  1318.         $filter_era json_decode($filter['era']);
  1319.         $filter_genus json_decode($filter['genus']);
  1320.         $filter_species json_decode($filter['species']);
  1321.         $filter_user json_decode($filter['user']);
  1322.         if(is_array($filter_taxanomy)) {
  1323.             foreach($filter_taxanomy as $id => $item) {
  1324.                 $taxanomy[] = $item->id;
  1325.             }
  1326.         }
  1327.         if(is_array($filter_location)) {
  1328.             foreach($filter_location as $id => $item) {
  1329.                 $location[] = $item->id;
  1330.             }
  1331.         }
  1332.         if(is_array($filter_era)) {
  1333.             foreach($filter_era as $id => $item) {
  1334.                 $era[] = $item->id;
  1335.             }
  1336.         }
  1337.         if(is_array($filter_genus)) {
  1338.             foreach($filter_genus as $id => $item) {
  1339.                 $genus[] = $item->value;
  1340.             }
  1341.         }
  1342.         if(is_array($filter_species)) {
  1343.             foreach($filter_species as $id => $item) {
  1344.                 $species[] = $item->value;
  1345.             }
  1346.         }
  1347.         if(is_array($filter_user)) {
  1348.             foreach($filter_user as $id => $item) {
  1349.                 $user[] = $item->id;
  1350.             }
  1351.         }
  1352.         if(is_null($filter['taxanomy'])) { $filter['taxanomy'] = '[""]'; }
  1353.         if(is_null($filter['location'])) { $filter['location'] = '[""]'; }
  1354.         if(is_null($filter['era'])) { $filter['era'] = '[""]'; }
  1355.         if(is_null($filter['genus'])) { $filter['genus'] = '[""]'; }
  1356.         if(is_null($filter['species'])) { $filter['species'] = '[""]'; }
  1357.         if(is_null($filter['user'])) { $filter['user'] = '[""]'; }
  1358.         if(!is_numeric($filter['id'])) { $filter['id'] = null; }
  1359.         $qb $em->createQueryBuilder('f')
  1360.             ->from('App\Entity\FossildbFossil''f')
  1361.             ->addSelect('f')
  1362.             ->orderBy('f.id','DESC')
  1363.             ->AddOrderBy('f.approved','DESC')
  1364.             ->AddOrderBy('f.num_new_photos','DESC')
  1365.             ->AddOrderBy('f.num_reviews','ASC')
  1366.         ;
  1367.         if(!empty($taxanomy)) {
  1368.             $qb->andWhere("f.taxanomy IN (:taxanomy)")
  1369.                 ->setParameter('taxanomy'array_values($taxanomy))
  1370.             ;
  1371.         }
  1372.         if(!empty($location)) {
  1373.             $qb->andWhere("f.location_fossil IN (:location)")
  1374.                 ->setParameter('location'array_values($location))
  1375.             ;
  1376.         }
  1377.         if(!empty($era)) {
  1378.             $qb->andWhere("f.era IN (:era)")
  1379.                 ->setParameter('era'array_values($era))
  1380.             ;
  1381.         }
  1382.         if(!empty($genus)) {
  1383.             $qb->andWhere("f.genus = :genus")
  1384.                 ->setParameter('genus'array_values($genus))
  1385.             ;
  1386.         }
  1387.         if(!empty($species)) {
  1388.             $qb->andWhere("f.species = :species")
  1389.                 ->setParameter('species'array_values($species))
  1390.             ;
  1391.         }
  1392.         if(!empty($user)) {
  1393.             $qb->andWhere("f.user_id = :user")
  1394.                 ->setParameter('user'array_values($user))
  1395.             ;
  1396.         }
  1397.         if(!empty($filter['id'])) {
  1398.             $qb->andWhere("f.id = :id")
  1399.                 ->setParameter('id'$filter['id'])
  1400.             ;
  1401.         }
  1402.         if($filter['property'] == 'new') {
  1403.             $qb->andWhere("f.approved = 0");
  1404.         }
  1405.         elseif($filter['property'] == 'edited') {
  1406.             $qb->andWhere("f.has_edits = 1");
  1407.         }
  1408.         elseif($filter['property'] == 'reviews') {
  1409.             $qb->andWhere("f.num_reviews > 0");
  1410.         }
  1411.         elseif($filter['property'] == 'photos') {
  1412.             $qb->andWhere("f.num_new_photos > 0");
  1413.         }
  1414.         $result $paginator->paginate(
  1415.             $qb/* query NOT result */
  1416.             $request->query->getInt('page'1), /*page number*/
  1417.             10 /*limit per page*/
  1418.         );
  1419.         $result->setParam('filter'$filter);
  1420.         $result->setCustomParameters([
  1421.             'align' => 'right'# center|right (for template: twitter_bootstrap_v4_pagination)
  1422.         ]);
  1423.         return $this->render('fossildb_moderate.html.twig', [
  1424.             'form' => $form->createView(),
  1425.             'filter' => $filter,
  1426.             'result' => $result,
  1427.         ]);
  1428.     }
  1429.     /**
  1430.      * @Route("/moderate/fossildb/{item}/edit", name="fossildb_moderate_edit")
  1431.      */
  1432.     public function fossildb_moderate_edit(FossildbFossil $itemEntityManagerInterface $emRequest $requestTranslatorInterface $translator)
  1433.     {
  1434.         $this->denyAccessUnlessGranted('ROLE_MOD_FOSSILDB');
  1435.         $fossil=array();
  1436.         $fossil['genus'] = json_encode(array(array('value' => $item->getGenus())));
  1437.         $fossil['species'] = json_encode(array(array('value' => $item->getSpecies())));
  1438.         $fossil['publication'] = json_encode(array(array('value' => $item->getPublication())));
  1439.         if(!is_null($item->getTaxanomy())) {
  1440.             if($translator->getLocale() == 'nl') {
  1441.                 $name $item->getTaxanomy()->getNameNl();
  1442.             } else {
  1443.                 $name $item->getTaxanomy()->getNameEn();
  1444.             }
  1445.             if($item->getTaxanomy()->getNameScientificClarification() != '' || is_null($item->getTaxanomy()->getNameScientificClarification())) {
  1446.                 $scientific $item->getTaxanomy()->getNameScientific() . " " $item->getTaxanomy()->getNameScientificClarification();
  1447.                 $filename $item->getTaxanomy()->getNameScientific() . $item->getTaxanomy()->getNameScientificClarification();
  1448.             } else {
  1449.                 $scientific $item->getTaxanomy()->getNameScientific();
  1450.                 $filename $item->getTaxanomy()->getNameScientific();
  1451.             }
  1452.             $fossil['taxanomy'] = json_encode(array(array(
  1453.                 'id' => $item->getTaxanomy()->getId(),
  1454.                 'value' => $name." (".$scientific.")",
  1455.                 'filename' => $filename,
  1456.             )));
  1457.         } else { $fossil['taxanomy'] = json_encode(array()); }
  1458.         if(!is_null($item->getLocationFossil())) {
  1459.             $fossil['location_fossil'] = json_encode(array(array(
  1460.                 'id' => $item->getLocationFossil()->getId(),
  1461.                 'value' => $item->getLocationFossil()->getNameNl(),
  1462.                 'name_en' => $item->getLocationFossil()->getNameEn(),
  1463.                 'location' => $item->getLocationFossil()->getLocation()
  1464.             )));
  1465.         } else { $fossil['location_fossil'] = json_encode(array()); }
  1466.         if(!is_null($item->getEra())) {
  1467.             $fossil['era'] = json_encode(array(array(
  1468.                 'id' => $item->getEra()->getId(),
  1469.                 'age_start' => $item->getEra()->getAgeStart(),
  1470.                 'age_end' => $item->getEra()->getAgeEnd(),
  1471.                 'value' => $item->getEra()->getNameNl(),
  1472.                 'name_en' => $item->getEra()->getNameEn(),
  1473.                 'color' => $item->getEra()->getColor()
  1474.             )));
  1475.         } else { $fossil['era'] = json_encode(array()); }
  1476.         if(!is_null($item->getEpoch())) {
  1477.             $fossil['epoch'] = json_encode(array(array(
  1478.                 'id' => $item->getEpoch()->getId(),
  1479.                 'age_start' => $item->getEpoch()->getAgeStart(),
  1480.                 'age_end' => $item->getEpoch()->getAgeEnd(),
  1481.                 'value' => $item->getEpoch()->getNameNl(),
  1482.                 'name_en' => $item->getEpoch()->getNameEn(),
  1483.                 'color' => $item->getEpoch()->getColor()
  1484.             )));
  1485.         } else { $fossil['epoch'] = json_encode(array()); }
  1486.         if(!is_null($item->getStage())) {
  1487.             $fossil['stage'] = json_encode(array(array(
  1488.                 'id' => $item->getStage()->getId(),
  1489.                 'age_start' => $item->getStage()->getAgeStart(),
  1490.                 'age_end' => $item->getStage()->getAgeEnd(),
  1491.                 'value' => $item->getStage()->getNameNl(),
  1492.                 'name_en' => $item->getStage()->getNameEn(),
  1493.                 'color' => $item->getStage()->getColor()
  1494.             )));
  1495.         } else { $fossil['stage'] = json_encode(array()); }
  1496.         if(!is_null($item->getFormation())) {
  1497.             $fossil['formation'] = json_encode(array(array(
  1498.                 'id' => $item->getFormation()->getId(),
  1499.                 'age_start' => $item->getFormation()->getAgeStart(),
  1500.                 'age_end' => $item->getFormation()->getAgeEnd(),
  1501.                 'value' => $item->getFormation()->getNameNl(),
  1502.                 'name_en' => $item->getFormation()->getNameEn(),
  1503.                 'color' => $item->getFormation()->getColor()
  1504.             )));
  1505.         } else { $fossil['formation'] = json_encode(array()); }
  1506.         if(!is_null($item->getMember())) {
  1507.             $fossil['member'] = json_encode(array(array(
  1508.                 'id' => $item->getMember()->getId(),
  1509.                 'age_start' => $item->getMember()->getAgeStart(),
  1510.                 'age_end' => $item->getMember()->getAgeEnd(),
  1511.                 'value' => $item->getMember()->getNameNl(),
  1512.                 'name_en' => $item->getMember()->getNameEn(),
  1513.                 'color' => $item->getMember()->getColor()
  1514.             )));
  1515.         } else { $fossil['member'] = json_encode(array()); }
  1516.         $fossil['date_year'] = $item->getDateYear();
  1517.         $fossil['date_month'] = $item->getDateMonth();
  1518.         $fossil['date_day'] = $item->getDateDay();
  1519.         $fossil['comment_nl'] = $item->getCommentNl();
  1520.         $fossil['comment_en'] = $item->getCommentEn();
  1521.         $fossil['user_number'] = $item->getUserNumber();
  1522.         $fossil['approved'] = $item->getApproved();
  1523.         if(!is_null($item->getLiterature())) {
  1524.             $fossil['literature'] = json_encode(array(array(
  1525.                 'id' => $item->getLiterature()->getId(),
  1526.                 'value' => $item->getLiterature()->getAuthor()." (".$item->getLiterature()->getyear().") - ".$item->getLiterature()->getTitle(),
  1527.                 'title' => $item->getLiterature()->getTitle(),
  1528.                 'year' => $item->getLiterature()->getyear()
  1529.             )));
  1530.         } else { $fossil['literature'] = json_encode(array()); }
  1531.         $filter = array( 'genus' => $fossil['genus'], 'species' => $fossil['species'], 'publication' => $fossil['publication'], 'taxanomy' => $fossil['taxanomy'], 'location' => $fossil['location_fossil'], 'era' => $fossil['era'], 'epoch' => $fossil['epoch'], 'stage' => $fossil['stage'], 'literature' => $fossil['literature']);
  1532.         $form $this->createForm(FossildbFossilModeratorEditFormType::class, $fossil);
  1533.         $form->handleRequest($request);
  1534.         if ($form->isSubmitted() && $form->isValid()){
  1535.             $fossil $form->getData();
  1536.             if(!is_null($fossil['location_fossil'])) {
  1537.                 $repository $this->getDoctrine()->getRepository(LocationsFossil::class);
  1538.                 $location_fossil $repository->findOneBy(array('id' => json_decode($fossil['location_fossil'])[0]->id));
  1539.             } else {
  1540.                 $location_fossil=null;
  1541.             }
  1542.             if(!is_null($fossil['taxanomy'])) {
  1543.                 $repository $this->getDoctrine()->getRepository(Taxanomy::class);
  1544.                 $taxanomy $repository->findOneBy(array('id' => json_decode($fossil['taxanomy'])[0]->id));
  1545.             } else {
  1546.                 $taxanomy=null;
  1547.             }
  1548.             if(!is_null($fossil['era'])) {
  1549.                 $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  1550.                 $era $repository->findOneBy(array('id' => json_decode($fossil['era'])[0]->id));
  1551.             } else {
  1552.                 $era=null;
  1553.             }
  1554.             if(!is_null($fossil['epoch'])) {
  1555.                 $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  1556.                 $epoch $repository->findOneBy(array('id' => json_decode($fossil['epoch'])[0]->id));
  1557.             } else {
  1558.                 $epoch=null;
  1559.             }
  1560.             if(!is_null($fossil['stage'])) {
  1561.                 $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  1562.                 $stage $repository->findOneBy(array('id' => json_decode($fossil['stage'])[0]->id));
  1563.             } else {
  1564.                 $stage=null;
  1565.             }
  1566.             if(!is_null($fossil['formation'])) {
  1567.                 $formation_item json_decode($fossil['formation'])[0];
  1568.                 if (property_exists($formation_item'id')) {
  1569.                     $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  1570.                     $formation $repository->findOneBy(array('id' => $formation_item->id));
  1571.                 } else {
  1572.                     $new_formation_item = new StratigraphyUnits;
  1573.                     $new_formation_item->setType("member");
  1574.                     $new_formation_item->setNameNl($formation_item->value);
  1575.                     $new_formation_item->setNameEn($formation_item->value);
  1576.                     $em->persist($new_formation_item);
  1577.                     $em->flush();
  1578.                     $formation $new_formation_item->getId();
  1579.                 }
  1580.             } else {
  1581.                 $formation=null;
  1582.             }
  1583.             if(!is_null($fossil['member'])) {
  1584.                 $member_item json_decode($fossil['member'])[0];
  1585.                 if (property_exists($member_item'id')) {
  1586.                     $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  1587.                     $member $repository->findOneBy(array('id' => $member_item->id));
  1588.                 } else {
  1589.                     $new_member_item = new StratigraphyUnits;
  1590.                     $new_member_item->setType("member");
  1591.                     $new_member_item->setNameNl($member_item->value);
  1592.                     $new_member_item->setNameEn($member_item->value);
  1593.                     $em->persist($new_member_item);
  1594.                     $em->flush();
  1595.                     $member $new_member_item;
  1596.                 }
  1597.             } else {
  1598.                 $member=null;
  1599.             }
  1600.             if(!is_null($fossil['literature'])) {
  1601.                 $repository $this->getDoctrine()->getRepository(Literature::class);
  1602.                 $literature $repository->findOneBy(array('id' => json_decode($fossil['literature'])[0]->id));
  1603.             } else {
  1604.                 $literature=null;
  1605.             }
  1606.             $fossildbFossil $item;
  1607.             if(json_decode($fossil['genus'])[0]) {
  1608.                 $fossildbFossil->setGenus(json_decode($fossil['genus'])[0]->value);
  1609.             }
  1610.             if(json_decode($fossil['species'])[0]) {
  1611.                 $fossildbFossil->setSpecies(json_decode($fossil['species'])[0]->value);
  1612.             }
  1613.             if(json_decode($fossil['publication'])[0]) {
  1614.                 $fossildbFossil->setPublication(json_decode($fossil['publication'])[0]->value);
  1615.             }
  1616.             $fossildbFossil->setLocationFossil($location_fossil);
  1617.             $fossildbFossil->setTaxanomy($taxanomy);
  1618.             $fossildbFossil->setEra($era);
  1619.             $fossildbFossil->setEpoch($epoch);
  1620.             $fossildbFossil->setStage($stage);
  1621.             $fossildbFossil->setFormation($formation);
  1622.             $fossildbFossil->setMember($member);
  1623.             $fossildbFossil->setDateYear($fossil['date_year']);
  1624.             $fossildbFossil->setDateMonth($fossil['date_month']);
  1625.             $fossildbFossil->setDateDay($fossil['date_day']);
  1626.             $fossildbFossil->setCommentNl($fossil['comment_nl']);
  1627.             $fossildbFossil->setCommentEn($fossil['comment_en']);
  1628.             $fossildbFossil->setUserNumber($fossil['user_number']);
  1629.             $fossildbFossil->setLiterature($literature);
  1630.             $constructed_taxanomy_tree=$this->taxanomy_tree(json_decode($fossil['taxanomy'])[0]->id$em);
  1631.             $taxanomy_tree = array();
  1632.             foreach($constructed_taxanomy_tree as $i => $object) {
  1633.                 $taxanomy_tree[$i]['namescientific'] = $object->getNameScientific();
  1634.                 $taxanomy_tree[$i]['namescientificclarification'] = $object->getNameScientificClarification();
  1635.                 $taxanomy_tree[$i]['namenl'] = $object->getNameNl();
  1636.                 $taxanomy_tree[$i]['nameen'] = $object->getNameEn();
  1637.                 $taxanomy_tree[$i]['author'] = $object->getAuthor();
  1638.                 $taxanomy_tree[$i]['authoryear'] = $object->getAuthorYear();
  1639.                 if($object->getGlossary()){
  1640.                     $taxanomy_tree[$i]['glossary']['id'] = $object->getGlossary()->getId();
  1641.                     $taxanomy_tree[$i]['glossary']['url'] = $object->getGlossary()->getUrl();
  1642.                     $taxanomy_tree[$i]['glossary']['titlenl'] = $object->getGlossary()->getTitleNl();
  1643.                     $taxanomy_tree[$i]['glossary']['titleen'] = $object->getGlossary()->getTitleEn();
  1644.                 } else {
  1645.                     $taxanomy_tree[$i]['glossary'] = null;
  1646.                 }
  1647.                 $taxanomy_tree[$i]['taxanomyrank']['namescientific'] = $object->getTaxanomyRank()->getNameScientific();
  1648.                 $taxanomy_tree[$i]['taxanomyrank']['namenl'] = $object->getTaxanomyRank()->getNameNl();
  1649.                 $taxanomy_tree[$i]['taxanomyrank']['nameen'] = $object->getTaxanomyRank()->getNameEn();
  1650.             }
  1651.             $fossildbFossil->setTaxanomyTree(array_reverse($taxanomy_tree));
  1652.             $fossildbFossil->setEdited(new \DateTime());
  1653.             $fossildbFossil->setEditedUserId($this->getUser()->getId());
  1654.             $fossildbFossil->setEditedUsername($this->getUser()->getUsername());
  1655.             $fossildbFossil->setApproved($fossil["approved"]);
  1656.             $fossildbFossil->setNumReviews($item->getNumReviews());
  1657.             $fossildbFossil->setNumNewPhotos($item->getNumNewPhotos());
  1658.             $em->persist($fossildbFossil);
  1659.             $repository $em->getRepository(SearchItems::class);
  1660.             $searchitem $repository->findOneBy(array('path' => $this->router->generate('fossildb_item', [ 'id' => $fossildbFossil->getId() ]) ));
  1661.             if ($fossildbFossil->getApproved() == 1){
  1662.                 $newsfeed = new Newsfeed();
  1663.                 $newsfeed->setTitleNl($fossildbFossil->getGenus()." ".$fossildbFossil->getSpecies());
  1664.                 $newsfeed->setTitleEn($fossildbFossil->getGenus()." ".$fossildbFossil->getSpecies());
  1665.                 $newsfeed->setRemoteId($fossildbFossil->getId());
  1666.                 $newsfeed->setIsUpdate(1);
  1667.                 $newsfeed->setType('fossildb');
  1668.                 $newsfeed->setTime(new \DateTime());
  1669.                 $em $this->getDoctrine()->getManager();
  1670.                 $em->persist($newsfeed);
  1671.                 if(!$searchitem) {
  1672.                     $searchitem = new SearchItems();
  1673.                 }
  1674.                 $searchitem->setType('fossildb');
  1675.                 $searchitem->setPath($this->router->generate('fossildb_item', [ 'id' => $fossildbFossil->getId() ]));
  1676.                 $name_nl_add '';
  1677.                 $name_en_add '';
  1678.                 $keywords_nl_add '';
  1679.                 $keywords_en_add '';
  1680.                 if($fossildbFossil->getTaxanomy()) {
  1681.                     $name_nl_add $fossildbFossil->getTaxanomy()->getNameNl().' -> ';
  1682.                     $name_en_add $fossildbFossil->getTaxanomy()->getNameEn().' -> ';
  1683.                     $keywords_nl_add $fossildbFossil->getTaxanomy()->getNameScientific().','.$fossildbFossil->getTaxanomy()->getNameNl().',';
  1684.                     $keywords_en_add $fossildbFossil->getTaxanomy()->getNameScientific().','.$fossildbFossil->getTaxanomy()->getNameEn().',';
  1685.                 }
  1686.                 if(empty($item->getGenus()) && empty($item->getSpecies())){
  1687.                     
  1688.                     $name_nl_add .= '[Ongedetermineerd]';
  1689.                     $name_en_add .= '[Unidentified]';
  1690.                 }
  1691.                 $searchitem->setNameNl($name_nl_add.$fossildbFossil->getGenus().' '.$fossildbFossil->getSpecies());
  1692.                 $searchitem->setNameEn($name_en_add.$fossildbFossil->getGenus().' '.$fossildbFossil->getSpecies());
  1693.                 $searchitem->setKeywordsNl($keywords_nl_add.$fossildbFossil->getGenus().','.$fossildbFossil->getSpecies());
  1694.                 $searchitem->setKeywordsEn($keywords_en_add.$fossildbFossil->getGenus().','.$fossildbFossil->getSpecies());
  1695.                 if(empty($fossildbFossil->getEdited())) {
  1696.                     $searchitem->setLastUpdateTime($fossildbFossil->getAdded());
  1697.                 } else {
  1698.                     $searchitem->setLastUpdateTime($fossildbFossil->getEdited());
  1699.                 }
  1700.                 $em->persist($searchitem);
  1701.                 $em->flush();
  1702.             } else {
  1703.                 if($searchitem) {
  1704.                     $em->remove($searchitem);
  1705.                     $em->flush();
  1706.                 }
  1707.             }
  1708.             $em->flush();
  1709.             $repository $em->getRepository(FossildbFossil::class);
  1710.             $totalsubmissions $repository->createQueryBuilder('a')
  1711.                 ->select('count(a.id)')
  1712.                 ->andWhere("a.user_id = (:user)")
  1713.                 ->andWhere("a.approved = 1")
  1714.                 ->setParameter('user'$item->getUserId())
  1715.                 ->getQuery()
  1716.                 ->getSingleScalarResult();
  1717.     
  1718.             $repository $em->getRepository(User::class);
  1719.             $user $repository->findOneBy(array('id' => $item->getUserId()));
  1720.     
  1721.             $repository $this->getDoctrine()->getRepository(UserProfile::class);
  1722.             $userprofile $repository->findOneBy(array('user' => $user));
  1723.             if(!$userprofile) {
  1724.                 $userprofile = new UserProfile();
  1725.                 $userprofile->setUser($user);
  1726.             }
  1727.             $userprofile->setFossildbSubmissions($totalsubmissions);
  1728.             $em->persist($userprofile);
  1729.             $em->flush();
  1730.             $this->addFlash('success'$translator->trans("Fossiel bijgewerkt."));
  1731.             return $this->redirectToRoute('fossildb_moderate');
  1732.         }
  1733.         return $this->render('fossildb_edit.html.twig', [
  1734.             'moderate' => 1,
  1735.             'item' => $item,
  1736.             'filter' => $filter,
  1737.             'formname' => 'fossildb_fossil_moderator_edit_form',
  1738.             'title' => $translator->trans("Fossiel bijwerken"),
  1739.             'button_text' => $translator->trans("Bijwerken"),
  1740.             'form' => $form->createView()
  1741.         ]);
  1742.     }
  1743.     /**
  1744.      * @Route("/moderate/fossildb/{item}/edits", name="fossildb_moderate_approve_edits")
  1745.      */
  1746.     public function fossildb_moderate_approve_edits(FossildbFossil $itemEntityManagerInterface $emRequest $requestTranslatorInterface $translator)
  1747.     {
  1748.         $this->denyAccessUnlessGranted('ROLE_MOD_FOSSILDB');
  1749.         $filter = array( 'genus' => '[""]''species' => '[""]''publication' => '[""]''literature' => '[""]''location' => '[""]''taxanomy' => '[""]''era' => '[""]''epoch' => '[""]''stage' => '[""]');
  1750.         $fossil=array();
  1751.         $fossil['id'] = $item->getId();
  1752.         $repository $this->getDoctrine()->getRepository(FossildbFossilEdits::class);
  1753.         $edited_fossil $repository->findOneBy(array('fossil' => $item->getId()));
  1754.         if($edited_fossil){
  1755.             $edited 1;
  1756.         } else {
  1757.             $edited 0;
  1758.         }
  1759.         if ($edited == && ($edited_fossil->getGenus() != $item->getGenus())){
  1760.             $fossil['genus'] = json_encode(array(array('value' => $edited_fossil->getGenus())));
  1761.             $fossil['edited']['genus'] = 1;
  1762.         } else {
  1763.             $fossil['genus'] = json_encode(array(array('value' => $item->getGenus())));
  1764.             $fossil['edited']['genus'] = 0;
  1765.         }
  1766.         if ($edited == && ($edited_fossil->getSpecies() != $item->getSpecies())){
  1767.             $fossil['species'] = json_encode(array(array('value' => $edited_fossil->getSpecies())));
  1768.             $fossil['edited']['species'] = 1;
  1769.         } else {
  1770.             $fossil['species'] = json_encode(array(array('value' => $item->getSpecies())));
  1771.             $fossil['edited']['species'] = 0;
  1772.         }
  1773.         if ($edited == && ($edited_fossil->getPublication() != $item->getPublication())){
  1774.             $fossil['publication'] = json_encode(array(array('value' => $edited_fossil->getPublication())));
  1775.             $fossil['edited']['publication'] = 1;
  1776.         } else {
  1777.             $fossil['publication'] = json_encode(array(array('value' => $item->getPublication())));
  1778.             $fossil['edited']['publication'] = 0;
  1779.         }
  1780.         if ($edited == && ($edited_fossil->getTaxanomy() != $item->getTaxanomy())){
  1781.             if($translator->getLocale() == 'nl') {
  1782.                 $name $edited_fossil->getTaxanomy()->getNameNl();
  1783.             } else {
  1784.                 $name $edited_fossil->getTaxanomy()->getNameEn();
  1785.             }
  1786.             if($edited_fossil->getTaxanomy()->getNameScientificClarification() != '' || is_null($edited_fossil->getTaxanomy()->getNameScientificClarification())) {
  1787.                 $scientific $edited_fossil->getTaxanomy()->getNameScientific() . " " $edited_fossil->getTaxanomy()->getNameScientificClarification();
  1788.                 $filename $edited_fossil->getTaxanomy()->getNameScientific() . $edited_fossil->getTaxanomy()->getNameScientificClarification();
  1789.             } else {
  1790.                 $scientific $edited_fossil->getTaxanomy()->getNameScientific();
  1791.                 $filename $edited_fossil->getTaxanomy()->getNameScientific();
  1792.             }
  1793.             $fossil['taxanomy'] = json_encode(array(array(
  1794.                 'id' => $edited_fossil->getTaxanomy()->getId(),
  1795.                 'value' => $name." (".$scientific.")",
  1796.                 'filename' => $filename,
  1797.             )));
  1798.             $fossil['edited']['taxanomy'] = 1;
  1799.         } else {
  1800.             if(!is_null($item->getTaxanomy())) {
  1801.                 if($translator->getLocale() == 'nl') {
  1802.                     $name $item->getTaxanomy()->getNameNl();
  1803.                 } else {
  1804.                     $name $item->getTaxanomy()->getNameEn();
  1805.                 }
  1806.                 if($item->getTaxanomy()->getNameScientificClarification() != '' || is_null($item->getTaxanomy()->getNameScientificClarification())) {
  1807.                     $scientific $item->getTaxanomy()->getNameScientific() . " " $item->getTaxanomy()->getNameScientificClarification();
  1808.                     $filename $item->getTaxanomy()->getNameScientific() . $item->getTaxanomy()->getNameScientificClarification();
  1809.                 } else {
  1810.                     $scientific $item->getTaxanomy()->getNameScientific();
  1811.                     $filename $item->getTaxanomy()->getNameScientific();
  1812.                 }
  1813.                 $fossil['taxanomy'] = json_encode(array(array(
  1814.                     'id' => $item->getTaxanomy()->getId(),
  1815.                     'value' => $name." (".$scientific.")",
  1816.                     'filename' => $filename,
  1817.                 )));
  1818.             } else { $fossil['taxanomy'] = json_encode(array()); }
  1819.             $fossil['edited']['taxanomy'] = 0;
  1820.         }
  1821.         if ($edited == && ($edited_fossil->getLocationFossil() != $item->getLocationFossil())){
  1822.             if(!is_null($edited_fossil->getLocationFossil())) {
  1823.                 $fossil['location_fossil'] = json_encode(array(array(
  1824.                     'id' => $edited_fossil->getLocationFossil()->getId(),
  1825.                     'value' => $edited_fossil->getLocationFossil()->getNameNl(),
  1826.                     'name_en' => $edited_fossil->getLocationFossil()->getNameEn(),
  1827.                     'location' => $edited_fossil->getLocationFossil()->getLocation()
  1828.                 )));
  1829.             } else { $fossil['location_fossil'] = json_encode(array()); }
  1830.             $fossil['edited']['location_fossil'] = 0;
  1831.         } else {
  1832.             if(!is_null($item->getLocationFossil())) {
  1833.                 $fossil['location_fossil'] = json_encode(array(array(
  1834.                     'id' => $item->getLocationFossil()->getId(),
  1835.                     'value' => $item->getLocationFossil()->getNameNl(),
  1836.                     'name_en' => $item->getLocationFossil()->getNameEn(),
  1837.                     'location' => $item->getLocationFossil()->getLocation()
  1838.                 )));
  1839.             } else { $fossil['location_fossil'] = json_encode(array()); }
  1840.             $fossil['edited']['location_fossil'] = 0;
  1841.         }
  1842.         if ($edited == && ($edited_fossil->getEra() != $item->getEra())){
  1843.             if(!is_null($edited_fossil->getEra())) {
  1844.                 $fossil['era'] = json_encode(array(array(
  1845.                     'id' => $edited_fossil->getEra()->getId(),
  1846.                     'age_start' => $edited_fossil->getEra()->getAgeStart(),
  1847.                     'age_end' => $edited_fossil->getEra()->getAgeEnd(),
  1848.                     'value' => $edited_fossil->getEra()->getNameNl(),
  1849.                     'name_en' => $edited_fossil->getEra()->getNameEn(),
  1850.                     'color' => $edited_fossil->getEra()->getColor()
  1851.                 )));
  1852.             } else { $fossil['era'] = json_encode(array()); }
  1853.             $fossil['edited']['era'] = 1;
  1854.         } else {
  1855.             if(!is_null($item->getEra())) {
  1856.                 $fossil['era'] = json_encode(array(array(
  1857.                     'id' => $item->getEra()->getId(),
  1858.                     'age_start' => $item->getEra()->getAgeStart(),
  1859.                     'age_end' => $item->getEra()->getAgeEnd(),
  1860.                     'value' => $item->getEra()->getNameNl(),
  1861.                     'name_en' => $item->getEra()->getNameEn(),
  1862.                     'color' => $item->getEra()->getColor()
  1863.                 )));
  1864.             } else { $fossil['era'] = json_encode(array()); }
  1865.             $fossil['edited']['era'] = 0;
  1866.         }
  1867.         if ($edited == && ($edited_fossil->getEpoch() != $item->getEpoch())){
  1868.             if(!is_null($item->getEpoch())) {
  1869.                 $fossil['epoch'] = json_encode(array(array(
  1870.                     'id' => $edited_fossil->getEpoch()->getId(),
  1871.                     'age_start' => $edited_fossil->getEpoch()->getAgeStart(),
  1872.                     'age_end' => $edited_fossil->getEpoch()->getAgeEnd(),
  1873.                     'value' => $edited_fossil->getEpoch()->getNameNl(),
  1874.                     'name_en' => $edited_fossil->getEpoch()->getNameEn(),
  1875.                     'color' => $edited_fossil->getEpoch()->getColor()
  1876.                 )));
  1877.             } else { $fossil['epoch'] = json_encode(array()); }
  1878.             $fossil['edited']['epoch'] = 1;
  1879.         } else {
  1880.             if(!is_null($item->getEpoch())) {
  1881.                 $fossil['epoch'] = json_encode(array(array(
  1882.                     'id' => $item->getEpoch()->getId(),
  1883.                     'age_start' => $item->getEpoch()->getAgeStart(),
  1884.                     'age_end' => $item->getEpoch()->getAgeEnd(),
  1885.                     'value' => $item->getEpoch()->getNameNl(),
  1886.                     'name_en' => $item->getEpoch()->getNameEn(),
  1887.                     'color' => $item->getEpoch()->getColor()
  1888.                 )));
  1889.             } else { $fossil['epoch'] = json_encode(array()); }
  1890.             $fossil['edited']['epoch'] = 0;
  1891.         }
  1892.         if ($edited == && ($edited_fossil->getStage() != $item->getStage())){
  1893.             if(!is_null($item->getStage())) {
  1894.                 $fossil['stage'] = json_encode(array(array(
  1895.                     'id' => $edited_fossil->getStage()->getId(),
  1896.                     'age_start' => $edited_fossil->getStage()->getAgeStart(),
  1897.                     'age_end' => $edited_fossil->getStage()->getAgeEnd(),
  1898.                     'value' => $edited_fossil->getStage()->getNameNl(),
  1899.                     'name_en' => $edited_fossil->getStage()->getNameEn(),
  1900.                     'color' => $edited_fossil->getStage()->getColor()
  1901.                 )));
  1902.             } else { $fossil['stage'] = json_encode(array()); }
  1903.             $fossil['edited']['stage'] = 1;
  1904.         } else {
  1905.             if(!is_null($item->getStage())) {
  1906.                 $fossil['stage'] = json_encode(array(array(
  1907.                     'id' => $item->getStage()->getId(),
  1908.                     'age_start' => $item->getStage()->getAgeStart(),
  1909.                     'age_end' => $item->getStage()->getAgeEnd(),
  1910.                     'value' => $item->getStage()->getNameNl(),
  1911.                     'name_en' => $item->getStage()->getNameEn(),
  1912.                     'color' => $item->getStage()->getColor()
  1913.                 )));
  1914.             } else { $fossil['stage'] = json_encode(array()); }
  1915.             $fossil['edited']['stage'] = 0;
  1916.         }
  1917.         if ($edited == && ($edited_fossil->getFormation() != $item->getFormation())){
  1918.             if(!is_null($item->getFormation())) {
  1919.                 $fossil['formation'] = json_encode(array(array(
  1920.                     'id' => $edited_fossil->getFormation()->getId(),
  1921.                     'age_start' => $edited_fossil->getFormation()->getAgeStart(),
  1922.                     'age_end' => $edited_fossil->getFormation()->getAgeEnd(),
  1923.                     'value' => $edited_fossil->getFormation()->getNameNl(),
  1924.                     'name_en' => $edited_fossil->getFormation()->getNameEn(),
  1925.                     'color' => $edited_fossil->getFormation()->getColor()
  1926.                 )));
  1927.             } else { $fossil['formation'] = json_encode(array()); }
  1928.             $fossil['edited']['formation'] = 1;
  1929.         } else {
  1930.             if(!is_null($item->getFormation())) {
  1931.                 $fossil['formation'] = json_encode(array(array(
  1932.                     'id' => $item->getFormation()->getId(),
  1933.                     'age_start' => $item->getFormation()->getAgeStart(),
  1934.                     'age_end' => $item->getFormation()->getAgeEnd(),
  1935.                     'value' => $item->getFormation()->getNameNl(),
  1936.                     'name_en' => $item->getFormation()->getNameEn(),
  1937.                     'color' => $item->getFormation()->getColor()
  1938.                 )));
  1939.             } else { $fossil['formation'] = json_encode(array()); }
  1940.             $fossil['edited']['formation'] = 0;
  1941.         }
  1942.         if ($edited == && ($edited_fossil->getMember() != $item->getMember())){
  1943.             if(!is_null($item->getMember())) {
  1944.                 $fossil['member'] = json_encode(array(array(
  1945.                     'id' => $edited_fossil->getMember()->getId(),
  1946.                     'age_start' => $edited_fossil->getMember()->getAgeStart(),
  1947.                     'age_end' => $edited_fossil->getMember()->getAgeEnd(),
  1948.                     'value' => $edited_fossil->getMember()->getNameNl(),
  1949.                     'name_en' => $edited_fossil->getMember()->getNameEn(),
  1950.                     'color' => $edited_fossil->getMember()->getColor()
  1951.                 )));
  1952.             } else { $fossil['member'] = json_encode(array()); }
  1953.             $fossil['edited']['member'] = 1;
  1954.         } else {
  1955.             if(!is_null($item->getMember())) {
  1956.                 $fossil['member'] = json_encode(array(array(
  1957.                     'id' => $item->getMember()->getId(),
  1958.                     'age_start' => $item->getMember()->getAgeStart(),
  1959.                     'age_end' => $item->getMember()->getAgeEnd(),
  1960.                     'value' => $item->getMember()->getNameNl(),
  1961.                     'name_en' => $item->getMember()->getNameEn(),
  1962.                     'color' => $item->getMember()->getColor()
  1963.                 )));
  1964.             } else { $fossil['member'] = json_encode(array()); }
  1965.             $fossil['edited']['member'] = 0;
  1966.         }
  1967.         if ($edited == && ($edited_fossil->getDateYear() != $item->getDateYear())){
  1968.             $fossil['date_year'] = $edited_fossil->getDateYear();
  1969.             $fossil['edited']['date_year'] = 1;
  1970.         } else {
  1971.             $fossil['date_year'] = $item->getDateYear();
  1972.             $fossil['edited']['date_year'] = 0;
  1973.         }
  1974.         if ($edited == && ($edited_fossil->getDateMonth() != $item->getDateMonth())){
  1975.             $fossil['date_month'] = $edited_fossil->getDateMonth();
  1976.             $fossil['edited']['date_month'] = 1;
  1977.         } else {
  1978.             $fossil['date_month'] = $item->getDateMonth();
  1979.             $fossil['edited']['date_month'] = 0;
  1980.         }
  1981.         if ($edited == && $edited_fossil->getDateDay() != $item->getDateDay()){
  1982.             $fossil['date_day'] = $edited_fossil->getDateDay();
  1983.             $fossil['edited']['date_day'] = 1;
  1984.         } else {
  1985.             $fossil['date_day'] = $item->getDateDay();
  1986.             $fossil['edited']['date_day'] = 0;
  1987.         }
  1988.         if ($edited == && ($edited_fossil->getCommentNl() != $item->getCommentNl())){
  1989.             $fossil['comment_nl'] = $edited_fossil->getCommentNl();
  1990.             $fossil['edited']['comment_nl'] = 1;
  1991.         } else {                
  1992.             $fossil['comment_nl'] = $item->getCommentNl();
  1993.             $fossil['edited']['comment_nl'] = 0;
  1994.         }
  1995.         if ($edited == && ($edited_fossil->getCommentEn() != $item->getCommentEn())){
  1996.             $fossil['comment_en'] = $edited_fossil->getCommentEn();
  1997.             $fossil['edited']['comment_en'] = 1;
  1998.         } else {
  1999.             $fossil['comment_en'] = $item->getCommentEn();
  2000.             $fossil['edited']['comment_en'] = 0;
  2001.         }
  2002.         if ($edited == && ($edited_fossil->getUserNumber() != $item->getUserNumber())){
  2003.             $fossil['user_number'] = $edited_fossil->getUserNumber();
  2004.             $fossil['edited']['user_number'] = 1;
  2005.         } else {
  2006.             $fossil['user_number'] = $item->getUserNumber();
  2007.             $fossil['edited']['user_number'] = 0;
  2008.         }
  2009.         if ($edited == && ($edited_fossil->getLiterature() != $item->getLiterature())){
  2010.             if(!is_null($item->getLiterature())) {
  2011.                 $fossil['literature'] = json_encode(array(array(
  2012.                     'id' => $edited_fossil->getLiterature()->getId(),
  2013.                     'value' => $edited_fossil->getLiterature()->getAuthor()." (".$edited_fossil->getLiterature()->getyear().") - ".$edited_fossil->getLiterature()->getTitle(),
  2014.                     'title' => $edited_fossil->getLiterature()->getTitle(),
  2015.                     'year' => $edited_fossil->getLiterature()->getyear()
  2016.                 )));
  2017.             } else { $fossil['literature'] = json_encode(array()); }
  2018.             $fossil['edited']['literature'] = 1;
  2019.         } else {
  2020.             if(!is_null($item->getLiterature())) {
  2021.                 $fossil['literature'] = json_encode(array(array(
  2022.                     'id' => $item->getLiterature()->getId(),
  2023.                     'value' => $item->getLiterature()->getAuthor()." (".$item->getLiterature()->getyear().") - ".$item->getLiterature()->getTitle(),
  2024.                     'title' => $item->getLiterature()->getTitle(),
  2025.                     'year' => $item->getLiterature()->getyear()
  2026.                 )));
  2027.             } else { $fossil['literature'] = json_encode(array()); }
  2028.             $fossil['edited']['literature'] = 0;
  2029.         }
  2030.         $filter = array( 'genus' => $fossil['genus'], 'species' => $fossil['species'], 'publication' => $fossil['publication'], 'taxanomy' => $fossil['taxanomy'], 'location' => $fossil['location_fossil'], 'era' => $fossil['era'], 'epoch' => $fossil['epoch'], 'stage' => $fossil['stage'], 'literature' => $fossil['literature']);
  2031.         $fossil['photos'] = $item->getFossildbPhotos();
  2032.         $form $this->createForm(FossildbFossilEditFormType::class, $fossil);
  2033.         $form->handleRequest($request);
  2034.         if ($form->isSubmitted() && $form->isValid()){
  2035.             
  2036.             $fossil_old $fossil;
  2037.             $fossil $form->getData();
  2038.             if($fossil_old['location_fossil'] != $fossil['location_fossil']) {
  2039.                 if(!is_null($fossil['location_fossil'])) {
  2040.                     $repository $this->getDoctrine()->getRepository(LocationsFossil::class);
  2041.                     $location_fossil $repository->findOneBy(array('id' => json_decode($fossil['location_fossil'])[0]->id));
  2042.                 } else {
  2043.                     $location_fossil null;
  2044.                 }
  2045.             } else {
  2046.                 if(!is_null($fossil_old['location_fossil'])) {
  2047.                     $repository $this->getDoctrine()->getRepository(LocationsFossil::class);
  2048.                     $location_fossil $repository->findOneBy(array('id' => json_decode($fossil_old['location_fossil'])[0]->id));
  2049.                 } else {
  2050.                     $location_fossil null;
  2051.                 }
  2052.             }
  2053.             if($fossil_old['taxanomy'] != $fossil['taxanomy']) {
  2054.                 if(!is_null($fossil['taxanomy'])) {
  2055.                     $repository $this->getDoctrine()->getRepository(Taxanomy::class);
  2056.                     $taxanomy $repository->findOneBy(array('id' => json_decode($fossil['taxanomy'])[0]->id));
  2057.                 } else {
  2058.                     $taxanomy null;
  2059.                 }
  2060.             } else {
  2061.                 if(!is_null($fossil_old['taxanomy'])) {
  2062.                     $repository $this->getDoctrine()->getRepository(Taxanomy::class);
  2063.                     $taxanomy $repository->findOneBy(array('id' => json_decode($fossil_old['taxanomy'])[0]->id));
  2064.                 } else {
  2065.                     $taxanomy null;
  2066.                 }
  2067.             }
  2068.             if($fossil_old['era'] != $fossil['era']) {
  2069.                 if(!is_null($fossil['era'])) {
  2070.                     $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  2071.                     $era $repository->findOneBy(array('id' => json_decode($fossil['era'])[0]->id));
  2072.                 } else {
  2073.                     $era null;
  2074.                 }
  2075.             } else {
  2076.                 if(!is_null($fossil_old['era'])) {
  2077.                     $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  2078.                     $era $repository->findOneBy(array('id' => json_decode($fossil_old['era'])[0]->id));
  2079.                 } else {
  2080.                     $era null;
  2081.                 }
  2082.             }
  2083.             if($fossil_old['epoch'] != $fossil['epoch']) {
  2084.                 if(!is_null($fossil['epoch'])) {
  2085.                     $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  2086.                     $epoch $repository->findOneBy(array('id' => json_decode($fossil['epoch'])[0]->id));
  2087.                 } else {
  2088.                     $epoch null;
  2089.                 }
  2090.             } else {
  2091.                 if(!is_null($fossil_old['epoch'])) {
  2092.                     $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  2093.                     $epoch $repository->findOneBy(array('id' => json_decode($fossil_old['epoch'])[0]->id));
  2094.                 } else {
  2095.                     $epoch null;
  2096.                 }
  2097.             }
  2098.             if($fossil_old['stage'] != $fossil['stage']) {
  2099.                 if(!is_null($fossil['stage'])) {
  2100.                     $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  2101.                     $stage $repository->findOneBy(array('id' => json_decode($fossil['stage'])[0]->id));
  2102.                 } else {
  2103.                     $stage null;
  2104.                 }
  2105.             } else {
  2106.                 if(!is_null($fossil_old['stage'])) {
  2107.                     $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  2108.                     $stage $repository->findOneBy(array('id' => json_decode($fossil_old['stage'])[0]->id));
  2109.                 } else {
  2110.                     $stage null;
  2111.                 }
  2112.             }
  2113.             if($fossil_old['formation'] != $fossil['formation']) {
  2114.                 $formation_item json_decode($fossil['formation'])[0];
  2115.                 if (is_null($formation_item)) {
  2116.                     $formation null;
  2117.                 } elseif (property_exists($formation_item'id')) {
  2118.                     $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  2119.                     $formation $repository->findOneBy(array('id' => $formation_item->id));
  2120.                 } else {
  2121.                     $new_formation_item = new StratigraphyUnits;
  2122.                     $new_formation_item->setType("member");
  2123.                     $new_formation_item->setNameNl($formation_item->value);
  2124.                     $new_formation_item->setNameEn($formation_item->value);
  2125.                     $em->persist($new_formation_item);
  2126.                     $em->flush();
  2127.                     $formation $new_formation_item->getId();
  2128.                 }
  2129.             } else {
  2130.                 if(!is_null($fossil_old['formation'])){
  2131.                     $formation_item json_decode($fossil_old['formation'])[0];
  2132.                     $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  2133.                     $formation $repository->findOneBy(array('id' => $formation_item->id));
  2134.                 } else {
  2135.                     $formation null;
  2136.                 }
  2137.             }
  2138.             if($fossil_old['member'] != $fossil['member']) {
  2139.                 $member_item json_decode($fossil['member'])[0];
  2140.                 if (is_null($member_item)) {
  2141.                     $member null;
  2142.                 } elseif  (property_exists($member_item'id')) {
  2143.                     $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  2144.                     $member $repository->findOneBy(array('id' => $member_item->id));
  2145.                 } else {
  2146.                     $new_member_item = new StratigraphyUnits;
  2147.                     $new_member_item->setType("member");
  2148.                     $new_member_item->setNameNl($member_item->value);
  2149.                     $new_member_item->setNameEn($member_item->value);
  2150.                     $em->persist($new_member_item);
  2151.                     $em->flush();
  2152.                     $member $new_member_item;
  2153.                 }
  2154.             } else {
  2155.                 if(!is_null($fossil_old['member'])){
  2156.                     $member_item json_decode($fossil_old['member'])[0];
  2157.                     $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  2158.                     $member $repository->findOneBy(array('id' => $member_item->id));
  2159.                 } else {
  2160.                     $member null;
  2161.                 }
  2162.             }
  2163.             if($fossil_old['literature'] != $fossil['literature']) {
  2164.                 if(!is_null($fossil['literature'])){
  2165.                     $repository $this->getDoctrine()->getRepository(Literature::class);
  2166.                     $literature $repository->findOneBy(array('id' => json_decode($fossil['literature'])[0]->id));
  2167.                 } else {
  2168.                     $literature null;
  2169.                 }
  2170.             } else {
  2171.                 if(!is_null($fossil_old['literature'])){
  2172.                     $repository $this->getDoctrine()->getRepository(Literature::class);
  2173.                     $literature $repository->findOneBy(array('id' => json_decode($fossil_old['literature'])[0]->id));
  2174.                 } else {
  2175.                     $literature null;
  2176.                 }
  2177.             }
  2178.             if($fossil_old['date_year'] != $fossil['date_year']) {
  2179.                 $date_year=$fossil['date_year'];
  2180.             } else {
  2181.                 $date_year=$fossil_old['date_year'];
  2182.             }
  2183.             if($fossil_old['date_month'] != $fossil['date_month']) {
  2184.                 $date_month=$fossil['date_month'];
  2185.             } else {
  2186.                 $date_month=$fossil_old['date_month'];
  2187.             }
  2188.             if($fossil_old['date_day'] != $fossil['date_day']) {
  2189.                 $date_day=$fossil['date_day'];
  2190.             } else {
  2191.                 $date_day=$fossil_old['date_day'];
  2192.             }
  2193.             if($fossil_old['comment_nl'] != $fossil['comment_nl']) {
  2194.                 $comment_nl=$fossil['comment_nl'];
  2195.             } else {
  2196.                 $comment_nl=$fossil_old['comment_nl'];
  2197.             }
  2198.             if($fossil_old['comment_en'] != $fossil['comment_en']) {
  2199.                 $comment_en=$fossil['comment_en'];
  2200.             } else {
  2201.                 $comment_en=$fossil_old['comment_en'];
  2202.             }
  2203.             if($fossil_old['user_number'] != $fossil['user_number']) {
  2204.                 $user_number=$fossil['user_number'];
  2205.             } else {
  2206.                 $user_number=$fossil_old['user_number'];
  2207.             }
  2208.             $repository $this->getDoctrine()->getRepository(FossildbFossil::class);
  2209.             $fossildbFossil $repository->findOneBy(array('id' => $item->getId()));
  2210.             if($fossil_old['genus'] != $fossil['genus']) {
  2211.                 if(!is_null($fossil['genus'])) {
  2212.                     $fossildbFossil->setGenus(json_decode($fossil['genus'])[0]->value);
  2213.                 } else {
  2214.                     $fossildbFossil->setGenus(null);
  2215.                 }
  2216.             } else {
  2217.                 if(!is_null($fossil_old['genus'])) {
  2218.                     $fossildbFossil->setGenus(json_decode($fossil_old['genus'])[0]->value);
  2219.                 } else {
  2220.                     $fossildbFossil->setGenus(null);
  2221.                 }
  2222.             }
  2223.             if($fossil_old['species'] != $fossil['species']) {
  2224.                 if(!is_null($fossil['species'])) {
  2225.                     $fossildbFossil->setSpecies(json_decode($fossil['species'])[0]->value);
  2226.                 } else {
  2227.                     $fossildbFossil->setSpecies(null);
  2228.                 }
  2229.             } else {
  2230.                 if(!is_null($fossil_old['species'])) {
  2231.                     $fossildbFossil->setSpecies(json_decode($fossil_old['species'])[0]->value);
  2232.                 } else {
  2233.                     $fossildbFossil->setSpecies(null);
  2234.                 }
  2235.             }
  2236.             if($fossil_old['publication'] != $fossil['publication']) {
  2237.                 if(!is_null($fossil['publication'])) {
  2238.                     $fossildbFossil->setPublication(json_decode($fossil['publication'])[0]->value);
  2239.                 } else {
  2240.                     $fossildbFossil->setPublication(null);
  2241.                 }
  2242.             } else {
  2243.                 if(!is_null($fossil_old['publication'])) {
  2244.                     $fossildbFossil->setPublication(json_decode($fossil_old['publication'])[0]->value);
  2245.                 } else {
  2246.                     $fossildbFossil->setPublication(null);
  2247.                 }
  2248.             }
  2249.             $fossildbFossil->setLocationFossil($location_fossil);
  2250.             $fossildbFossil->setTaxanomy($taxanomy);
  2251.             $fossildbFossil->setEra($era);
  2252.             $fossildbFossil->setEpoch($epoch);
  2253.             $fossildbFossil->setStage($stage);
  2254.             $fossildbFossil->setFormation($formation);
  2255.             $fossildbFossil->setMember($member);
  2256.             $fossildbFossil->setDateYear($date_year);
  2257.             $fossildbFossil->setDateMonth($date_month);
  2258.             $fossildbFossil->setDateDay($date_day);
  2259.             $fossildbFossil->setCommentNl($comment_nl);
  2260.             $fossildbFossil->setCommentEn($comment_en);
  2261.             $fossildbFossil->setUserNumber($user_number);
  2262.             $fossildbFossil->setLiterature($literature);
  2263.             $fossil_id $item->getId();
  2264.             if(!is_null($fossil['upload'])) {
  2265.                 $upload json_decode($fossil['upload']);
  2266.                 foreach($upload as $id => $item) {
  2267.                     if(!is_null($item)) {
  2268.                         $repository $this->getDoctrine()->getRepository(FossildbFossil::class);
  2269.                         $fossildbFossil $repository->findOneBy(array('id' => $fossil_old['id']));
  2270.                         $repository $this->getDoctrine()->getRepository(UploadQueue::class);
  2271.                         $queuefile $repository->findOneBy(array('system' => 'fossildb','filename' => $item->name));
  2272.                         if(!is_null($queuefile)) {
  2273.                             $fossildbPhoto = new FossildbPhotos;
  2274.                             $fossildbPhoto->setFossildbFossil($fossildbFossil);
  2275.                             $fossildbPhoto->setType('fossil');
  2276.                             $fossildbPhoto->setFilename($item->name);
  2277.                             $fossildbPhoto->setAdded(new \DateTime());
  2278.                             $fossildbPhoto->setUserId($this->getUser()->getId());
  2279.                             $fossildbPhoto->setUsername($this->getUser()->getUsername());
  2280.                             $fossildbPhoto->setApproved(0);
  2281.     
  2282.                             $fp $em->createQueryBuilder('fp')
  2283.                                 ->from('App\Entity\FossildbPhotos''fp')
  2284.                                 ->addSelect('count(fp.id)')
  2285.                                 ->andWhere("fp.is_primary = 1")
  2286.                                 ->andWhere("fp.FossildbFossil = (:id)")
  2287.                                 ->setParameter('id'$item->id)
  2288.                                 ->getQuery()
  2289.                                 ->getSingleScalarResult();
  2290.                             ;
  2291.                             if($fp == 0) {
  2292.                                 $fossildbPhoto->setIsPrimary(1);
  2293.                             } else {
  2294.                                 $fossildbPhoto->setIsPrimary(0);
  2295.                             }
  2296.                             $em->persist($fossildbPhoto);
  2297.                             $em->remove($queuefile);
  2298.                             $fossildbFossil->setNumNewPhotos($fossildbFossil->getNumNewPhotos()+1);
  2299.                             $em->persist($fossildbFossil);
  2300.                             $em->persist($item);
  2301.                             $em->flush();
  2302.                         }
  2303.                     }
  2304.                 }
  2305.             }
  2306.             $em->persist($fossildbFossil);
  2307.             $em->flush();            
  2308.             $repository $this->getDoctrine()->getRepository(FossildbFossilEdits::class);
  2309.             $editedfossil $repository->findOneBy(array('fossil' => $item->getId()));
  2310.             $em->remove($editedfossil);
  2311.             $em->flush();
  2312.             $this->addFlash('success'$translator->trans("Fossiel bijgewerkt. De wijzigingen zijn moeten nog goed gekeurd worden."));
  2313.             return $this->redirectToRoute('fossildb_moderate');
  2314.         }
  2315.         return $this->render('fossildb_edit.html.twig', [
  2316.             'filter' => $filter,
  2317.             'formname' => 'fossildb_fossil_edit_form',
  2318.             'edit' => true,
  2319.             'approve_or_deny' => true,
  2320.             'item' => $fossil,
  2321.             'title' => $translator->trans("Fossiel bewerkingen"),
  2322.             'button_text' => $translator->trans("Bewerken"),
  2323.             'form' => $form->createView()
  2324.         ]);
  2325.     }
  2326.     /**
  2327.      * @Route("/moderate/fossildb/{item}/edits/deny", name="fossildb_moderate_deny_edits")
  2328.      */
  2329.     public function fossildb_moderate_deny_edits(FossildbFossil $itemEntityManagerInterface $em)
  2330.     {
  2331.         $this->denyAccessUnlessGranted('ROLE_MOD_FOSSILDB');
  2332.         $repository $this->getDoctrine()->getRepository(FossildbFossilEdits::class);
  2333.         $editedfossil $repository->findOneBy(array('fossil' => $item->getId()));
  2334.         $em->remove($editedfossil);
  2335.         $em->flush();
  2336.         
  2337.         return $this->redirectToRoute('fossildb_moderate');
  2338.     }
  2339.     /**
  2340.      * @Route("/moderate/fossildb/{item}/approve", name="fossildb_moderate_approve")
  2341.      */
  2342.     public function fossildb_moderate_approve(FossildbFossil $itemEntityManagerInterface $emTranslatorInterface $translator)
  2343.     {
  2344.         $this->denyAccessUnlessGranted('ROLE_MOD_FOSSILDB');
  2345.         $item->setApprovedUserId($this->getUser()->getId());
  2346.         $item->setApprovedUsername($this->getUser()->getUsername());
  2347.         $item->setApproved('1');
  2348.         $em->persist($item);
  2349.         $newsfeed = new Newsfeed();
  2350.         $newsfeed->setTitleNl($item->getGenus()." ".$item->getSpecies());
  2351.         $newsfeed->setTitleEn($item->getGenus()." ".$item->getSpecies());
  2352.         $newsfeed->setRemoteId($item->getId());
  2353.         $newsfeed->setIsUpdate(0);
  2354.         $newsfeed->setType('fossildb');
  2355.         $newsfeed->setTime(new \DateTime());
  2356.         $em $this->getDoctrine()->getManager();
  2357.         $em->persist($newsfeed);
  2358.         $em->flush();
  2359.         $repository $em->getRepository(SearchItems::class);
  2360.         $searchitem $repository->findOneBy(array('path' => $this->router->generate('fossildb_item', [ 'id' => $item->getId() ]) ));
  2361.         if(!$searchitem) {
  2362.             $searchitem = new SearchItems();
  2363.         }
  2364.         $searchitem->setType('fossildb');
  2365.         $searchitem->setPath($this->router->generate('fossildb_item', [ 'id' => $item->getId() ]));
  2366.         $name_nl_add '';
  2367.         $name_en_add '';
  2368.         $keywords_nl_add '';
  2369.         $keywords_en_add '';
  2370.         if($item->getTaxanomy()) {
  2371.             $name_nl_add $item->getTaxanomy()->getNameNl().' -> ';
  2372.             $name_en_add $item->getTaxanomy()->getNameEn().' -> ';
  2373.             $keywords_nl_add $item->getTaxanomy()->getNameScientific().','.$item->getTaxanomy()->getNameNl().',';
  2374.             $keywords_en_add $item->getTaxanomy()->getNameScientific().','.$item->getTaxanomy()->getNameEn().',';
  2375.         }
  2376.         if(empty($item->getGenus()) && empty($item->getSpecies())){
  2377.             
  2378.             $name_nl_add .= '[Ongedetermineerd]';
  2379.             $name_en_add .= '[Unidentified]';
  2380.         }
  2381.         $searchitem->setNameNl($name_nl_add.$item->getGenus().' '.$item->getSpecies());
  2382.         $searchitem->setNameEn($name_en_add.$item->getGenus().' '.$item->getSpecies());
  2383.         $searchitem->setKeywordsNl($keywords_nl_add.$item->getGenus().','.$item->getSpecies());
  2384.         $searchitem->setKeywordsEn($keywords_en_add.$item->getGenus().','.$item->getSpecies());
  2385.         if(empty($item->getEdited())) {
  2386.             $searchitem->setLastUpdateTime($item->getAdded());
  2387.         } else {
  2388.             $searchitem->setLastUpdateTime($item->getEdited());
  2389.         }
  2390.         $em->persist($searchitem);
  2391.         $em->flush();
  2392.         
  2393.         $repository $em->getRepository(FossildbFossil::class);
  2394.         $totalsubmissions $repository->createQueryBuilder('a')
  2395.             ->select('count(a.id)')
  2396.             ->andWhere("a.user_id = (:user)")
  2397.             ->andWhere("a.approved = 1")
  2398.             ->setParameter('user'$item->getUserId())
  2399.             ->getQuery()
  2400.             ->getSingleScalarResult();
  2401.         $repository $em->getRepository(User::class);
  2402.         $user $repository->findOneBy(array('id' => $item->getUserId()));
  2403.         $repository $this->getDoctrine()->getRepository(UserProfile::class);
  2404.         $userprofile $repository->findOneBy(array('user' => $user));
  2405.         if(!$userprofile) {
  2406.             $userprofile = new UserProfile();
  2407.             $userprofile->setUser($user);
  2408.         }
  2409.         $userprofile->setFossildbSubmissions($totalsubmissions);
  2410.         $em->persist($userprofile);
  2411.         $em->flush();
  2412.         $this->addFlash('success'$translator->trans("Fossiel goedgekeurd."));
  2413.         return $this->redirectToRoute('fossildb_moderate');
  2414.     }
  2415.     /**
  2416.      * @Route("/moderate/fossildb/{item}/delete", name="fossildb_moderate_delete")
  2417.      */
  2418.     public function moderate_delete(FossildbFossil $itemEntityManagerInterface $emTranslatorInterface $translator)
  2419.     {
  2420.         $this->denyAccessUnlessGranted('ROLE_MOD_FOSSILDB');
  2421.         $repository $em->getRepository(SearchItems::class);
  2422.         $searchitem $repository->findOneBy(array('path' => $this->router->generate('fossildb_item', [ 'id' => $item->getId() ]) ));
  2423.         if($searchitem){
  2424.             $em->remove($searchitem);
  2425.         }
  2426.         $em->remove($item);
  2427.         $em->flush();
  2428.         $repository $em->getRepository(FossildbFossil::class);
  2429.         $totalsubmissions $repository->createQueryBuilder('a')
  2430.             ->select('count(a.id)')
  2431.             ->andWhere("a.user_id = (:user)")
  2432.             ->andWhere("a.approved = 1")
  2433.             ->setParameter('user'$item->getUserId())
  2434.             ->getQuery()
  2435.             ->getSingleScalarResult();
  2436.         $repository $em->getRepository(User::class);
  2437.         $user $repository->findOneBy(array('id' => $item->getUserId()));
  2438.         $repository $this->getDoctrine()->getRepository(UserProfile::class);
  2439.         $userprofile $repository->findOneBy(array('user' => $user));
  2440.         if(!$userprofile) {
  2441.             $userprofile = new UserProfile();
  2442.             $userprofile->setUser($user);
  2443.         }
  2444.         $userprofile->setFossildbSubmissions($totalsubmissions);
  2445.         $em->persist($userprofile);
  2446.         $em->flush();
  2447.         $this->addFlash('success'$translator->trans("Fossiel verwijderd uit Fossielendatabase"));
  2448.         return $this->redirectToRoute('fossildb_moderate');
  2449.     }
  2450.     /**
  2451.      * @Route("/api/v1/fossildb/getgenus", methods="GET", name="api_fossildb_genus")
  2452.      */
  2453.     public function getGenusApi(FossildbFossilRepository $fossildbFossilRepositoryRequest $request)
  2454.     {
  2455.         $fossildbGenus $fossildbFossilRepository->findAllGenusMatching($request->query->get('query'));
  2456.         return $this->json($fossildbGenus200, [], ['groups' => ['main']]);
  2457.     }
  2458.     /**
  2459.      * @Route("/api/v1/fossildb/getspecies", methods="GET", name="api_fossildb_species")
  2460.      */
  2461.     public function getSpeciesApi(FossildbFossilRepository $fossildbFossilRepositoryRequest $request)
  2462.     {
  2463.         $fossildbSpecies $fossildbFossilRepository->findAllSpeciesMatching($request->query->get('query'));
  2464.         return $this->json($fossildbSpecies200, [], ['groups' => ['main']]);
  2465.     }
  2466.     /**
  2467.      * @Route("/api/v1/fossildb/getpublication", methods="GET", name="api_fossildb_publication")
  2468.      */
  2469.     public function getPublicationApi(FossildbFossilRepository $fossildbFossilRepositoryRequest $request)
  2470.     {
  2471.         $fossildbPublications $fossildbFossilRepository->findAllPublicationsMatching($request->query->get('query'));
  2472.         return $this->json($fossildbPublications200, [], ['groups' => ['main']]);
  2473.     }
  2474.     /**
  2475.      * @Route("/api/v1/fossildb/gettaxanomy", methods="GET", name="api_fossildb_taxaonmy")
  2476.      */
  2477.     public function getTaxanomyApi(TaxanomyRepository $taxanomyRepositoryRequest $requestTranslatorInterface $translator)
  2478.     {
  2479.         $taxanomy $taxanomyRepository->findAllMatching($request->query->get('query'));
  2480.         $return = array();
  2481.         foreach($taxanomy as $item) {
  2482.             if($translator->getLocale() == 'nl') {
  2483.                 $name $item->getNameNl();
  2484.             } else {
  2485.                 $name $item->getNameEn();
  2486.             }
  2487.             if($item->getNameScientificClarification() != '' || !is_null($item->getNameScientificClarification())) {
  2488.                 $scientific $item->getNameScientific() . " " $item->getNameScientificClarification();
  2489.                 $filename strtolower($item->getNameScientific()) . strtolower($item->getNameScientificClarification());
  2490.             } else {
  2491.                 $scientific $item->getNameScientific();
  2492.                 $filename strtolower($item->getNameScientific());
  2493.             }
  2494.             $return[] = array(
  2495.                 'id' => $item->getId(),
  2496.                 'value' => $name." (".$scientific.")",
  2497.                 'filename' => $filename,
  2498.             );
  2499.         }
  2500.         return $this->json($return200, [], ['groups' => ['main']]);
  2501.     }
  2502.     #ToDo-Ante: Probably a duplicate
  2503.     /**
  2504.      * @Route("/api/v1/fossildb/getlocation", methods="GET", name="api_fossildb_location")
  2505.      */
  2506.     public function getLocation(LocationsFossilRepository $LocationsFossilRepositoryRequest $request)
  2507.     {
  2508.         $user $this->getUser();
  2509.         $location $LocationsFossilRepository->findAllMatching($request->query->get('query'),25,$user);
  2510.         return $this->json($location200, [], ['groups' => ['main']]);
  2511.     }
  2512.     /**
  2513.      * @Route("/api/v1/fossildb/getstratigraphyunits/{type}", methods="GET", name="api_fossildb_stratigraphyunits")
  2514.      */
  2515.     public function getStratigraphyUnitsApi(string $typeStratigraphyUnitsRepository $stratigraphyUnitsRepositoryRequest $requestTranslatorInterface $translator)
  2516.     {
  2517.         if($request->query->get('age_start') && $request->query->get('age_end')) {
  2518.             $stratigraphyUnits $stratigraphyUnitsRepository->findAllMatching($type$request->query->get('query'), 5$request->query->get('age_start'), $request->query->get('age_end'));
  2519.         } else {
  2520.             $stratigraphyUnits $stratigraphyUnitsRepository->findAllMatching($type$request->query->get('query'));
  2521.         }
  2522.         
  2523.         $return = array();
  2524.         foreach($stratigraphyUnits as $item) {
  2525.             if($translator->getLocale() == 'nl') {
  2526.                 $name $item->getNameNl();
  2527.             } else {
  2528.                 $name $item->getNameEn();
  2529.             }
  2530.             $return[] = array(
  2531.                 'id' => $item->getId(),
  2532.                 'age_start' => $item->getAgeStart(),
  2533.                 'age_end' => $item->getAgeEnd(),
  2534.                 'value' => $name,
  2535.                 'name_en' => $item->getNameEn(),
  2536.                 'color' => $item->getColor(),
  2537.             );
  2538.         }
  2539.         return $this->json($return200, [], ['groups' => ['main']]);
  2540.     }
  2541.     // /**
  2542.     //  * @Route("/api/v1/fossildb/getgenus/{genus}", methods="GET", name="api_fossildb_genus")
  2543.     //  */
  2544.     // public function getGenusApi(string $genus, Request $request)
  2545.     // {
  2546.     //     $query = $em->createQuery('SELECT DISTINCT f.genus FROM App\Entity\FossildbFossil f WHERE f.genus = (:genus)');
  2547.     //     $query->setParameter('genus', $genus);
  2548.         
  2549.     //     if($request->query->get('age_start') && $request->query->get('age_end')) {
  2550.     //         $stratigraphyUnits = $stratigraphyUnitsRepository->findAllMatching($type, $request->query->get('query'), 5, $request->query->get('age_start'), $request->query->get('age_end'));
  2551.     //     } else {
  2552.     //         $stratigraphyUnits = $stratigraphyUnitsRepository->findAllMatching($type, $request->query->get('query'));
  2553.     //     }
  2554.         
  2555.     //     return $this->json($stratigraphyUnits, 200, [], ['groups' => ['main']]);
  2556.     // }
  2557.     /**
  2558.      * @Route("/api/v1/fossildb/add", methods="POST", name="api_fossildb_add")
  2559.      */
  2560.     public function api_fossildb_add(Request $requestStratigraphyUnitsRepository $stratigraphyUnitsRepositoryEntityManagerInterface $em)
  2561.     {
  2562.         $this->denyAccessUnlessGranted('ROLE_USER');
  2563.         /* Sample Data
  2564. {
  2565.     "location":137, (int, required)
  2566.     "taxanomy":14, (int, required)
  2567.     "literature":220, (int)
  2568.     "era":1005, (int, required)
  2569.     "epoch":1025, (int)
  2570.     "stage":1089, (int)
  2571.     "formation":1236, (int or string eg. "Slite")
  2572.     "member":1619, (int or string eg. "Lanaye")
  2573.     "genus":"Cosmopolitodus", (string)
  2574.     "species":"hastalis", (string)
  2575.     "author":"Agassiz", (string)
  2576.     "author_year":1843, (int)
  2577.     "found_day":31, (int)
  2578.     "found_month":12, (int)
  2579.     "found_year":1999, (int)
  2580.     "comment_nl":"vrij tekst veld", (string)
  2581.     "comment_en":"free text field", (string)
  2582.     "user_number":"123AB" (string)
  2583.     returns: { error: 0|1, message: <id>|<reason> }
  2584. }
  2585.         */
  2586.         if($request->getContent() != "" && is_array($data json_decode($request->getContent(), true))) {
  2587.             $error 0;
  2588.             $message "";
  2589.             // Check required fields
  2590.             if(!array_key_exists('location',$data)||$data['location']=="") { $error 1;$message=$message."Location is required. "; }
  2591.             elseif(!is_integer($data['location'])) { $error 1;$message=$message."Location data is not a number. "; }
  2592.             else{
  2593.                 $repository $this->getDoctrine()->getRepository(LocationsFossil::class);
  2594.                 $data['location'] = $repository->findOneBy(array('id' => $data['location']));
  2595.             }
  2596.             if(!array_key_exists('taxanomy',$data)||$data['taxanomy']=="") { $error 1;$message=$message."Taxanomy is required. "; }
  2597.             elseif(!is_integer($data['taxanomy'])) { $error 1;$message=$message."Taxanomy data is not a number. "; }
  2598.             else{
  2599.                 $repository $this->getDoctrine()->getRepository(Taxanomy::class);
  2600.                 $data['taxanomy'] = $repository->findOneBy(array('id' => $data['taxanomy']));
  2601.             }
  2602.             if(!array_key_exists('era',$data)||$data['era']=="") { $error 1;$message=$message."Era is required. "; }
  2603.             elseif(!is_integer($data['era'])) { $error 1;$message=$message."Era data is not a number. "; }
  2604.             else{
  2605.                 $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  2606.                 $data['era'] = $repository->findOneBy(array('id' => $data['era']));
  2607.             }
  2608.             // Check for missing, empty or incorrect fields
  2609.             if(!array_key_exists('literature',$data)) { $data['literature'] = null; }
  2610.             elseif(!is_integer($data['literature'])) { $error 1;$message=$message."Literature data is not a number. "; }
  2611.             else{
  2612.                 $repository $this->getDoctrine()->getRepository(Literature::class);
  2613.                 $data['literature'] = $repository->findOneBy(array('id' => $data['literature']));
  2614.             }
  2615.             if(!array_key_exists('epoch',$data)) { $data['epoch'] = null; }
  2616.             elseif(!is_integer($data['epoch'])) { $error 1;$message=$message."Epoch data is not a number. "; }
  2617.             else{
  2618.                 $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  2619.                 $data['epoch'] = $repository->findOneBy(array('id' => $data['epoch']));
  2620.             }
  2621.             if(!array_key_exists('stage',$data)) { $data['stage'] = null; }
  2622.             elseif(!is_integer($data['stage'])) { $error 1;$message=$message."Stage data is not a number. "; }
  2623.             else{
  2624.                 $repository $this->getDoctrine()->getRepository(StratigraphyUnits::class);
  2625.                 $data['stage'] = $repository->findOneBy(array('id' => $data['stage']));
  2626.             }
  2627.             $data['formation_new']=0;
  2628.             if(!array_key_exists('formation',$data) || is_null($data['formation'])) { $data['formation'] = null; }
  2629.             elseif(!is_integer($data['formation'])) {
  2630.                 $formation $stratigraphyUnitsRepository->findAllMatching('formation'$data['formation']);
  2631.                 if(count($formation)>0){$data['formation'] = $formation[0];}
  2632.                 else{$data['formation_new']=1;}
  2633.             }
  2634.             $data['member_new']=0;
  2635.             if(!array_key_exists('member',$data) || is_null($data['member'])) { $data['member'] = null; }
  2636.             elseif(!is_integer($data['member'])) {
  2637.                 $member $stratigraphyUnitsRepository->findAllMatching('member'$data['member']);
  2638.                 if(count($member)>0){$data['member'] = $member[0];}
  2639.                 else{$data['member_new']=1;}
  2640.             }
  2641.             if(!array_key_exists('genus',$data)) { $data['genus'] = ""; }
  2642.             if(!array_key_exists('species',$data)) { $data['species'] = ""; }
  2643.             if(!array_key_exists('publication',$data)) { $data['publication'] = ""; }
  2644.             if(!array_key_exists('found_day',$data)) { $data['found_day'] = ""; }
  2645.             elseif(!is_integer($data['found_day'])) {$error 1;$message=$message."found_day data is not a number. "; }
  2646.             elseif(!preg_match('/^\d{1,2}$/',$data['found_day'])) {$error 1;$message=$message."found_day data not a day. "; }
  2647.             if(!array_key_exists('found_month',$data)) { $data['found_month'] = ""; }
  2648.             elseif(!is_integer($data['found_month'])) {$error 1;$message=$message."found_month data is not a number. "; }
  2649.             elseif(!preg_match('/^\d{1,2}$/',$data['found_month'])) {$error 1;$message=$message."found_month data not a month. "; }
  2650.             if(!array_key_exists('found_year',$data)) { $data['found_year'] = ""; }
  2651.             elseif(!is_integer($data['found_year'])) {$error 1;$message=$message."found_year data is not a number. "; }
  2652.             elseif(!preg_match('/^\d{4}$/',$data['found_year'])) {$error 1;$message=$message."found_year data not a year. "; }
  2653.             if(!array_key_exists('comment_nl',$data)) { $data['comment_nl'] = ""; }
  2654.             if(!array_key_exists('comment_en',$data)) { $data['comment_en'] = ""; }
  2655.             if(!array_key_exists('user_number',$data)) { $data['user_number'] = ""; }
  2656.             if($error == 0){
  2657.                 $fossildbFossil = new FossildbFossil;
  2658.                 $fossildbFossil->setLocationFossil($data['location']);
  2659.                 $fossildbFossil->setTaxanomy($data['taxanomy']);
  2660.                 $fossildbFossil->setLiterature($data['literature']);
  2661.                 $fossildbFossil->setEra($data['era']);
  2662.                 $fossildbFossil->setEpoch($data['epoch']);
  2663.                 $fossildbFossil->setStage($data['stage']);
  2664.                 if($data['formation_new'] == 1){
  2665.                     $new_formation_item = new StratigraphyUnits;
  2666.                     $new_formation_item->setType("formation");
  2667.                     $new_formation_item->setNameNl($data['formation']);
  2668.                     $new_formation_item->setNameEn($data['formation']);
  2669.                     $em->persist($new_formation_item);
  2670.                     $em->flush();
  2671.                     $data['formation'] = $new_formation_item->getId();
  2672.                 }
  2673.                 $fossildbFossil->setFormation($data['formation']);
  2674.                 if($data['member_new'] == 1){
  2675.                     $new_member_item = new StratigraphyUnits;
  2676.                     $new_member_item->setType("member");
  2677.                     $new_member_item->setNameNl($data['member']);
  2678.                     $new_member_item->setNameEn($data['member']);
  2679.                     $em->persist($new_member_item);
  2680.                     $em->flush();
  2681.                     $data['member'] = $new_member_item->getId();
  2682.                 }
  2683.                 $fossildbFossil->setMember($data['member']);
  2684.                 $fossildbFossil->setGenus($data['genus']);
  2685.                 $fossildbFossil->setSpecies($data['species']);
  2686.                 $fossildbFossil->setPublication($data['publication']);
  2687.                 $fossildbFossil->setDateDay($data['found_day']);
  2688.                 $fossildbFossil->setDateMonth($data['found_month']);
  2689.                 $fossildbFossil->setDateYear($data['found_year']);
  2690.                 $fossildbFossil->setCommentNl($data['comment_nl']);
  2691.                 $fossildbFossil->setCommentEn($data['comment_en']);
  2692.                 $fossildbFossil->setUserNumber($data['user_number']);
  2693.                 $constructed_taxanomy_tree=$this->taxanomy_tree($data['taxanomy']->getId(), $em);
  2694.                 $taxanomy_tree = array();
  2695.                 foreach($constructed_taxanomy_tree as $item => $object) {
  2696.                     $taxanomy_tree[$item]['namescientific'] = $object->getNameScientific();
  2697.                     $taxanomy_tree[$item]['namescientificclarification'] = $object->getNameScientificClarification();
  2698.                     $taxanomy_tree[$item]['namenl'] = $object->getNameNl();
  2699.                     $taxanomy_tree[$item]['nameen'] = $object->getNameEn();
  2700.                     $taxanomy_tree[$item]['author'] = $object->getAuthor();
  2701.                     $taxanomy_tree[$item]['authoryear'] = $object->getAuthorYear();
  2702.                     if($object->getGlossary()){
  2703.                         $taxanomy_tree[$item]['glossary']['id'] = $object->getGlossary()->getId();
  2704.                         $taxanomy_tree[$item]['glossary']['url'] = $object->getGlossary()->getUrl();
  2705.                         $taxanomy_tree[$item]['glossary']['titlenl'] = $object->getGlossary()->getTitleNl();
  2706.                         $taxanomy_tree[$item]['glossary']['titleen'] = $object->getGlossary()->getTitleEn();
  2707.                     } else {
  2708.                         $taxanomy_tree[$item]['glossary'] = null;
  2709.                     }
  2710.                     $taxanomy_tree[$item]['taxanomyrank']['namescientific'] = $object->getTaxanomyRank()->getNameScientific();
  2711.                     $taxanomy_tree[$item]['taxanomyrank']['namenl'] = $object->getTaxanomyRank()->getNameNl();
  2712.                     $taxanomy_tree[$item]['taxanomyrank']['nameen'] = $object->getTaxanomyRank()->getNameEn();
  2713.                 }
  2714.                 $fossildbFossil->setTaxanomyTree(array_reverse($taxanomy_tree));
  2715.     
  2716.                 $fossildbFossil->setAdded(new \DateTime());
  2717.                 $fossildbFossil->setUserId($this->getUser()->getId());
  2718.                 $fossildbFossil->setUsername($this->getUser()->getUsername());
  2719.                 $fossildbFossil->setApproved(0);
  2720.                 $fossildbFossil->setNumReviews(0);
  2721.                 $fossildbFossil->setNumNewPhotos(0);
  2722.                 $fossildbFossil->setHasEdits(0);
  2723.                 $em->persist($fossildbFossil);
  2724.                 $em->flush();
  2725.                 $message $fossildbFossil->getid();
  2726.             }
  2727.             $return = array("error" => $error'message' => $message);
  2728.         } else {
  2729.             $return = array("error" => 1"message" => "No valid data was recieved");
  2730.         }
  2731.         if($return['error'] == 1) {
  2732.             $status 422;
  2733.         } else {
  2734.             $status 200;
  2735.         }
  2736.         return new JsonResponse($return$status);
  2737.     }
  2738. }