<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use App\Entity\User;
use App\Entity\Countries;
use App\Entity\LocationReviews;
use App\Entity\LocationsGIS;
use App\Entity\LocationsGISNearby;
use App\Entity\LocationsFossil;
use App\Entity\LocationsGeology;
use App\Entity\LocationsMuseum;
use App\Entity\LocationsSociety;
use App\Entity\LocationPhotos;
use App\Repository\LocationsFossilRepository;
use App\Form\LocationGISCoordinateFormType;
use App\Form\LocationGISFilterFormType;
use App\Form\LocationReviewFormType;
use App\Form\LocationPhotoAddFormType;
class LocationsController extends AbstractController
{
public function find_nearby(LocationsGIS $item, EntityManagerInterface $em) {
$locations_nearby = array();
$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');
$query->setParameter('latmin', $item->getCenterLat()-0.5);
$query->setParameter('latmax', $item->getCenterLat()+0.5);
$query->setParameter('lngmin', $item->getCenterLng()-0.5);
$query->setParameter('lngmax', $item->getCenterLng()+0.5);
foreach ($query->getResult() as $key => $location) {
if($location->getType() == $item->getType()){
if ($location->getType() == 'fossil') {
if ($item->getFossil()->getId() != $location->getFossil()->getId()){
$locations_nearby[] = $location;
}
} elseif ($location->getType() == 'geology') {
if ($item->getGeology()->getId() != $location->getGeology()->getId()){
$locations_nearby[] = $location;
}
} elseif ($location->getType() == 'museum') {
if ($item->getMuseum()->getId() != $location->getMuseum()->getId()){
$locations_nearby[] = $location;
}
} elseif ($location->getType() == 'society') {
if ($item->getSociety()->getId() != $location->getSociety()->getId()){
$locations_nearby[] = $location;
}
}
} else {
$locations_nearby[] = $location;
}
}
$repository = $this->getDoctrine()->getRepository(LocationsGISNearby::class);
$fossil_allready=array(); $fossil_allready_reverse=array();
$geology_allready=array(); $geology_allready_reverse=array();
$museum_allready=array(); $museum_allready_reverse=array();
$society_allready=array(); $society_allready_reverse=array();
foreach ($locations_nearby as $key => $location) {
//forward
$is_location_present = $repository->findOneBy(array('gis' => $item->getId(), 'nearby_gis' => $location->getId()));
if(!$is_location_present) {
if($location->getType() == 'fossil') {
$remote_gis_locations = $repository->findBy(array('gis' => $item->getId(), 'type' => 'fossil'));
if (count($remote_gis_locations) > 0) {
foreach ($remote_gis_locations as $key => $remote_gis_location) {
$fossil_allready[] = $remote_gis_location->getNearbyGis()->getFossil()->getId();
}
foreach ($remote_gis_locations as $key => $remote_gis_location) {
if(!in_array($location->getFossil()->getId(), $fossil_allready)){
$this->add_nearby($item, $location, $em);
$this->add_nearby($location, $item, $em);
$fossil_allready[] = $location->getFossil()->getId();
} else {
$fossil_allready[] = $location->getFossil()->getId();
}
}
} else {
$this->add_nearby($item, $location, $em);
$this->add_nearby($location, $item, $em);
}
} elseif($location->getType() == 'geology') {
$remote_gis_locations = $repository->findBy(array('gis' => $item->getId(), 'type' => 'geology'));
if (count($remote_gis_locations) > 0) {
foreach ($remote_gis_locations as $key => $remote_gis_location) {
$geology_allready[] = $remote_gis_location->getNearbyGis()->getGeology()->getId();
}
foreach ($remote_gis_locations as $key => $remote_gis_location) {
if(!in_array($location->getGeology()->getId(), $geology_allready)){
$this->add_nearby($item, $location, $em);
$this->add_nearby($location, $item, $em);
$geology_allready[] = $location->getGeology()->getId();
} else {
$geology_allready[] = $location->getGeology()->getId();
}
}
} else {
$this->add_nearby($item, $location, $em);
$this->add_nearby($location, $item, $em);
}
} elseif($location->getType() == 'museum') {
$remote_gis_locations = $repository->findBy(array('gis' => $item->getId(), 'type' => 'museum'));
if (count($remote_gis_locations) > 0) {
foreach ($remote_gis_locations as $key => $remote_gis_location) {
$museum_allready[] = $remote_gis_location->getNearbyGis()->getMuseum()->getId();
}
foreach ($remote_gis_locations as $key => $remote_gis_location) {
if(!in_array($location->getMuseum()->getId(), $museum_allready)){
$this->add_nearby($item, $location, $em);
$this->add_nearby($location, $item, $em);
$museum_allready[] = $location->getMuseum()->getId();
} else {
$museum_allready[] = $location->getMuseum()->getId();
}
}
} else {
$this->add_nearby($item, $location, $em);
$this->add_nearby($location, $item, $em);
}
} elseif($location->getType() == 'society') {
$remote_gis_locations = $repository->findBy(array('gis' => $item->getId(), 'type' => 'society'));
if (count($remote_gis_locations) > 0) {
foreach ($remote_gis_locations as $key => $remote_gis_location) {
$society_allready[] = $remote_gis_location->getNearbyGis()->getSociety()->getId();
}
foreach ($remote_gis_locations as $key => $remote_gis_location) {
if(!in_array($location->getSociety()->getId(), $society_allready)){
$this->add_nearby($item, $location, $em);
$this->add_nearby($location, $item, $em);
$society_allready[] = $location->getSociety()->getId();
} else {
$society_allready[] = $location->getSociety()->getId();
}
}
} else {
$this->add_nearby($item, $location, $em);
$this->add_nearby($location, $item, $em);
}
}
}
}
return new Response;
}
private function add_nearby($item, $location, $em) {
$add_location = new LocationsGISNearby();
$add_location->setGis($item);
$add_location->setNearbyGis($location);
$add_location->setType($location->getType());
$em->persist($add_location);
$em->flush();
}
public function remove_nearby(LocationsGIS $item, EntityManagerInterface $em){
$repository = $this->getDoctrine()->getRepository(LocationsGISNearby::class);
$gis_nearby = $repository->findBy(array('gis' => $item->getId()));
foreach ($gis_nearby as $key => $gis) {
$em->remove($gis);
$em->flush();
}
$gis_nearby = $repository->findBy(array('nearby_gis' => $item->getId()));
foreach ($gis_nearby as $key => $gis) {
$em->remove($gis);
$em->flush();
}
}
public function find_new_nearby($item_id, $type, EntityManagerInterface $em, TranslatorInterface $translator){
$gis_repository = $this->getDoctrine()->getRepository(LocationsGIS::class);
$gis_locations = $gis_repository->findBy(array($type => $item_id, 'type' => $type, 'approved' => '1'));
$foundGISNearby = null;
$repository = $this->getDoctrine()->getRepository(LocationsGISNearby::class);
foreach ($gis_locations as $key => $gis_location) {
$gis_locations_used = $repository->findOneBy(array('gis' => $gis_location->getId()));
if($gis_locations_used) {
$foundGISNearby = $gis_locations_used;
}
}
if(!$foundGISNearby) {
$gis_location = $gis_repository->findOneBy(array($type => $item_id, 'type' => $type, 'approved' => '1'));
if($gis_location) {
$this->find_nearby($gis_location, $em);
} else {
if ($type == 'fossil') {
$repository = $this->getDoctrine()->getRepository(LocationsFossil::class);
} elseif ($type == 'geology') {
$repository = $this->getDoctrine()->getRepository(LocationsGeology::class);
} elseif ($type == 'museum') {
$repository = $this->getDoctrine()->getRepository(LocationsMuseum::class);
} elseif ($type == 'society') {
$repository = $this->getDoctrine()->getRepository(LocationsSociety::class);
}
$item = $repository->findOneBy(array('id' => $item_id));
$item->setApproved('0');
$em->persist($item);
$em->flush();
$this->addFlash('error', $translator->trans("Er zijn geen goedgekeurde coördinaten meer, locatie ingetrokken"));
}
}
}
private function get_location_by_id(string $type, int $id) {
if($type == 'fossil') {
$repository = $this->getDoctrine()->getRepository(LocationsFossil::class);
} elseif($type == 'geology') {
$repository = $this->getDoctrine()->getRepository(LocationsGeology::class);
} elseif($type == 'museum') {
$repository = $this->getDoctrine()->getRepository(LocationsMuseum::class);
} elseif($type == 'society') {
$repository = $this->getDoctrine()->getRepository(LocationsSociety::class);
}
$location = $repository->findOneBy(array('id'=>$id));
return $location;
}
/**
* @Route("/locations/", name="locations_gis")
* @Route("/locations/user/{user}/{type}", name="locations_gis_user")
*/
public function index(Request $request, TranslatorInterface $translator, User $user = null, String $type = null)
{
$repository = $this->getDoctrine()->getRepository(LocationsGIS::class);
$filters=array();
if($request->query->get('country') != null ) { $filterby['country'] = $request->query->get('country'); }
if($request->query->get('type') != null ) { $filterby['type'] = $request->query->get('type'); }
if ($routeName = $request->get('_route') == 'locations_gis_user') {
if($type != null) { $filterby['type'] = $type; }
}
if($this->getUser() == null){
$filterby['vulnerability'] = array('public');
} else {
$vulnerability = $this->getUser()->getCanSeeVulnerability();
if($vulnerability == 'very') { $filterby['vulnerability'] = array('public','slightly','moderate','very'); }
elseif($vulnerability == 'moderate') { $filterby['vulnerability'] = array('public','slightly','moderate'); }
elseif($vulnerability == 'slightly') { $filterby['vulnerability'] = array('public','slightly'); }
else { $filterby['vulnerability'] = array('public'); }
}
$form = $this->createForm(LocationGISFilterFormType::class, null, [
'action' => $request->getPathInfo('_route'),
]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()){
$filters = $form->getData();
if($filters->getType() != null) {
$filterby['type'] = $filters->getType();
}
if($filters->getCountry() != null) {
$filterby['country'] = $filters->getCountry()->getId();
}
}
$filterby['approved'] = 1;
//$gis = $repository->findBy($filterby,array('type' => 'ASC'));
if($translator->getLocale() == 'nl') {
$oder_field = 'name_nl';
} else {
$oder_field = 'name_en';
}
$locations_filterby=array();
if ($routeName = $request->get('_route') == 'locations_gis_user') {
if($user != null) { $locations_filterby['user_id'] = $user->getId(); }
$user_only = $user->getId();
if(empty($filters)) { $filters = array('user_filter'); }
} else {
$user_only = false;
}
$repository = $this->getDoctrine()->getRepository(Countries::class);
if(isset($filterby['country'])) {
$locations_filterby['country'] = $filterby['country'];
$country = $repository->findOneBy(array('id' => $filterby['country']));
} else {
$country = null;
}
/*if(isset($filterby['vulnerability'])) {
$locations_filterby['vulnerability'] = $filterby['vulnerability'];
if (($key = array_search('none', $locations_filterby['vulnerability'])) === true ) {
unset($locations_filterby['vulnerability'][$key]);
$locations_filterby['vulnerability'][] = 'public';
}
}*/
$fossil_locations=array();
if(!isset($filterby['type']) || $filterby['type'] == 'fossil') {
$repository = $this->getDoctrine()->getRepository(LocationsFossil::class);
$fossil_locations = $repository->findBy($locations_filterby,array('location' => 'ASC'));
}
$geology_locations=array();
if(!isset($filterby['type']) || $filterby['type'] == 'geology') {
$repository = $this->getDoctrine()->getRepository(LocationsGeology::class);
$geology_locations = $repository->findBy($locations_filterby,array('location' => 'ASC'));
}
unset($locations_filterby['vulnerability']);
$museum_locations=array();
if(!isset($filterby['type']) || $filterby['type'] == 'museum') {
$repository = $this->getDoctrine()->getRepository(LocationsMuseum::class);
$museum_locations = $repository->findBy($locations_filterby,array($oder_field => 'ASC'));
}
$society_locations=array();
if(!isset($filterby['type']) || $filterby['type'] == 'society') {
$repository = $this->getDoctrine()->getRepository(LocationsSociety::class);
$society_locations = $repository->findBy($locations_filterby,array($oder_field => 'ASC'));
}
if(!isset($filterby['type'])) {
$filterby_types = array('fossil','geology','museum','society');
} else {
$filterby_types = array($filterby['type']);
}
if(!empty($filters)) { $filter_set = 1; } else { $filter_set = 0; }
return $this->render('locations.html.twig', [
'form' => $form->createView(),
'filterby' => $filterby,
'filter_set' => $filter_set,
'types' => $filterby_types,
'country' => $country,
'fossil_locations' => $fossil_locations,
'geology_locations' => $geology_locations,
'museum_locations' => $museum_locations,
'society_locations' => $society_locations,
'all_locations' => true,
'user_only' => $user_only,
]);
}
/**
* @Route("/locations/geojson/protected/{type}/{vulnerability}", name="locations_gis_protected_geojson")
*/
public function locations_gis_protected_geojson(string $vulnerability, string $type, TranslatorInterface $translator)
{
$this->denyAccessUnlessGranted('ROLE_USER');
$uservulnerability = $this->getUser()->getCanSeeVulnerability();
$filterby = array();
if($uservulnerability == 'very') { $filterby['vulnerability'] = array('slightly','moderate','very'); }
elseif($uservulnerability == 'moderate') { $filterby['vulnerability'] = array('slightly','moderate'); }
elseif($uservulnerability == 'slightly') { $filterby['vulnerability'] = array('slightly'); }
else { $filterby['vulnerability'] = array('none'); }
$fileContent = '{"type":"FeatureCollection","features":[]}';
if(in_array($vulnerability ,$filterby['vulnerability'])) {
$finder = new Finder();
$finder->files()->name('locations.'.$vulnerability.'.'.$type.'.'.$translator->getLocale().'.geojson')->in(__DIR__.'/../../templates/generated');
foreach ($finder as $file) {
$fileContent = $file->getContents();
}
}
$response = new Response($fileContent);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
/**
* @Route("/locations/geojson/user/{user}/{type}/{vulnerability}", name="locations_gis_user_geojson")
*/
public function locations_gis_user_geojson(User $user, string $type, string $vulnerability, TranslatorInterface $translator, RouterInterface $router)
{
if ($this->isGranted('IS_AUTHENTICATED')) {
$uservulnerability = $this->getUser()->getCanSeeVulnerability();
} else {
$uservulnerability=array('public');
}
$filterby = array();
if($uservulnerability == 'very') { $filterby['vulnerability'] = array('public','slightly','moderate','very'); }
elseif($uservulnerability == 'moderate') { $filterby['vulnerability'] = array('public','slightly','moderate'); }
elseif($uservulnerability == 'slightly') { $filterby['vulnerability'] = array('public','slightly'); }
else { $filterby['vulnerability'] = array('public'); }
$fileContent = '{"type":"FeatureCollection","features":[';
$gis = '';
if($type == 'fossil') {
$repository = $this->getDoctrine()->getRepository(LocationsGIS::class);
$gis = $repository->findBy(array('user_id' => $user, 'approved' => '1', 'vulnerability' => $filterby['vulnerability']));
}
if($type == 'geology') {
$repository = $this->getDoctrine()->getRepository(LocationsGIS::class);
$gis = $repository->findBy(array('user_id' => $user, 'approved' => '1', 'vulnerability' => $filterby['vulnerability']));
}
if($type == 'museum') {
$repository = $this->getDoctrine()->getRepository(LocationsGIS::class);
$gis = $repository->findBy(array('user_id' => $user, 'approved' => '1', 'vulnerability' => $filterby['vulnerability']));
}
if($type == 'society') {
$repository = $this->getDoctrine()->getRepository(LocationsGIS::class);
$gis = $repository->findBy(array('user_id' => $user, 'approved' => '1', 'vulnerability' => $filterby['vulnerability']));
}
$length = count($gis);
$counter = 0;
foreach($gis as $location){
$popupContent = '';
if($location->getType() == 'fossil') { $popupContent .= "<b>".$location->getNameEn()."</b><br><br>".$translator->trans('Fossielenlocatie')."<br>";
if($location->GetFossil()->getClosed() == '1') { $popupContent .= "<span style='color: #FF0000;'>".$translator->trans('Gesloten')."</span><br>"; }
$popupContent .= "<a href='".$router->generate('locations_fossil', array('id'=>$location->GetFossil()->getId()))."'>".$translator->trans('Locatie bekijken')."</a>"; }
if($location->getType() == 'geology') { $popupContent .= "<b>".$location->getNameEn()."</b><br><br>".$translator->trans('Geologisch excursiepunt')."<br>";
if($location->GetGeology()->getClosed() == '1') { $popupContent .= "<span style='color: #FF0000;'>".$translator->trans('Gesloten')."</span><br>"; }
$popupContent .= "<a href='".$router->generate('locations_geology', array('id'=>$location->GetGeology()->getId()))."'>".$translator->trans('Locatie bekijken')."</a>"; }
if($location->getType() == 'museum') { $popupContent .= "<b>".$location->getNameEn()."</b><br><br>".$translator->trans('Museum')."<br>";
$popupContent .= "<a href='".$router->generate('locations_museum', array('id'=>$location->GetMuseum()->getId()))."'>".$translator->trans('Locatie bekijken')."</a>"; }
if($location->getType() == 'society') { $popupContent .= "<b>".$location->getNameEn()."</b><br><br>".$translator->trans('Vereniging')."<br>";
$popupContent .= "<a href='".$router->generate('locations_society', array('id'=>$location->GetSociety()->getId()))."'>".$translator->trans('Locatie bekijken')."</a>"; }
if ($translator->getLocale() == 'nl'){
$name = $location->getNameEn();
} else {
$name = $location->getNameNl();
}
$fileContent .= '
{
"type": "Feature",
"id": "'.$location->getId().'",
"properties": {
"name": "'.$name.'",
"popupContent":"'.$popupContent.'",
"type": "'.$location->getType().'",
"icon": "'.$location->getType().'Icon"
},
"geometry" :
{
"type":"'.$location->getShape().'",
"coordinates":'.str_replace('"', "", $location->getData()).',
"center": ['.$location->getCenterLng().','.$location->getCenterLat().']
}
}';
if($counter != ($length-1)) {$fileContent .= ',';}
$counter++;
}
$fileContent .= ']}';
$response = new Response($fileContent);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
/**
* @Route("/locations/geojson/locations/{type}/{id}", name="locations_gis_geojson_locations")
*/
public function locations_gis_geojson_locations(string $type, int $id, TranslatorInterface $translator, RouterInterface $router)
{
if ($this->isGranted('IS_AUTHENTICATED')) {
$uservulnerability = $this->getUser()->getCanSeeVulnerability();
} else {
$uservulnerability=array('public');
}
$filterby = array();
if($uservulnerability == 'very') { $filterby['vulnerability'] = array('public','slightly','moderate','very'); }
elseif($uservulnerability == 'moderate') { $filterby['vulnerability'] = array('public','slightly','moderate'); }
elseif($uservulnerability == 'slightly') { $filterby['vulnerability'] = array('public','slightly'); }
else { $filterby['vulnerability'] = array('public'); }
$fileContent = '{"type":"FeatureCollection","features":[';
$gis = '';
if($type == 'fossil') {
$repository = $this->getDoctrine()->getRepository(LocationsGIS::class);
$gis = $repository->findBy(array('fossil' => $id, 'approved' => '1', 'vulnerability' => $filterby['vulnerability']));
}
if($type == 'geology') {
$repository = $this->getDoctrine()->getRepository(LocationsGIS::class);
$gis = $repository->findBy(array('geology' => $id, 'approved' => '1', 'vulnerability' => $filterby['vulnerability']));
}
if($type == 'museum') {
$repository = $this->getDoctrine()->getRepository(LocationsGIS::class);
$gis = $repository->findBy(array('museum' => $id, 'approved' => '1', 'vulnerability' => $filterby['vulnerability']));
}
if($type == 'society') {
$repository = $this->getDoctrine()->getRepository(LocationsGIS::class);
$gis = $repository->findBy(array('society' => $id, 'approved' => '1', 'vulnerability' => $filterby['vulnerability']));
}
$length = count($gis);
$counter = 0;
foreach($gis as $location){
$popupContent = '';
if($location->getType() == 'fossil') { $popupContent .= "<b>".$location->getNameEn()."</b><br><br>".$translator->trans('Fossielenlocatie')."<br>";
if($location->GetFossil()->getClosed() == '1') { $popupContent .= "<span style='color: #FF0000;'>".$translator->trans('Gesloten')."</span><br>"; }
$popupContent .= "<a href='".$router->generate('locations_fossil', array('id'=>$location->GetFossil()->getId()))."'>".$translator->trans('Locatie bekijken')."</a>"; }
if($location->getType() == 'geology') { $popupContent .= "<b>".$location->getNameEn()."</b><br><br>".$translator->trans('Geologisch excursiepunt')."<br>";
if($location->GetGeology()->getClosed() == '1') { $popupContent .= "<span style='color: #FF0000;'>".$translator->trans('Gesloten')."</span><br>"; }
$popupContent .= "<a href='".$router->generate('locations_geology', array('id'=>$location->GetGeology()->getId()))."'>".$translator->trans('Locatie bekijken')."</a>"; }
if($location->getType() == 'museum') { $popupContent .= "<b>".$location->getNameEn()."</b><br><br>".$translator->trans('Museum')."<br>";
$popupContent .= "<a href='".$router->generate('locations_museum', array('id'=>$location->GetMuseum()->getId()))."'>".$translator->trans('Locatie bekijken')."</a>"; }
if($location->getType() == 'society') { $popupContent .= "<b>".$location->getNameEn()."</b><br><br>".$translator->trans('Vereniging')."<br>";
$popupContent .= "<a href='".$router->generate('locations_society', array('id'=>$location->GetSociety()->getId()))."'>".$translator->trans('Locatie bekijken')."</a>"; }
if ($translator->getLocale() == 'nl'){
$name = $location->getNameEn();
} else {
$name = $location->getNameNl();
}
$fileContent .= '
{
"type": "Feature",
"id": "'.$location->getId().'",
"properties": {
"name": "'.$name.'",
"popupContent":"'.$popupContent.'",
"type": "'.$location->getType().'",
"icon": "'.$location->getType().'Icon"
},
"geometry" :
{
"type":"'.$location->getShape().'",
"coordinates":'.str_replace('"', "", $location->getData()).',
"center": ['.$location->getCenterLng().','.$location->getCenterLat().']
}
}';
if($counter != ($length-1)) {$fileContent .= ',';}
$counter++;
}
$fileContent .= ']}';
$response = new Response($fileContent);
$response->headers->set('Content-Type', 'application/json');
return $response;
}
/**
* @Route("/locations/geojson/moderate/location/{id}", name="locations_gis_geojson_moderate_location")
*/
/*public function locations_gis_geojson_moderate_location( int $id, TranslatorInterface $translator)
{
$this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
$uservulnerability = $this->getUser()->getCanSeeVulnerability();
$filterby = array();
if($uservulnerability == 'very') { $filterby['vulnerability'] = array('public','slightly','moderate','very'); }
elseif($uservulnerability == 'moderate') { $filterby['vulnerability'] = array('public','slightly','moderate'); }
elseif($uservulnerability == 'slightly') { $filterby['vulnerability'] = array('public','slightly'); }
else { $filterby['vulnerability'] = array('public'); }
$fileContent = '{"type":"FeatureCollection","features":[';
$repository = $this->getDoctrine()->getRepository(LocationsGIS::class);
$location = $repository->findOneBy(array('id' => $id));
if ($translator->getLocale() == 'nl'){
$name = $location->getNameEn();
} else {
$name = $location->getNameNl();
}
$fileContent .= '
{
"type":"Feature",
"id":"'.$location->getId().'",
"properties": {
"name":"'.$name.'"
},
"geometry":
{
"type":"'.$location->getShape().'",
"coordinates":'.str_replace('"', "", $location->getData()).'
}
}';
$fileContent .= ']}';
$response = new Response($fileContent);
$response->headers->set('Content-Type', 'application/json');
return $response;
}*/
/**
* @Route("/moderate/gis/", name="locations_gis_moderate")
*/
public function locations_gis()
{
$this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
$repository = $this->getDoctrine()->getRepository(LocationsGIS::class);
$gis = $repository->findBy(array('approved' => '0'));
return $this->render('locations_gis_moderate.html.twig', [
'gis' => $gis,
]);
}
/**
* @Route("/locations/add", name="locations_user_add")
*/
public function locations_user_add()
{
$this->denyAccessUnlessGranted('ROLE_USER');
if($_ENV['DISABLE_FORMS'] == "true") { return $this->render('maintenance_form_disabled.html.twig'); }
return $this->render('locations_user_add.html.twig');
}
/**
* @Route("/locations/photo/add/{type}/{id}", name="locations_photo_add")
*/
public function locations_photo_add(string $type, int $id, EntityManagerInterface $em, Request $request, TranslatorInterface $translator)
{
$this->denyAccessUnlessGranted('ROLE_USER');
if($_ENV['DISABLE_FORMS'] == "true") { return $this->render('maintenance_form_disabled.html.twig'); }
$form = $this->createForm(LocationPhotoAddFormType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()){
$item = $form->getData();
$locationImage = $form->get('filename')->getData();
if($locationImage) {
$get_valid_name = $this->forward('App\Controller\FileUploadController:get_valid_name', [
'basePath' => $this->getParameter('locationphoto_directory'),
'name' => $locationImage->getClientOriginalName(),
]);
$newFilename = $get_valid_name->getContent();
try {
$locationImage->move(
$this->getParameter('locationphoto_directory')."/".substr($newFilename,0,2),
$newFilename
);
} catch (FileException $e) {
//ToDo-Ante
// ... handle exception if something happens during file upload
}
if($type == 'fossil') {
$repository = $this->getDoctrine()->getRepository(LocationsFossil::class);
} elseif($type == 'geology') {
$repository = $this->getDoctrine()->getRepository(LocationsGeology::class);
} elseif($type == 'museum') {
$repository = $this->getDoctrine()->getRepository(LocationsMuseum::class);
} elseif($type == 'society') {
$repository = $this->getDoctrine()->getRepository(LocationsSociety::class);
}
$location = $repository->findOneBy(array('id' => $id));
if($type == 'fossil') {
$item->setFossil($location);
$num_new_photos = $item->getFossil()->getNumNewPhotos();
$item->getFossil()->setNumNewPhotos($num_new_photos+1);
} elseif($type == 'geology') {
$item->setGeology($location);
$num_new_photos = $item->getGeology()->getNumNewPhotos();
$item->getGeology()->setNumNewPhotos($num_new_photos+1);
} elseif($type == 'museum') {
$item->setMuseum($location);
$num_new_photos = $item->getMuseum()->getNumNewPhotos();
$item->getMuseum()->setNumNewPhotos($num_new_photos+1);
} elseif($type == 'society') {
$item->setSociety($location);
$num_new_photos = $item->getSociety()->getNumNewPhotos();
$item->getSociety()->setNumNewPhotos($num_new_photos+1);
}
$item->setFilename($newFilename);
$item->setType($type);
$item->setDate(new \DateTime());
$item->setUserId($this->getUser()->getId());
$item->setUsername($this->getUser()->getUsername());
$item->setApproved('0');
$em->persist($item);
$em->flush();
$this->addFlash('success', $translator->trans("Afbeelding toegevoegd en wacht op goedkeuring"));
if($type == 'fossil') {
return $this->redirectToRoute('locations_fossil', array('id' => $id) );
} elseif($type == 'geology') {
return $this->redirectToRoute('locations_geology', array('id' => $id) );
} elseif($type == 'museum') {
return $this->redirectToRoute('locations_museum', array('id' => $id) );
} elseif($type == 'society') {
return $this->redirectToRoute('locations_society', array('id' => $id) );
}
} else {
$this->addFlash('error', $translator->trans("Geen afbeelding geselecteerd"));
}
}
return $this->render('form_edit.html.twig', [
'form' => $form->createView(),
'title' => $translator->trans("Locatie afbeelding toevoegen"),
]);
}
/**
* @Route("/locations/gis/add/{return_type}/{return_id}", name="locations_gis_add")
*/
public function add(string $return_type, int $return_id, EntityManagerInterface $em, Request $request, TranslatorInterface $translator)
{
$this->denyAccessUnlessGranted('ROLE_USER');
if($return_type && $return_id) {
$repository = $this->getDoctrine()->getRepository(LocationsGIS::class);
$gis = $repository->findBy(array('type' => $return_type, $return_type => $return_id));
if($return_type == 'fossil') {
$repository = $this->getDoctrine()->getRepository(LocationsFossil::class);
} elseif($return_type == 'geology') {
$repository = $this->getDoctrine()->getRepository(LocationsGeology::class);
} elseif($return_type == 'museum') {
$repository = $this->getDoctrine()->getRepository(LocationsMuseum::class);
} elseif($return_type == 'society') {
$repository = $this->getDoctrine()->getRepository(LocationsSociety::class);
}
$location = $repository->findOneBy(array('id' => $return_id));
$country = $location->getCountry();
} else {
$gis = array();
}
$form = $this->createForm(LocationGISCoordinateFormType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()){
$item = $form->getData();
$item->setCountry($country);
$item->setUserId($this->getUser()->getId());
$item->setUsername($this->getUser()->getUsername());
$item->setApproved('0');
$item->setType($return_type);
if($return_type == 'fossil') { $item->setFossil($location); }
elseif($return_type == 'geology') { $item->setGeology($location); }
elseif($return_type == 'museum') { $item->setMuseum($location); }
elseif($return_type == 'society') { $item->setSociety($location); }
$em->persist($item);
$em->flush();
$this->addFlash('success', $translator->trans("Coördinaat toegevoegd"));
return $this->redirectToRoute('locations_gis_item_moderate', array('type' => $return_type, 'id' => $return_id) );
}
return $this->render('locations_gis_edit.html.twig', [
'form' => $form->createView(),
'form_name' => 'location_gis_coordinate',
'gis' => $gis,
]);
}
/**
* @Route("/moderate/gis/{type}/{id}", name="locations_gis_item_moderate")
*/
public function locations_item_gis(string $type, int $id)
{
$this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
$repository = $this->getDoctrine()->getRepository(LocationsGIS::class);
$gis = $repository->findBy(array($type => $id));
return $this->render('locations_gis_item_moderate.html.twig', [
'gis' => $gis,
'return_type' => $type,
'return_id' => $id,
'type' => $type,
'id' => $id,
'all_locations' => false,
'types' => array($type),
'filterby' => array('vulnerability' => array('public','slightly','moderate','very')),
'country' => null
]);
}
/**
* @Route("/moderate/gis/edit/{id}/{return_type}/{return_id}", name="locations_gis_moderate_edit")
*/
public function edit(int $id, string $return_type, int $return_id, LocationsGIS $LocationsGIS, EntityManagerInterface $em, Request $request, TranslatorInterface $translator)
{
$this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
$repository = $this->getDoctrine()->getRepository(LocationsGIS::class);
$gis = $repository->findBy(array('type' => $return_type, $return_type => $return_id));
$form = $this->createForm(LocationGISCoordinateFormType::class, $LocationsGIS);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()){
$item = $form->getData();
$em->persist($item);
$em->flush();
$this->addFlash('success', $translator->trans("Coördinaat bijgewerkt"));
return $this->redirectToRoute('locations_gis_item_moderate', array('type' => $return_type, 'id' => $return_id) );
}
return $this->render('locations_gis_edit.html.twig', [
'form' => $form->createView(),
'return_type' => $return_type,
'return_id' => $return_id,
'edit_id' => $id,
'gis' => $gis,
'form_name' => 'location_gis_coordinate'
]);
}
/**
* @Route("/moderate/gis/{id}/revoke/{return_type}/{return_id}", name="locations_gis_moderate_revoke")
*/
public function moderate_revoke(int $id, string $return_type, int $return_id, LocationsGIS $LocationsGIS, EntityManagerInterface $em, TranslatorInterface $translator)
{
$this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
$LocationsGIS->setApprovedUserId($this->getUser()->getId());
$LocationsGIS->setApprovedUsername($this->getUser()->getUsername());
$LocationsGIS->setApproved('0');
$em->persist($LocationsGIS);
$em->flush();
$this->remove_nearby($LocationsGIS, $em);
$type = $LocationsGIS->getType();
if ($LocationsGIS->getType() == 'fossil') {
$location_id = $LocationsGIS->getFossil()->getId();
} elseif ($LocationsGIS->getType() == 'geology') {
$location_id = $LocationsGIS->getGeology()->getId();
} elseif ($LocationsGIS->getType() == 'museum') {
$location_id = $LocationsGIS->getMuseum()->getId();
} elseif ($LocationsGIS->getType() == 'society') {
$location_id = $LocationsGIS->getSociety()->getId();
}
$this->find_new_nearby($location_id, $type, $em, $translator);
$this->addFlash('success', $translator->trans("Coördinaat ingetrokken"));
return $this->redirectToRoute('locations_gis_item_moderate', array('type' => $return_type, 'id' => $return_id) );
}
/**
* @Route("/moderate/gis/{id}/approve/{return_type}/{return_id}", name="locations_gis_moderate_approve")
*/
public function moderate_approve(int $id, string $return_type, int $return_id, LocationsGIS $LocationsGIS, EntityManagerInterface $em, TranslatorInterface $translator)
{
$this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
$LocationsGIS->setApprovedUserId($this->getUser()->getId());
$LocationsGIS->setApprovedUsername($this->getUser()->getUsername());
$LocationsGIS->setApproved('1');
$em->persist($LocationsGIS);
$em->flush();
$type = $LocationsGIS->getType();
if ($LocationsGIS->getType() == 'fossil') {
$location_id = $LocationsGIS->getFossil()->getId();
} elseif ($LocationsGIS->getType() == 'geology') {
$location_id = $LocationsGIS->getGeology()->getId();
} elseif ($LocationsGIS->getType() == 'museum') {
$location_id = $LocationsGIS->getMuseum()->getId();
} elseif ($LocationsGIS->getType() == 'society') {
$location_id = $LocationsGIS->getSociety()->getId();
}
$this->find_new_nearby($location_id, $type, $em, $translator);
$this->addFlash('success', $translator->trans("Coördinaat goedgekeurd"));
return $this->redirectToRoute('locations_gis_item_moderate', array('type' => $return_type, 'id' => $return_id) );
}
/**
* @Route("/moderate/gis/{id}/delete/{return_type}/{return_id}", name="locations_gis_moderate_delete")
*/
public function moderate_delete(int $id, string $return_type, int $return_id, LocationsGIS $LocationsGIS, EntityManagerInterface $em, TranslatorInterface $translator)
{
$this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
$this->remove_nearby($LocationsGIS, $em);
$type = $LocationsGIS->getType();
if ($LocationsGIS->getType() == 'fossil') {
$location_id = $LocationsGIS->getFossil()->getId();
} elseif ($LocationsGIS->getType() == 'geology') {
$location_id = $LocationsGIS->getGeology()->getId();
} elseif ($LocationsGIS->getType() == 'museum') {
$location_id = $LocationsGIS->getMuseum()->getId();
} elseif ($LocationsGIS->getType() == 'society') {
$location_id = $LocationsGIS->getSociety()->getId();
}
$em->remove($LocationsGIS);
$em->flush();
$this->find_new_nearby($location_id, $type, $em, $translator);
$this->addFlash('success', $translator->trans("Coördinaat verwijderd"));
return $this->redirectToRoute('locations_gis_item_moderate', array('type' => $return_type, 'id' => $return_id) );
}
/**
* @Route("/locations/{type}/{id}/review", name="locations_review_add")
*/
public function review_add(string $type, int $id, Request $request, EntityManagerInterface $em, TranslatorInterface $translator)
{
$this->denyAccessUnlessGranted('ROLE_USER');
$form = $this->createForm(LocationReviewFormType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()){
$location = $this->get_location_by_id($type, $id);
$review = $form->getData();
$review->setUserId($this->getUser()->getId());
$review->setUsername($this->getUser()->getUsername());
$review->setType($type);
if($type == 'fossil') {
$review->setFossil($location);
$num_reviews = $review->getFossil()->getNumReviews();
$review->getFossil()->setNumReviews($num_reviews+1);
} elseif($type == 'geology') {
$review->setGeology($location);
$num_reviews = $review->getGeology()->getNumReviews();
$review->getGeology()->setNumReviews($num_reviews+1);
} elseif($type == 'museum') {
$review->setMuseum($location);
$num_reviews = $review->getMuseum()->getNumReviews();
$review->getMuseum()->setNumReviews($num_reviews+1);
} elseif($type == 'society') {
$review->setSociety($location);
$num_reviews = $review->getSociety()->getNumReviews();
$review->getSociety()->setNumReviews($num_reviews+1);
}
$em->persist($review);
$em->flush();
$this->addFlash('success', $translator->trans("Feedback doorgegeven"));
if($type = 'museum') {
return $this->redirectToRoute('locations_museum', array('id' => $id ) );
}
}
return $this->render('form_edit.html.twig', [
'title' => $translator->trans("Feedback doorgeven"),
'button_text' => $translator->trans("Insturen"),
'form' => $form->createView()
]);
}
/**
* @Route("/moderate/locations/{type}/{id}/reviews", name="locations_moderate_reviews")
*/
public function moderate_review(string $type, int $id, EntityManagerInterface $em, TranslatorInterface $translator)
{
$this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
return $this->render('locationreviews_moderate.html.twig', [
'location' => $this->get_location_by_id($type, $id),
'type' => $type,
]);
}
/**
* @Route("/moderate/locations/review/{id}/read/{type}/{location_id}", name="locationsreviews_moderate_read")
*/
public function review_read(int $location_id, string $type, LocationReviews $locationreview, EntityManagerInterface $em, TranslatorInterface $translator)
{
$this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
return $this->render('locationreview.html.twig', [
'review' => $locationreview,
'type' => $type,
'location_id' => $location_id,
]);
}
/**
* @Route("/moderate/locations/review/{id}/delete/{type}/{location_id}", name="locationsreviews_moderate_delete")
*/
public function review_delete(int $location_id, string $type, LocationReviews $locationreview, EntityManagerInterface $em, TranslatorInterface $translator)
{
$this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
if($type == 'fossil') {
$num_reviews = $locationreview->getFossil()->getNumReviews();
$locationreview->getFossil()->setNumReviews($num_reviews-1);
} elseif($type == 'geology') {
$num_reviews = $locationreview->getGeology()->getNumReviews();
$locationreview->getGeology()->setNumReviews($num_reviews-1);
} elseif($type == 'museum') {
$num_reviews = $locationreview->getMuseum()->getNumReviews();
$locationreview->getMuseum()->setNumReviews($num_reviews-1);
} elseif($type == 'society') {
$num_reviews = $locationreview->getSociety()->getNumReviews();
$locationreview->getSociety()->setNumReviews($num_reviews-1);
}
$em->persist($locationreview);
$em->flush();
$em->remove($locationreview);
$em->flush();
$this->addFlash('success', $translator->trans("Locatie review verwijderd"));
return $this->redirectToRoute('locations_moderate_reviews', array('type' => $type,'id' => $location_id, ));
}
/**
* @Route("/moderate/locations/{type}/{id}/photos", name="locations_moderate_photos")
*/
public function moderate_photos(string $type, int $id, EntityManagerInterface $em, TranslatorInterface $translator)
{
$this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
return $this->render('locationphotos_moderate.html.twig', [
'location' => $this->get_location_by_id($type, $id),
'type' => $type,
'location_id' => $id,
]);
}
/**
* @Route("/moderate/locations/photos/{id}/approve/{return_type}/{return_id}", name="locations_photos_moderate_approve")
*/
public function moderate_photos_approve(string $return_type, int $return_id, LocationPhotos $locationphoto, EntityManagerInterface $em, TranslatorInterface $translator)
{
$this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
$locationphoto->setApprovedUserId($this->getUser()->getId());
$locationphoto->setApprovedUsername($this->getUser()->getUsername());
$locationphoto->setApproved('1');
$em->persist($locationphoto);
$em->flush();
$type = $locationphoto->getType();
if ($locationphoto->getType() == 'fossil') {
$location_id = $locationphoto->getFossil()->getId();
} elseif ($locationphoto->getType() == 'geology') {
$location_id = $locationphoto->getGeology()->getId();
} elseif ($locationphoto->getType() == 'museum') {
$location_id = $locationphoto->getMuseum()->getId();
} elseif ($locationphoto->getType() == 'society') {
$location_id = $locationphoto->getSociety()->getId();
}
$this->addFlash('success', $translator->trans("Locatie foto goedgekeurd"));
return $this->redirectToRoute('locations_moderate_photos', array('type' => $return_type, 'id' => $return_id) );
}
/**
* @Route("/moderate/locations/photos/{id}/delete/{return_type}/{return_id}", name="locations_photos_moderate_delete")
*/
public function moderate_photo_delete(string $return_type, string $return_id, LocationPhotos $locationphoto, EntityManagerInterface $em, TranslatorInterface $translator)
{
//, UploaderHelper $uploaderHelper
$this->denyAccessUnlessGranted('ROLE_MOD_LOCATIONS');
$type = $locationphoto->getType();
if($photo->getApproved() == 0){
if ($locationphoto->getType() == 'fossil') {
$locationphoto->getFossil()->setNumNewPhotos($locationphoto->getFossil()->getNumNewPhotos()-1);
} elseif ($locationphoto->getType() == 'geology') {
$locationphoto->getGeology()->setNumNewPhotos($locationphoto->getGeology()->getNumNewPhotos()-1);
} elseif ($locationphoto->getType() == 'museum') {
$locationphoto->getMuseum()->setNumNewPhotos($locationphoto->getMuseum()->getNumNewPhotos()-1);
} elseif ($locationphoto->getType() == 'society') {
$locationphoto->getSociety()->setNumNewPhotos($locationphoto->getSociety()->getNumNewPhotos()-1);
}
$em->persist($item);
}
$filename = $this->getParameter('locationphoto_directory')."/".substr($locationphoto->getFilename(),0,2)."/".$locationphoto->getFilename();
$filename_thumbnail = $this->getParameter('locationphotothumbnail_directory')."/".substr($locationphoto->getFilename(),0,2)."/".$locationphoto->getFilename();
$filesystem = new Filesystem();
$filesystem->remove($filename);
$filesystem->remove($filename_thumbnail);
$em->remove($locationphoto);
$em->flush();
$this->addFlash('success', $translator->trans("Locatie foto verwijderd"));
return $this->redirectToRoute('locations_moderate_photos', array('type' => $return_type,'id' => $return_id, ));
}
}