91 lines
2.4 KiB
PHP
91 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Entity\SupportedArea;
|
|
|
|
use App\Service\KMLFileImporter;
|
|
use App\Service\FileUploader;
|
|
|
|
use Doctrine\ORM\Query;
|
|
use Doctrine\ORM\QueryBuilder;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
|
|
use Catalyst\MenuBundle\Annotation\Menu;
|
|
|
|
use CrEOF\Spatial\PHP\Types\Geometry\Point;
|
|
use DateTime;
|
|
|
|
class GeofenceController extends Controller
|
|
{
|
|
/**
|
|
* @Menu(selected="geofence_list")
|
|
*/
|
|
public function index()
|
|
{
|
|
$this->denyAccessUnlessGranted('geofence.list', null, 'No access.');
|
|
|
|
$params['areas'] = $this->getDoctrine()
|
|
->getRepository(SupportedArea::class)
|
|
->findAll();;
|
|
|
|
return $this->render('geofence/list.html.twig', $params);
|
|
}
|
|
|
|
/**
|
|
* @Menu(selected="geofence_list")
|
|
*/
|
|
public function addForm()
|
|
{
|
|
$this->denyAccessUnlessGranted('geofence.add', null, 'No access.');
|
|
|
|
$params['obj'] = new SupportedArea();
|
|
|
|
// response
|
|
return $this->render('geofence/form.html.twig', $params);
|
|
}
|
|
|
|
public function uploadKML(Request $req, FileUploader $uploader, KMLFileImporter $importer)
|
|
{
|
|
// retrieve temporary info for file
|
|
$file = $req->files->get('kml_file');
|
|
|
|
// upload the file
|
|
$filename = $uploader->upload($file);
|
|
|
|
// process the kml file
|
|
$kml_file = $uploader->getTargetDir() . '/' . $filename;
|
|
$importer->getMapdata($kml_file);
|
|
|
|
// return response
|
|
return $this->json([
|
|
'success' => true,
|
|
'filename' => $filename
|
|
]);
|
|
}
|
|
|
|
public function destroy($id)
|
|
{
|
|
$this->denyAccessUnlessGranted('geofence.delete', null, 'No access.');
|
|
|
|
// get object data
|
|
$em = $this->getDoctrine()->getManager();
|
|
$obj = $em->getRepository(SupportedArea::class)->find($id);
|
|
|
|
if (empty($obj))
|
|
throw $this->createNotFoundException('The item does not exist');
|
|
|
|
// delete this object
|
|
$em->remove($obj);
|
|
$em->flush();
|
|
|
|
// response
|
|
$response = new Response();
|
|
$response->setStatusCode(Response::HTTP_OK);
|
|
$response->send();
|
|
}
|
|
}
|