src/Controller/LocationsController.php line 916

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Symfony\Contracts\Translation\TranslatorInterface;
  9. use Symfony\Component\Routing\RouterInterface;
  10. use Symfony\Component\Filesystem\Filesystem;
  11. use Symfony\Component\Finder\Finder;
  12. use App\Entity\User;
  13. use App\Entity\Countries;
  14. use App\Entity\LocationReviews;
  15. use App\Entity\LocationsGIS;
  16. use App\Entity\LocationsGISNearby;
  17. use App\Entity\LocationsFossil;
  18. use App\Entity\LocationsGeology;
  19. use App\Entity\LocationsMuseum;
  20. use App\Entity\LocationsSociety;
  21. use App\Entity\LocationPhotos;
  22. use App\Repository\LocationsFossilRepository;
  23. use App\Form\LocationGISCoordinateFormType;
  24. use App\Form\LocationGISFilterFormType;
  25. use App\Form\LocationReviewFormType;
  26. use App\Form\LocationPhotoAddFormType;
  27. class LocationsController extends AbstractController
  28. {
  29.     public function find_nearby(LocationsGIS $itemEntityManagerInterface $em) {
  30.         $locations_nearby = array();
  31.         $query $em->createQuery('SELECT lg FROM App\Entity\LocationsGIS lg WHERE (lg.center_lat BETWEEN :latmin AND :latmax) AND (lg.center_lng BETWEEN :lngmin AND :lngmax) ORDER BY lg.type ASC');
  32.         $query->setParameter('latmin'$item->getCenterLat()-0.5);
  33.         $query->setParameter('latmax'$item->getCenterLat()+0.5);
  34.         $query->setParameter('lngmin'$item->getCenterLng()-0.5);
  35.         $query->setParameter('lngmax'$item->getCenterLng()+0.5);
  36.         foreach ($query->getResult() as $key => $location) {
  37.             if($location->getType() == $item->getType()){
  38.                 if ($location->getType() == 'fossil') {
  39.                     if ($item->getFossil()->getId() != $location->getFossil()->getId()){
  40.                         $locations_nearby[] = $location;
  41.                     }
  42.                 } elseif ($location->getType() == 'geology') {
  43.                     if ($item->getGeology()->getId() != $location->getGeology()->getId()){
  44.                         $locations_nearby[] = $location;
  45.                     }
  46.                 } elseif ($location->getType() == 'museum') {
  47.                     if ($item->getMuseum()->getId() != $location->getMuseum()->getId()){
  48.                         $locations_nearby[] = $location;
  49.                     }
  50.                 } elseif ($location->getType() == 'society') {
  51.                     if ($item->getSociety()->getId() != $location->getSociety()->getId()){
  52.                         $locations_nearby[] = $location;
  53.                     }
  54.                 }
  55.             } else {
  56.                 $locations_nearby[] = $location;
  57.             }
  58.         }
  59.         $repository $this->getDoctrine()->getRepository(LocationsGISNearby::class);
  60.         $fossil_allready=array(); $fossil_allready_reverse=array();
  61.         $geology_allready=array(); $geology_allready_reverse=array();
  62.         $museum_allready=array(); $museum_allready_reverse=array();
  63.         $society_allready=array(); $society_allready_reverse=array();
  64.         foreach ($locations_nearby as $key => $location) {
  65.             //forward
  66.             $is_location_present $repository->findOneBy(array('gis' => $item->getId(), 'nearby_gis' => $location->getId()));
  67.             if(!$is_location_present) {
  68.                 if($location->getType() == 'fossil') {
  69.                     $remote_gis_locations $repository->findBy(array('gis' => $item->getId(), 'type' => 'fossil'));
  70.                     if (count($remote_gis_locations) > 0) {
  71.                         foreach ($remote_gis_locations as $key => $remote_gis_location) {
  72.                             $fossil_allready[] = $remote_gis_location->getNearbyGis()->getFossil()->getId();
  73.                         }
  74.                         foreach ($remote_gis_locations as $key => $remote_gis_location) {
  75.                             if(!in_array($location->getFossil()->getId(), $fossil_allready)){
  76.                                 $this->add_nearby($item$location$em);
  77.                                 $this->add_nearby($location$item$em);
  78.                                 $fossil_allready[] = $location->getFossil()->getId();
  79.                             } else {
  80.                                 $fossil_allready[] = $location->getFossil()->getId();
  81.                             }
  82.                         }
  83.                     } else {
  84.                         $this->add_nearby($item$location$em);
  85.                         $this->add_nearby($location$item$em);
  86.                     }
  87.                 } elseif($location->getType() == 'geology') {
  88.                     $remote_gis_locations $repository->findBy(array('gis' => $item->getId(), 'type' => 'geology'));
  89.                     if (count($remote_gis_locations) > 0) {
  90.                         foreach ($remote_gis_locations as $key => $remote_gis_location) {
  91.                             $geology_allready[] = $remote_gis_location->getNearbyGis()->getGeology()->getId();
  92.                         }
  93.                         foreach ($remote_gis_locations as $key => $remote_gis_location) {
  94.                             if(!in_array($location->getGeology()->getId(), $geology_allready)){
  95.                                 $this->add_nearby($item$location$em);
  96.                                 $this->add_nearby($location$item$em);
  97.                                 $geology_allready[] = $location->getGeology()->getId();
  98.                             } else {
  99.                                 $geology_allready[] = $location->getGeology()->getId();
  100.                             }
  101.                         }
  102.                     } else {
  103.                         $this->add_nearby($item$location$em);
  104.                         $this->add_nearby($location$item$em);
  105.                     }
  106.                 } elseif($location->getType() == 'museum') {
  107.                     $remote_gis_locations $repository->findBy(array('gis' => $item->getId(), 'type' => 'museum'));
  108.                     if (count($remote_gis_locations) > 0) {
  109.                         foreach ($remote_gis_locations as $key => $remote_gis_location) {
  110.                             $museum_allready[] = $remote_gis_location->getNearbyGis()->getMuseum()->getId();
  111.                         }
  112.                         foreach ($remote_gis_locations as $key => $remote_gis_location) {
  113.                             if(!in_array($location->getMuseum()->getId(), $museum_allready)){
  114.                                 $this->add_nearby($item$location$em);
  115.                                 $this->add_nearby($location$item$em);
  116.                                 $museum_allready[] = $location->getMuseum()->getId();
  117.                             } else {
  118.                                 $museum_allready[] = $location->getMuseum()->getId();
  119.                             }
  120.                         }
  121.                     } else {
  122.                         $this->add_nearby($item$location$em);
  123.                         $this->add_nearby($location$item$em);
  124.                     }
  125.                 } elseif($location->getType() == 'society') {
  126.                     $remote_gis_locations $repository->findBy(array('gis' => $item->getId(), 'type' => 'society'));
  127.                     if (count($remote_gis_locations) > 0) {
  128.                         foreach ($remote_gis_locations as $key => $remote_gis_location) {
  129.                             $society_allready[] = $remote_gis_location->getNearbyGis()->getSociety()->getId();
  130.                         }
  131.                         foreach ($remote_gis_locations as $key => $remote_gis_location) {
  132.                             if(!in_array($location->getSociety()->getId(), $society_allready)){
  133.                                 $this->add_nearby($item$location$em);
  134.                                 $this->add_nearby($location$item$em);
  135.                                 $society_allready[] = $location->getSociety()->getId();
  136.                             } else {
  137.                                 $society_allready[] = $location->getSociety()->getId();
  138.                             }
  139.                         }
  140.                     } else {
  141.                         $this->add_nearby($item$location$em);
  142.                         $this->add_nearby($location$item$em);
  143.                     }
  144.                 }
  145.             }
  146.            
  147.         }
  148.         return new Response;
  149.     }
  150.     private function add_nearby($item$location$em) {
  151.         $add_location = new LocationsGISNearby();
  152.         $add_location->setGis($item);
  153.         $add_location->setNearbyGis($location);
  154.         $add_location->setType($location->getType());
  155.         $em->persist($add_location);
  156.         $em->flush();
  157.     }
  158.     public function remove_nearby(LocationsGIS $itemEntityManagerInterface $em){
  159.         $repository $this->getDoctrine()->getRepository(LocationsGISNearby::class);
  160.         $gis_nearby $repository->findBy(array('gis' => $item->getId()));
  161.         foreach ($gis_nearby as $key => $gis) {
  162.             $em->remove($gis);
  163.             $em->flush();
  164.         }
  165.         $gis_nearby $repository->findBy(array('nearby_gis' => $item->getId()));
  166.         foreach ($gis_nearby as $key => $gis) {
  167.             $em->remove($gis);
  168.             $em->flush();
  169.         }
  170.     }
  171.     public function find_new_nearby($item_id$typeEntityManagerInterface $emTranslatorInterface $translator){    
  172.         $gis_repository $this->getDoctrine()->getRepository(LocationsGIS::class);
  173.         $gis_locations $gis_repository->findBy(array($type => $item_id'type' => $type'approved' => '1'));
  174.         $foundGISNearby null;
  175.         $repository $this->getDoctrine()->getRepository(LocationsGISNearby::class);
  176.         foreach ($gis_locations as $key => $gis_location) {
  177.             $gis_locations_used $repository->findOneBy(array('gis' => $gis_location->getId()));
  178.             if($gis_locations_used) {
  179.                 $foundGISNearby $gis_locations_used;
  180.             }
  181.         }
  182.         if(!$foundGISNearby) {
  183.             $gis_location $gis_repository->findOneBy(array($type => $item_id'type' => $type'approved' => '1'));
  184.             if($gis_location) {
  185.                 $this->find_nearby($gis_location$em);
  186.             } else {
  187.                 if ($type == 'fossil') {
  188.                     $repository $this->getDoctrine()->getRepository(LocationsFossil::class);
  189.                 } elseif ($type == 'geology') {
  190.                     $repository $this->getDoctrine()->getRepository(LocationsGeology::class);
  191.                 } elseif ($type == 'museum') {
  192.                     $repository $this->getDoctrine()->getRepository(LocationsMuseum::class);
  193.                 } elseif ($type == 'society') {
  194.                     $repository $this->getDoctrine()->getRepository(LocationsSociety::class);
  195.                 }
  196.                 $item $repository->findOneBy(array('id' => $item_id));
  197.                 $item->setApproved('0');
  198.                 $em->persist($item);
  199.                 $em->flush();
  200.                 $this->addFlash('error'$translator->trans("Er zijn geen goedgekeurde coördinaten meer, locatie ingetrokken"));
  201.             }
  202.         }
  203.     }
  204.     private function get_location_by_id(string $typeint $id) {
  205.         if($type == 'fossil') {
  206.             $repository $this->getDoctrine()->getRepository(LocationsFossil::class);
  207.         } elseif($type == 'geology') {
  208.             $repository $this->getDoctrine()->getRepository(LocationsGeology::class);
  209.         } elseif($type == 'museum') {
  210.             $repository $this->getDoctrine()->getRepository(LocationsMuseum::class);
  211.         } elseif($type == 'society') {
  212.             $repository $this->getDoctrine()->getRepository(LocationsSociety::class);
  213.         }
  214.         $location $repository->findOneBy(array('id'=>$id));
  215.         return $location;
  216.     }
  217.     
  218.     /**
  219.      * @Route("/locations/", name="locations_gis")
  220.      * @Route("/locations/user/{user}/{type}", name="locations_gis_user")
  221.      */
  222.     public function index(Request $requestTranslatorInterface $translatorUser $user nullString $type null)
  223.     {
  224.         $repository $this->getDoctrine()->getRepository(LocationsGIS::class);
  225.         $filters=array();
  226.         if($request->query->get('country') != null ) { $filterby['country'] = $request->query->get('country'); }
  227.         if($request->query->get('type') != null ) { $filterby['type'] = $request->query->get('type'); }
  228.         if ($routeName $request->get('_route') == 'locations_gis_user') {
  229.             if($type != null) { $filterby['type'] = $type; }
  230.         }
  231.         if($this->getUser() == null){
  232.             $filterby['vulnerability'] = array('public');
  233.         } else {
  234.             $vulnerability $this->getUser()->getCanSeeVulnerability();
  235.             if($vulnerability == 'very') { $filterby['vulnerability'] = array('public','slightly','moderate','very'); }
  236.             elseif($vulnerability == 'moderate') { $filterby['vulnerability'] = array('public','slightly','moderate'); }
  237.             elseif($vulnerability == 'slightly') { $filterby['vulnerability'] = array('public','slightly'); }
  238.             else { $filterby['vulnerability'] = array('public'); }
  239.         }
  240.         $form $this->createForm(LocationGISFilterFormType::class, null, [
  241.             'action' => $request->getPathInfo('_route'),
  242.         ]);
  243.         $form->handleRequest($request);
  244.         if ($form->isSubmitted() && $form->isValid()){
  245.             $filters $form->getData();
  246.             if($filters->getType() != null) {
  247.                 $filterby['type'] = $filters->getType();
  248.             }
  249.             if($filters->getCountry() != null) {
  250.                 $filterby['country'] = $filters->getCountry()->getId();
  251.             }
  252.         }
  253.         $filterby['approved'] = 1;
  254.         //$gis = $repository->findBy($filterby,array('type' => 'ASC'));
  255.         if($translator->getLocale() == 'nl') {
  256.             $oder_field 'name_nl';
  257.         } else {
  258.             $oder_field 'name_en';
  259.         }
  260.         
  261.         $locations_filterby=array();
  262.         if ($routeName $request->get('_route') == 'locations_gis_user') {
  263.             if($user != null) { $locations_filterby['user_id'] = $user->getId(); }
  264.             $user_only $user->getId();
  265.             if(empty($filters)) { $filters = array('user_filter'); }
  266.         } else {
  267.             $user_only false;
  268.         }
  269.         $repository $this->getDoctrine()->getRepository(Countries::class);
  270.         
  271.         if(isset($filterby['country'])) {
  272.             $locations_filterby['country'] = $filterby['country'];
  273.             $country $repository->findOneBy(array('id' => $filterby['country']));
  274.         } else {
  275.             $country null;
  276.         }
  277.         /*if(isset($filterby['vulnerability'])) {
  278.             $locations_filterby['vulnerability'] = $filterby['vulnerability'];
  279.             if (($key = array_search('none', $locations_filterby['vulnerability'])) === true ) {
  280.                 unset($locations_filterby['vulnerability'][$key]);
  281.                 $locations_filterby['vulnerability'][] = 'public';
  282.             }
  283.         }*/
  284.         $fossil_locations=array();
  285.         if(!isset($filterby['type']) || $filterby['type'] == 'fossil') {
  286.             $repository $this->getDoctrine()->getRepository(LocationsFossil::class);
  287.             $fossil_locations $repository->findBy($locations_filterby,array('location' => 'ASC'));
  288.         }
  289.         $geology_locations=array();
  290.         if(!isset($filterby['type']) || $filterby['type'] == 'geology') {
  291.             $repository $this->getDoctrine()->getRepository(LocationsGeology::class);
  292.             $geology_locations $repository->findBy($locations_filterby,array('location' => 'ASC'));
  293.         }
  294.         unset($locations_filterby['vulnerability']);
  295.         $museum_locations=array();
  296.         if(!isset($filterby['type']) || $filterby['type'] == 'museum') {
  297.             $repository $this->getDoctrine()->getRepository(LocationsMuseum::class);
  298.             $museum_locations $repository->findBy($locations_filterby,array($oder_field => 'ASC'));
  299.         }
  300.         $society_locations=array();
  301.         if(!isset($filterby['type']) || $filterby['type'] == 'society') {
  302.             $repository $this->getDoctrine()->getRepository(LocationsSociety::class);
  303.             $society_locations $repository->findBy($locations_filterby,array($oder_field => 'ASC'));
  304.         }
  305.         if(!isset($filterby['type'])) {
  306.             $filterby_types = array('fossil','geology','museum','society');
  307.         } else {
  308.             $filterby_types = array($filterby['type']);
  309.         }
  310.         
  311.         if(!empty($filters)) { $filter_set 1; } else { $filter_set 0; }
  312.         return $this->render('locations.html.twig', [
  313.             'form' => $form->createView(),
  314.             'filterby' => $filterby,
  315.             'filter_set' => $filter_set,
  316.             'types' => $filterby_types,
  317.             'country' => $country,
  318.             'fossil_locations' => $fossil_locations,
  319.             'geology_locations' => $geology_locations,
  320.             'museum_locations' => $museum_locations,
  321.             'society_locations' => $society_locations,
  322.             'all_locations' => true,
  323.             'user_only' => $user_only,
  324.         ]);
  325.     }
  326.     /**
  327.      * @Route("/locations/geojson/protected/{type}/{vulnerability}", name="locations_gis_protected_geojson")
  328.      */
  329.     public function locations_gis_protected_geojson(string $vulnerabilitystring $typeTranslatorInterface $translator)
  330.     {
  331.         $this->denyAccessUnlessGranted('ROLE_USER');
  332.         $uservulnerability $this->getUser()->getCanSeeVulnerability();
  333.         $filterby = array();
  334.         if($uservulnerability == 'very') { $filterby['vulnerability'] = array('slightly','moderate','very'); }
  335.         elseif($uservulnerability == 'moderate') { $filterby['vulnerability'] = array('slightly','moderate'); }
  336.         elseif($uservulnerability == 'slightly') { $filterby['vulnerability'] = array('slightly'); }
  337.         else { $filterby['vulnerability'] = array('none'); }
  338.         $fileContent '{"type":"FeatureCollection","features":[]}';
  339.         if(in_array($vulnerability ,$filterby['vulnerability'])) {
  340.             $finder = new Finder();
  341.             $finder->files()->name('locations.'.$vulnerability.'.'.$type.'.'.$translator->getLocale().'.geojson')->in(__DIR__.'/../../templates/generated');
  342.             foreach ($finder as $file) {
  343.                 $fileContent $file->getContents();
  344.             }
  345.         }
  346.         $response = new Response($fileContent);
  347.         $response->headers->set('Content-Type''application/json');
  348.         return $response;
  349.     }
  350.     /**
  351.      * @Route("/locations/geojson/user/{user}/{type}/{vulnerability}", name="locations_gis_user_geojson")
  352.      */
  353.     public function locations_gis_user_geojson(User $userstring $typestring $vulnerabilityTranslatorInterface $translatorRouterInterface $router)
  354.     {
  355.         if ($this->isGranted('IS_AUTHENTICATED')) {
  356.             $uservulnerability $this->getUser()->getCanSeeVulnerability();
  357.         } else {
  358.             $uservulnerability=array('public');
  359.         }
  360.         $filterby = array();
  361.         if($uservulnerability == 'very') { $filterby['vulnerability'] = array('public','slightly','moderate','very'); }
  362.         elseif($uservulnerability == 'moderate') { $filterby['vulnerability'] = array('public','slightly','moderate'); }
  363.         elseif($uservulnerability == 'slightly') { $filterby['vulnerability'] = array('public','slightly'); }
  364.         else { $filterby['vulnerability'] = array('public'); }
  365.         $fileContent '{"type":"FeatureCollection","features":[';
  366.         $gis '';
  367.         if($type == 'fossil') {
  368.             $repository $this->getDoctrine()->getRepository(LocationsGIS::class);
  369.             $gis $repository->findBy(array('user_id' => $user'approved' => '1''vulnerability' => $filterby['vulnerability']));
  370.         }
  371.         if($type == 'geology') {
  372.             $repository $this->getDoctrine()->getRepository(LocationsGIS::class);
  373.             $gis $repository->findBy(array('user_id' => $user'approved' => '1''vulnerability' => $filterby['vulnerability']));
  374.         }
  375.         if($type == 'museum') {
  376.             $repository $this->getDoctrine()->getRepository(LocationsGIS::class);
  377.             $gis $repository->findBy(array('user_id' => $user'approved' => '1''vulnerability' => $filterby['vulnerability']));
  378.         }
  379.         if($type == 'society') {
  380.             $repository $this->getDoctrine()->getRepository(LocationsGIS::class);
  381.             $gis $repository->findBy(array('user_id' => $user'approved' => '1''vulnerability' => $filterby['vulnerability']));
  382.         }
  383.         $length count($gis);
  384.         $counter 0;
  385.         foreach($gis as $location){
  386.             $popupContent '';
  387.             if($location->getType() == 'fossil') { $popupContent .= "<b>".$location->getNameEn()."</b><br><br>".$translator->trans('Fossielenlocatie')."<br>";
  388.             if($location->GetFossil()->getClosed() == '1') { $popupContent .= "<span style='color: #FF0000;'>".$translator->trans('Gesloten')."</span><br>"; }
  389.             $popupContent .= "<a href='".$router->generate('locations_fossil', array('id'=>$location->GetFossil()->getId()))."'>".$translator->trans('Locatie bekijken')."</a>"; }
  390.             if($location->getType() == 'geology') { $popupContent .= "<b>".$location->getNameEn()."</b><br><br>".$translator->trans('Geologisch excursiepunt')."<br>";
  391.             if($location->GetGeology()->getClosed() == '1') { $popupContent .= "<span style='color: #FF0000;'>".$translator->trans('Gesloten')."</span><br>"; }
  392.             $popupContent .= "<a href='".$router->generate('locations_geology', array('id'=>$location->GetGeology()->getId()))."'>".$translator->trans('Locatie bekijken')."</a>"; }
  393.             if($location->getType() == 'museum') { $popupContent .= "<b>".$location->getNameEn()."</b><br><br>".$translator->trans('Museum')."<br>";
  394.             $popupContent .= "<a href='".$router->generate('locations_museum', array('id'=>$location->GetMuseum()->getId()))."'>".$translator->trans('Locatie bekijken')."</a>"; }
  395.             if($location->getType() == 'society') { $popupContent .= "<b>".$location->getNameEn()."</b><br><br>".$translator->trans('Vereniging')."<br>";
  396.             $popupContent .= "<a href='".$router->generate('locations_society', array('id'=>$location->GetSociety()->getId()))."'>".$translator->trans('Locatie bekijken')."</a>"; }
  397.             if ($translator->getLocale() == 'nl'){
  398.                 $name $location->getNameEn();
  399.             } else {
  400.                 $name $location->getNameNl();
  401.             }
  402.             $fileContent .= '
  403.             {
  404.               "type": "Feature",
  405.               "id": "'.$location->getId().'",
  406.               "properties": {
  407.                 "name": "'.$name.'",
  408.                 "popupContent":"'.$popupContent.'",
  409.                 "type": "'.$location->getType().'",
  410.                 "icon": "'.$location->getType().'Icon"
  411.               },
  412.               "geometry" :
  413.               {
  414.                 "type":"'.$location->getShape().'",
  415.                 "coordinates":'.str_replace('"'""$location->getData()).',
  416.                 "center": ['.$location->getCenterLng().','.$location->getCenterLat().']
  417.               }
  418.             }';
  419.             if($counter != ($length-1)) {$fileContent .= ',';}
  420.             $counter++;
  421.         }
  422.         $fileContent .= ']}';
  423.         $response = new Response($fileContent);
  424.         $response->headers->set('Content-Type''application/json');
  425.         return $response;
  426.     }
  427.     /**
  428.      * @Route("/locations/geojson/locations/{type}/{id}", name="locations_gis_geojson_locations")
  429.      */
  430.     public function locations_gis_geojson_locations(string $typeint $idTranslatorInterface $translatorRouterInterface $router)
  431.     {
  432.         if ($this->isGranted('IS_AUTHENTICATED')) {
  433.             $uservulnerability $this->getUser()->getCanSeeVulnerability();
  434.         } else {
  435.             $uservulnerability=array('public');
  436.         }
  437.         $filterby = array();
  438.         if($uservulnerability == 'very') { $filterby['vulnerability'] = array('public','slightly','moderate','very'); }
  439.         elseif($uservulnerability == 'moderate') { $filterby['vulnerability'] = array('public','slightly','moderate'); }
  440.         elseif($uservulnerability == 'slightly') { $filterby['vulnerability'] = array('public','slightly'); }
  441.         else { $filterby['vulnerability'] = array('public'); }
  442.         $fileContent '{"type":"FeatureCollection","features":[';
  443.         $gis '';
  444.         if($type == 'fossil') {
  445.             $repository $this->getDoctrine()->getRepository(LocationsGIS::class);
  446.             $gis $repository->findBy(array('fossil' => $id'approved' => '1''vulnerability' => $filterby['vulnerability']));
  447.         }
  448.         if($type == 'geology') {
  449.             $repository $this->getDoctrine()->getRepository(LocationsGIS::class);
  450.             $gis $repository->findBy(array('geology' => $id'approved' => '1''vulnerability' => $filterby['vulnerability']));
  451.         }
  452.         if($type == 'museum') {
  453.             $repository $this->getDoctrine()->getRepository(LocationsGIS::class);
  454.             $gis $repository->findBy(array('museum' => $id'approved' => '1''vulnerability' => $filterby['vulnerability']));
  455.         }
  456.         if($type == 'society') {
  457.             $repository $this->getDoctrine()->getRepository(LocationsGIS::class);
  458.             $gis $repository->findBy(array('society' => $id'approved' => '1''vulnerability' => $filterby['vulnerability']));
  459.         }
  460.         $length count($gis);
  461.         $counter 0;
  462.         foreach($gis as $location){
  463.             $popupContent '';
  464.             if($location->getType() == 'fossil') { $popupContent .= "<b>".$location->getNameEn()."</b><br><br>".$translator->trans('Fossielenlocatie')."<br>";
  465.             if($location->GetFossil()->getClosed() == '1') { $popupContent .= "<span style='color: #FF0000;'>".$translator->trans('Gesloten')."</span><br>"; }
  466.             $popupContent .= "<a href='".$router->generate('locations_fossil', array('id'=>$location->GetFossil()->getId()))."'>".$translator->trans('Locatie bekijken')."</a>"; }
  467.             if($location->getType() == 'geology') { $popupContent .= "<b>".$location->getNameEn()."</b><br><br>".$translator->trans('Geologisch excursiepunt')."<br>";
  468.             if($location->GetGeology()->getClosed() == '1') { $popupContent .= "<span style='color: #FF0000;'>".$translator->trans('Gesloten')."</span><br>"; }
  469.             $popupContent .= "<a href='".$router->generate('locations_geology', array('id'=>$location->GetGeology()->getId()))."'>".$translator->trans('Locatie bekijken')."</a>"; }
  470.             if($location->getType() == 'museum') { $popupContent .= "<b>".$location->getNameEn()."</b><br><br>".$translator->trans('Museum')."<br>";
  471.             $popupContent .= "<a href='".$router->generate('locations_museum', array('id'=>$location->GetMuseum()->getId()))."'>".$translator->trans('Locatie bekijken')."</a>"; }
  472.             if($location->getType() == 'society') { $popupContent .= "<b>".$location->getNameEn()."</b><br><br>".$translator->trans('Vereniging')."<br>";
  473.             $popupContent .= "<a href='".$router->generate('locations_society', array('id'=>$location->GetSociety()->getId()))."'>".$translator->trans('Locatie bekijken')."</a>"; }
  474.             if ($translator->getLocale() == 'nl'){
  475.                 $name $location->getNameEn();
  476.             } else {
  477.                 $name $location->getNameNl();
  478.             }
  479.             $fileContent .= '
  480.             {
  481.               "type": "Feature",
  482.               "id": "'.$location->getId().'",
  483.               "properties": {
  484.                 "name": "'.$name.'",
  485.                 "popupContent":"'.$popupContent.'",
  486.                 "type": "'.$location->getType().'",
  487.                 "icon": "'.$location->getType().'Icon"
  488.               },
  489.               "geometry" :
  490.               {
  491.                 "type":"'.$location->getShape().'",
  492.                 "coordinates":'.str_replace('"'""$location->getData()).',
  493.                 "center": ['.$location->getCenterLng().','.$location->getCenterLat().']
  494.               }
  495.             }';
  496.             if($counter != ($length-1)) {$fileContent .= ',';}
  497.             $counter++;
  498.         }
  499.         $fileContent .= ']}';
  500.         $response = new Response($fileContent);
  501.         $response->headers->set('Content-Type''application/json');
  502.         return $response;
  503.     }
  504.     /**
  505.      * @Route("/locations/geojson/moderate/location/{id}", name="locations_gis_geojson_moderate_location")
  506.      */
  507.     /*public function locations_gis_geojson_moderate_location( int $id, TranslatorInterface $translator)
  508.     {
  509.         $this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
  510.         
  511.         $uservulnerability = $this->getUser()->getCanSeeVulnerability();
  512.         $filterby = array();
  513.         if($uservulnerability == 'very') { $filterby['vulnerability'] = array('public','slightly','moderate','very'); }
  514.         elseif($uservulnerability == 'moderate') { $filterby['vulnerability'] = array('public','slightly','moderate'); }
  515.         elseif($uservulnerability == 'slightly') { $filterby['vulnerability'] = array('public','slightly'); }
  516.         else { $filterby['vulnerability'] = array('public'); }
  517.         $fileContent = '{"type":"FeatureCollection","features":[';
  518.         $repository = $this->getDoctrine()->getRepository(LocationsGIS::class);
  519.         $location = $repository->findOneBy(array('id' => $id));
  520.         
  521.         if ($translator->getLocale() == 'nl'){
  522.             $name = $location->getNameEn();
  523.         } else {
  524.             $name = $location->getNameNl();
  525.         }
  526.         $fileContent .= '
  527.         {
  528.             "type":"Feature",
  529.             "id":"'.$location->getId().'",
  530.             "properties": {
  531.             "name":"'.$name.'"
  532.             },
  533.             "geometry":
  534.             {
  535.             "type":"'.$location->getShape().'",
  536.             "coordinates":'.str_replace('"', "", $location->getData()).'
  537.             }
  538.         }';
  539.         $fileContent .= ']}';
  540.         $response = new Response($fileContent);
  541.         $response->headers->set('Content-Type', 'application/json');
  542.         return $response;
  543.     }*/
  544.     /**
  545.      * @Route("/moderate/gis/", name="locations_gis_moderate")
  546.      */
  547.     public function locations_gis()
  548.     {
  549.         $this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
  550.         $repository $this->getDoctrine()->getRepository(LocationsGIS::class);
  551.         $gis $repository->findBy(array('approved' => '0'));
  552.         return $this->render('locations_gis_moderate.html.twig', [
  553.             'gis' => $gis,
  554.         ]);
  555.     }
  556.     /**
  557.      * @Route("/locations/add", name="locations_user_add")
  558.      */
  559.     public function locations_user_add()
  560.     {
  561.         $this->denyAccessUnlessGranted('ROLE_USER');
  562.         if($_ENV['DISABLE_FORMS'] == "true") { return $this->render('maintenance_form_disabled.html.twig'); }
  563.         return $this->render('locations_user_add.html.twig');
  564.     }
  565.     /**
  566.      * @Route("/locations/photo/add/{type}/{id}", name="locations_photo_add")
  567.      */
  568.     public function locations_photo_add(string $typeint $idEntityManagerInterface $emRequest $requestTranslatorInterface $translator)
  569.     {
  570.         $this->denyAccessUnlessGranted('ROLE_USER');
  571.         if($_ENV['DISABLE_FORMS'] == "true") { return $this->render('maintenance_form_disabled.html.twig'); }
  572.         $form $this->createForm(LocationPhotoAddFormType::class);
  573.         $form->handleRequest($request);
  574.         if ($form->isSubmitted() && $form->isValid()){
  575.             $item $form->getData();
  576.             $locationImage $form->get('filename')->getData();
  577.             if($locationImage) {
  578.                 $get_valid_name $this->forward('App\Controller\FileUploadController:get_valid_name', [
  579.                     'basePath' => $this->getParameter('locationphoto_directory'),
  580.                     'name' => $locationImage->getClientOriginalName(),
  581.                     ]);
  582.                 $newFilename $get_valid_name->getContent();
  583.                 try {
  584.                     $locationImage->move(
  585.                         $this->getParameter('locationphoto_directory')."/".substr($newFilename,0,2),
  586.                         $newFilename
  587.                     );
  588.                 } catch (FileException $e) {
  589.                     //ToDo-Ante
  590.                     // ... handle exception if something happens during file upload
  591.                 }
  592.                 if($type == 'fossil') {
  593.                     $repository $this->getDoctrine()->getRepository(LocationsFossil::class);
  594.                 } elseif($type == 'geology') {
  595.                     $repository $this->getDoctrine()->getRepository(LocationsGeology::class);
  596.                 } elseif($type == 'museum') {
  597.                     $repository $this->getDoctrine()->getRepository(LocationsMuseum::class);
  598.                 } elseif($type == 'society') {
  599.                     $repository $this->getDoctrine()->getRepository(LocationsSociety::class);
  600.                 }
  601.                 $location $repository->findOneBy(array('id' => $id));
  602.                 if($type == 'fossil') {
  603.                     $item->setFossil($location);
  604.                     $num_new_photos $item->getFossil()->getNumNewPhotos();
  605.                     $item->getFossil()->setNumNewPhotos($num_new_photos+1);
  606.                 } elseif($type == 'geology') {
  607.                     $item->setGeology($location);
  608.                     $num_new_photos $item->getGeology()->getNumNewPhotos();
  609.                     $item->getGeology()->setNumNewPhotos($num_new_photos+1);
  610.                 } elseif($type == 'museum') {
  611.                     $item->setMuseum($location);
  612.                     $num_new_photos $item->getMuseum()->getNumNewPhotos();
  613.                     $item->getMuseum()->setNumNewPhotos($num_new_photos+1);
  614.                 } elseif($type == 'society') {
  615.                     $item->setSociety($location);
  616.                     $num_new_photos $item->getSociety()->getNumNewPhotos();
  617.                     $item->getSociety()->setNumNewPhotos($num_new_photos+1);
  618.                 }
  619.                 $item->setFilename($newFilename);
  620.                 $item->setType($type);
  621.                 $item->setDate(new \DateTime());
  622.                 $item->setUserId($this->getUser()->getId());
  623.                 $item->setUsername($this->getUser()->getUsername());
  624.                 $item->setApproved('0');
  625.                 $em->persist($item);
  626.                 $em->flush();
  627.                 $this->addFlash('success'$translator->trans("Afbeelding toegevoegd en wacht op goedkeuring"));
  628.                 if($type == 'fossil') {
  629.                     return $this->redirectToRoute('locations_fossil', array('id' => $id) );
  630.                 } elseif($type == 'geology') {
  631.                     return $this->redirectToRoute('locations_geology', array('id' => $id) );
  632.                 } elseif($type == 'museum') {
  633.                     return $this->redirectToRoute('locations_museum', array('id' => $id) );
  634.                 } elseif($type == 'society') {
  635.                     return $this->redirectToRoute('locations_society', array('id' => $id) );
  636.                 }
  637.             } else {
  638.                 $this->addFlash('error'$translator->trans("Geen afbeelding geselecteerd"));
  639.             }
  640.         }
  641.         return $this->render('form_edit.html.twig', [
  642.             'form' => $form->createView(),
  643.             'title' => $translator->trans("Locatie afbeelding toevoegen"),
  644.         ]);
  645.     }
  646.     /**
  647.      * @Route("/locations/gis/add/{return_type}/{return_id}", name="locations_gis_add")
  648.      */
  649.     public function add(string $return_typeint $return_idEntityManagerInterface $emRequest $requestTranslatorInterface $translator)
  650.     {
  651.         $this->denyAccessUnlessGranted('ROLE_USER');
  652.         if($return_type && $return_id) {
  653.             $repository $this->getDoctrine()->getRepository(LocationsGIS::class);
  654.             $gis $repository->findBy(array('type' => $return_type$return_type => $return_id));
  655.             if($return_type == 'fossil') {
  656.                 $repository $this->getDoctrine()->getRepository(LocationsFossil::class);
  657.             } elseif($return_type == 'geology') {
  658.                 $repository $this->getDoctrine()->getRepository(LocationsGeology::class);
  659.             } elseif($return_type == 'museum') {
  660.                 $repository $this->getDoctrine()->getRepository(LocationsMuseum::class);
  661.             } elseif($return_type == 'society') {
  662.                 $repository $this->getDoctrine()->getRepository(LocationsSociety::class);
  663.             }
  664.             $location $repository->findOneBy(array('id' => $return_id));
  665.             $country $location->getCountry();
  666.         } else {
  667.             $gis = array();
  668.         }
  669.         $form $this->createForm(LocationGISCoordinateFormType::class);
  670.         $form->handleRequest($request);
  671.         if ($form->isSubmitted() && $form->isValid()){
  672.             $item $form->getData();
  673.             $item->setCountry($country);
  674.             $item->setUserId($this->getUser()->getId());
  675.             $item->setUsername($this->getUser()->getUsername());
  676.             $item->setApproved('0');
  677.             $item->setType($return_type);
  678.             if($return_type == 'fossil') { $item->setFossil($location); }
  679.             elseif($return_type == 'geology') { $item->setGeology($location); }
  680.             elseif($return_type == 'museum') { $item->setMuseum($location); }
  681.             elseif($return_type == 'society') { $item->setSociety($location); }
  682.             $em->persist($item);
  683.             $em->flush();
  684.             $this->addFlash('success'$translator->trans("Coördinaat toegevoegd"));
  685.            
  686.             return $this->redirectToRoute('locations_gis_item_moderate', array('type' => $return_type'id' => $return_id) );
  687.         }
  688.         return $this->render('locations_gis_edit.html.twig', [
  689.             'form' => $form->createView(),
  690.             'form_name' => 'location_gis_coordinate',
  691.             'gis' => $gis,
  692.         ]);
  693.     }
  694.     /**
  695.      * @Route("/moderate/gis/{type}/{id}", name="locations_gis_item_moderate")
  696.      */
  697.     public function locations_item_gis(string $typeint $id)
  698.     {
  699.         $this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
  700.         $repository $this->getDoctrine()->getRepository(LocationsGIS::class);
  701.         $gis $repository->findBy(array($type => $id));
  702.         return $this->render('locations_gis_item_moderate.html.twig', [
  703.             'gis' => $gis,
  704.             'return_type' => $type,
  705.             'return_id' => $id,
  706.             'type' => $type,
  707.             'id' => $id,
  708.             'all_locations' => false,
  709.             'types' => array($type),
  710.             'filterby' => array('vulnerability' => array('public','slightly','moderate','very')),
  711.             'country' => null
  712.         ]);
  713.     }
  714.     /**
  715.      * @Route("/moderate/gis/edit/{id}/{return_type}/{return_id}", name="locations_gis_moderate_edit") 
  716.      */
  717.     public function edit(int $idstring $return_typeint $return_idLocationsGIS $LocationsGISEntityManagerInterface $emRequest $requestTranslatorInterface $translator)
  718.     {
  719.         $this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
  720.         $repository $this->getDoctrine()->getRepository(LocationsGIS::class);
  721.         $gis $repository->findBy(array('type' => $return_type$return_type => $return_id));
  722.         $form $this->createForm(LocationGISCoordinateFormType::class, $LocationsGIS);
  723.         $form->handleRequest($request);
  724.         if ($form->isSubmitted() && $form->isValid()){
  725.             $item $form->getData();
  726.             $em->persist($item);
  727.             $em->flush();
  728.             $this->addFlash('success'$translator->trans("Coördinaat bijgewerkt"));
  729.             
  730.             return $this->redirectToRoute('locations_gis_item_moderate', array('type' => $return_type'id' => $return_id) );
  731.         }
  732.         return $this->render('locations_gis_edit.html.twig', [
  733.             'form' => $form->createView(),
  734.             'return_type' => $return_type,
  735.             'return_id' => $return_id,
  736.             'edit_id' => $id,
  737.             'gis' => $gis,
  738.             'form_name' => 'location_gis_coordinate'
  739.         ]);
  740.     }
  741.     /**
  742.      * @Route("/moderate/gis/{id}/revoke/{return_type}/{return_id}", name="locations_gis_moderate_revoke")
  743.      */
  744.     public function moderate_revoke(int $idstring $return_typeint $return_idLocationsGIS $LocationsGISEntityManagerInterface $emTranslatorInterface $translator)
  745.     {
  746.         $this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
  747.         $LocationsGIS->setApprovedUserId($this->getUser()->getId());
  748.         $LocationsGIS->setApprovedUsername($this->getUser()->getUsername());
  749.         $LocationsGIS->setApproved('0');
  750.         $em->persist($LocationsGIS);
  751.         $em->flush();
  752.         $this->remove_nearby($LocationsGIS$em);
  753.         $type $LocationsGIS->getType();
  754.         if ($LocationsGIS->getType() == 'fossil') {
  755.             $location_id $LocationsGIS->getFossil()->getId();
  756.         } elseif ($LocationsGIS->getType() == 'geology') {
  757.             $location_id $LocationsGIS->getGeology()->getId();
  758.         } elseif ($LocationsGIS->getType() == 'museum') {
  759.             $location_id $LocationsGIS->getMuseum()->getId();
  760.         } elseif ($LocationsGIS->getType() == 'society') {
  761.             $location_id $LocationsGIS->getSociety()->getId();
  762.         }
  763.         $this->find_new_nearby($location_id$type$em$translator);
  764.         $this->addFlash('success'$translator->trans("Coördinaat ingetrokken"));
  765.         return $this->redirectToRoute('locations_gis_item_moderate', array('type' => $return_type'id' => $return_id) );
  766.     }
  767.     /**
  768.      * @Route("/moderate/gis/{id}/approve/{return_type}/{return_id}", name="locations_gis_moderate_approve")
  769.      */
  770.     public function moderate_approve(int $idstring $return_typeint $return_idLocationsGIS $LocationsGISEntityManagerInterface $emTranslatorInterface $translator)
  771.     {
  772.         $this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
  773.         $LocationsGIS->setApprovedUserId($this->getUser()->getId());
  774.         $LocationsGIS->setApprovedUsername($this->getUser()->getUsername());
  775.         $LocationsGIS->setApproved('1');
  776.         $em->persist($LocationsGIS);
  777.         $em->flush();
  778.         $type $LocationsGIS->getType();
  779.         if ($LocationsGIS->getType() == 'fossil') {
  780.             $location_id $LocationsGIS->getFossil()->getId();
  781.         } elseif ($LocationsGIS->getType() == 'geology') {
  782.             $location_id $LocationsGIS->getGeology()->getId();
  783.         } elseif ($LocationsGIS->getType() == 'museum') {
  784.             $location_id $LocationsGIS->getMuseum()->getId();
  785.         } elseif ($LocationsGIS->getType() == 'society') {
  786.             $location_id $LocationsGIS->getSociety()->getId();
  787.         }
  788.         $this->find_new_nearby($location_id$type$em$translator);
  789.         $this->addFlash('success'$translator->trans("Coördinaat goedgekeurd"));
  790.         return $this->redirectToRoute('locations_gis_item_moderate', array('type' => $return_type'id' => $return_id) );
  791.     }
  792.     /**
  793.      * @Route("/moderate/gis/{id}/delete/{return_type}/{return_id}", name="locations_gis_moderate_delete")
  794.      */
  795.     public function moderate_delete(int $idstring $return_typeint $return_idLocationsGIS $LocationsGISEntityManagerInterface $emTranslatorInterface $translator)
  796.     {
  797.         $this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
  798.         $this->remove_nearby($LocationsGIS$em);
  799.         $type $LocationsGIS->getType();
  800.         if ($LocationsGIS->getType() == 'fossil') {
  801.             $location_id $LocationsGIS->getFossil()->getId();
  802.         } elseif ($LocationsGIS->getType() == 'geology') {
  803.             $location_id $LocationsGIS->getGeology()->getId();
  804.         } elseif ($LocationsGIS->getType() == 'museum') {
  805.             $location_id $LocationsGIS->getMuseum()->getId();
  806.         } elseif ($LocationsGIS->getType() == 'society') {
  807.             $location_id $LocationsGIS->getSociety()->getId();
  808.         }
  809.         $em->remove($LocationsGIS);
  810.         $em->flush();
  811.         $this->find_new_nearby($location_id$type$em$translator);
  812.         $this->addFlash('success'$translator->trans("Coördinaat verwijderd"));
  813.         return $this->redirectToRoute('locations_gis_item_moderate', array('type' => $return_type'id' => $return_id) );
  814.     }
  815.     /**
  816.      * @Route("/locations/{type}/{id}/review", name="locations_review_add")
  817.      */
  818.     public function review_add(string $typeint $idRequest $requestEntityManagerInterface $emTranslatorInterface $translator)
  819.     {
  820.         $this->denyAccessUnlessGranted('ROLE_USER');
  821.         $form $this->createForm(LocationReviewFormType::class);
  822.         $form->handleRequest($request);
  823.         if ($form->isSubmitted() && $form->isValid()){
  824.             $location $this->get_location_by_id($type$id);
  825.             $review $form->getData();
  826.             $review->setUserId($this->getUser()->getId());
  827.             $review->setUsername($this->getUser()->getUsername());
  828.             $review->setType($type);
  829.             if($type == 'fossil') {
  830.                 $review->setFossil($location);
  831.                 $num_reviews $review->getFossil()->getNumReviews();
  832.                 $review->getFossil()->setNumReviews($num_reviews+1);
  833.             } elseif($type == 'geology') {
  834.                 $review->setGeology($location);
  835.                 $num_reviews $review->getGeology()->getNumReviews();
  836.                 $review->getGeology()->setNumReviews($num_reviews+1);
  837.             } elseif($type == 'museum') {
  838.                 $review->setMuseum($location);
  839.                 $num_reviews $review->getMuseum()->getNumReviews();
  840.                 $review->getMuseum()->setNumReviews($num_reviews+1);
  841.             } elseif($type == 'society') {
  842.                 $review->setSociety($location);
  843.                 $num_reviews $review->getSociety()->getNumReviews();
  844.                 $review->getSociety()->setNumReviews($num_reviews+1);
  845.             }
  846.             $em->persist($review);
  847.             $em->flush();
  848.             $this->addFlash('success'$translator->trans("Feedback doorgegeven"));
  849.             if($type 'museum') {
  850.                 return $this->redirectToRoute('locations_museum', array('id' => $id ) );
  851.             }
  852.             
  853.         }
  854.         return $this->render('form_edit.html.twig', [
  855.             'title' => $translator->trans("Feedback doorgeven"),
  856.             'button_text' => $translator->trans("Insturen"),
  857.             'form' => $form->createView()
  858.         ]);
  859.     }
  860.     /**
  861.      * @Route("/moderate/locations/{type}/{id}/reviews", name="locations_moderate_reviews")
  862.      */
  863.     public function moderate_review(string $typeint $idEntityManagerInterface $emTranslatorInterface $translator)
  864.     {
  865.         $this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
  866.         return $this->render('locationreviews_moderate.html.twig', [
  867.             'location' => $this->get_location_by_id($type$id),
  868.             'type' => $type,
  869.         ]);
  870.     }
  871.     /**
  872.      * @Route("/moderate/locations/review/{id}/read/{type}/{location_id}", name="locationsreviews_moderate_read")
  873.      */
  874.     public function review_read(int $location_idstring $typeLocationReviews $locationreviewEntityManagerInterface $emTranslatorInterface $translator)
  875.     {
  876.         $this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
  877.         return $this->render('locationreview.html.twig', [
  878.             'review' => $locationreview,
  879.             'type' => $type,
  880.             'location_id' => $location_id,
  881.         ]);
  882.     }
  883.     /**
  884.      * @Route("/moderate/locations/review/{id}/delete/{type}/{location_id}", name="locationsreviews_moderate_delete")
  885.      */
  886.     public function review_delete(int $location_idstring $typeLocationReviews $locationreviewEntityManagerInterface $emTranslatorInterface $translator)
  887.     {
  888.         $this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
  889.         if($type == 'fossil') {
  890.             $num_reviews $locationreview->getFossil()->getNumReviews();
  891.             $locationreview->getFossil()->setNumReviews($num_reviews-1);
  892.         } elseif($type == 'geology') {
  893.             $num_reviews $locationreview->getGeology()->getNumReviews();
  894.             $locationreview->getGeology()->setNumReviews($num_reviews-1);
  895.         } elseif($type == 'museum') {
  896.             $num_reviews $locationreview->getMuseum()->getNumReviews();
  897.             $locationreview->getMuseum()->setNumReviews($num_reviews-1);
  898.         } elseif($type == 'society') {
  899.             $num_reviews $locationreview->getSociety()->getNumReviews();
  900.             $locationreview->getSociety()->setNumReviews($num_reviews-1);
  901.         }
  902.         $em->persist($locationreview);
  903.         $em->flush();
  904.         $em->remove($locationreview);
  905.         $em->flush();
  906.         $this->addFlash('success'$translator->trans("Locatie review verwijderd"));
  907.         return $this->redirectToRoute('locations_moderate_reviews', array('type' => $type,'id' => $location_id, ));
  908.     }
  909.     /**
  910.      * @Route("/moderate/locations/{type}/{id}/photos", name="locations_moderate_photos")
  911.      */
  912.     public function moderate_photos(string $typeint $idEntityManagerInterface $emTranslatorInterface $translator)
  913.     {
  914.         $this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
  915.         return $this->render('locationphotos_moderate.html.twig', [
  916.             'location' => $this->get_location_by_id($type$id),
  917.             'type' => $type,
  918.             'location_id' => $id,
  919.         ]);
  920.     }
  921.     /**
  922.      * @Route("/moderate/locations/photos/{id}/approve/{return_type}/{return_id}", name="locations_photos_moderate_approve")
  923.      */
  924.     public function moderate_photos_approve(string $return_typeint $return_idLocationPhotos $locationphotoEntityManagerInterface $emTranslatorInterface $translator)
  925.     {
  926.         $this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
  927.         $locationphoto->setApprovedUserId($this->getUser()->getId());
  928.         $locationphoto->setApprovedUsername($this->getUser()->getUsername());
  929.         $locationphoto->setApproved('1');
  930.         $em->persist($locationphoto);
  931.         $em->flush();
  932.         $type $locationphoto->getType();
  933.         if ($locationphoto->getType() == 'fossil') {
  934.             $location_id $locationphoto->getFossil()->getId();
  935.         } elseif ($locationphoto->getType() == 'geology') {
  936.             $location_id $locationphoto->getGeology()->getId();
  937.         } elseif ($locationphoto->getType() == 'museum') {
  938.             $location_id $locationphoto->getMuseum()->getId();
  939.         } elseif ($locationphoto->getType() == 'society') {
  940.             $location_id $locationphoto->getSociety()->getId();
  941.         }
  942.         $this->addFlash('success'$translator->trans("Locatie foto goedgekeurd"));
  943.         return $this->redirectToRoute('locations_moderate_photos', array('type' => $return_type'id' => $return_id) );
  944.     }
  945.     /**
  946.      * @Route("/moderate/locations/photos/{id}/delete/{return_type}/{return_id}", name="locations_photos_moderate_delete")
  947.      */
  948.     public function moderate_photo_delete(string $return_typestring $return_idLocationPhotos $locationphotoEntityManagerInterface $emTranslatorInterface $translator)
  949.     {
  950.         //, UploaderHelper $uploaderHelper
  951.         $this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
  952.         $type $locationphoto->getType();
  953.         if($photo->getApproved() == 0){
  954.             if ($locationphoto->getType() == 'fossil') {
  955.                 $locationphoto->getFossil()->setNumNewPhotos($locationphoto->getFossil()->getNumNewPhotos()-1);
  956.             } elseif ($locationphoto->getType() == 'geology') {
  957.                 $locationphoto->getGeology()->setNumNewPhotos($locationphoto->getGeology()->getNumNewPhotos()-1);
  958.             } elseif ($locationphoto->getType() == 'museum') {
  959.                 $locationphoto->getMuseum()->setNumNewPhotos($locationphoto->getMuseum()->getNumNewPhotos()-1);
  960.             } elseif ($locationphoto->getType() == 'society') {
  961.                 $locationphoto->getSociety()->setNumNewPhotos($locationphoto->getSociety()->getNumNewPhotos()-1);
  962.             }
  963.             $em->persist($item);
  964.         }
  965.       
  966.         $filename $this->getParameter('locationphoto_directory')."/".substr($locationphoto->getFilename(),0,2)."/".$locationphoto->getFilename();
  967.         $filename_thumbnail $this->getParameter('locationphotothumbnail_directory')."/".substr($locationphoto->getFilename(),0,2)."/".$locationphoto->getFilename();
  968.         $filesystem = new Filesystem();
  969.         $filesystem->remove($filename);
  970.         $filesystem->remove($filename_thumbnail);
  971.         $em->remove($locationphoto);
  972.         $em->flush();
  973.         
  974.         $this->addFlash('success'$translator->trans("Locatie foto verwijderd"));
  975.         return $this->redirectToRoute('locations_moderate_photos', array('type' => $return_type,'id' => $return_id, ));
  976.     }
  977. }