diff --git a/config/acl.yaml b/config/acl.yaml index 3e221f67..7e1f910c 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -202,6 +202,17 @@ access_keys: label: Add - id: geofence.delete label: Delete + - id: geofence_blacklist + label: Geofence Blacklist + acls: + - id: geofence_blacklist.menu + label: Menu + - id: geofence_blacklist.list + label: List + - id: geofence_blacklist.add + label: Add + - id: geofence_blacklist.delete + label: Delete - id: rider label: Rider Access diff --git a/config/menu.yaml b/config/menu.yaml index 487a4ef7..37e1c116 100644 --- a/config/menu.yaml +++ b/config/menu.yaml @@ -116,7 +116,11 @@ main_menu: parent: location - id: geofence_list acl: geofence.menu - label: Geofence + label: Geofence Whitelist + parent: location + - id: geofence_blacklist_list + acl: geofence_blacklist.menu + label: Geofence Blacklist parent: location diff --git a/config/routes/geofence_blacklist.yaml b/config/routes/geofence_blacklist.yaml new file mode 100644 index 00000000..5d47f23a --- /dev/null +++ b/config/routes/geofence_blacklist.yaml @@ -0,0 +1,20 @@ +#geofence blacklist + +geofence_blacklist_list: + path: /geofence-blacklist + controller: App\Controller\GeofenceBlacklistController::index + +geofence_blacklist_upload_kml: + path: /geofence-blacklist/upload + controller: App\Controller\GeofenceBlacklistController::uploadKML + methods: [POST] + +geofence_blacklist_create: + path: /geofence-blacklist/create + controller: App\Controller\GeofenceBlacklistController::addForm + methods: [GET] + +geofence_blacklist_delete: + path: /geofence-blacklist/{id} + controller: App\Controller\GeofenceBlacklistController::destroy + methods: [DELETE] diff --git a/src/Controller/GeofenceBlacklistController.php b/src/Controller/GeofenceBlacklistController.php new file mode 100644 index 00000000..486dc258 --- /dev/null +++ b/src/Controller/GeofenceBlacklistController.php @@ -0,0 +1,91 @@ +getDoctrine() + ->getRepository(BlacklistArea::class) + ->findAll();; + + return $this->render('geofence-blacklist/list.html.twig', $params); + } + + /** + * @Menu(selected="geofence_blacklist_list") + * @IsGranted("geofence_blacklist.add") + */ + public function addForm() + { + $params['obj'] = new BlacklistArea(); + + // response + return $this->render('geofence-blacklist/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, 'blacklist'); + + // return response + return $this->json([ + 'success' => true, + 'filename' => $filename + ]); + } + + /** + * @ParamConverter("blacklist_area", class="App\Entity\BlacklistArea") + * @IsGranted("geofence_blacklist.delete") + */ + public function destroy(BlacklistArea $obj, EntityManagerInterface $em) + { + 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(); + } +} diff --git a/src/Entity/BlacklistArea.php b/src/Entity/BlacklistArea.php new file mode 100644 index 00000000..eafd8759 --- /dev/null +++ b/src/Entity/BlacklistArea.php @@ -0,0 +1,86 @@ +date_create = new DateTime(); + } + + public function getID() + { + return $this->id; + } + + public function setDateCreate(DateTime $date_create) + { + $this->date_create = $date_create; + return $this; + } + + public function getDateCreate() + { + return $this->date_Create; + } + + public function setName($name) + { + $this->name = $name; + return $this; + } + + public function getName() + { + return $this->name; + } + + public function setCoverageArea(Polygon $polygon) + { + $this->coverage_area = $polygon; + + return $this; + } + + public function getCoverageArea() + { + return $this->coverage_area; + } +} + diff --git a/src/Service/KMLFileImporter.php b/src/Service/KMLFileImporter.php index 60bcfa54..7722dc95 100644 --- a/src/Service/KMLFileImporter.php +++ b/src/Service/KMLFileImporter.php @@ -5,6 +5,7 @@ namespace App\Service; use XMLReader; use App\Entity\SupportedArea; +use App\Entity\BlacklistArea; use Doctrine\ORM\EntityManagerInterface; @@ -21,7 +22,7 @@ class KMLFileImporter $this->em = $em; } - public function getMapData($fh) + public function getMapData($fh, $type=null) { $placemark_name = ''; @@ -42,7 +43,13 @@ class KMLFileImporter if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == "coordinates") { // each polygon is a new area - $supported_area = new SupportedArea(); + // check if blacklist area or whitelist area. + // type = null if whitelist + if ($type == null) + $supported_area = new SupportedArea(); + else + $supported_area = new BlacklistArea(); + $supported_area->setName($placemark_name); $point_array = []; diff --git a/templates/geofence-blacklist/form.html.twig b/templates/geofence-blacklist/form.html.twig new file mode 100644 index 00000000..3f5e222a --- /dev/null +++ b/templates/geofence-blacklist/form.html.twig @@ -0,0 +1,96 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +