diff --git a/config/acl.yaml b/config/acl.yaml index f6677bdf..85577e38 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -172,6 +172,8 @@ access_keys: label: List - id: geofence.add label: Add + - id: geofence.delete + label: Delete - id: rider label: Rider Access diff --git a/config/routes/geofence.yaml b/config/routes/geofence.yaml index a902802f..a050cc85 100644 --- a/config/routes/geofence.yaml +++ b/config/routes/geofence.yaml @@ -4,6 +4,11 @@ geofence_list: path: /geofence controller: App\Controller\GeofenceController::index +geofence_rows: + path: /geofence/rows + controller: App\Controller\GeofenceController::rows + methods: [POST] + geofence_upload_kml: path: /geofence/upload controller: App\Controller\GeofenceController::uploadKML @@ -13,3 +18,8 @@ geofence_create: path: /geofence/create controller: App\Controller\GeofenceController::addForm methods: [GET] + +geofence_delete: + path: /geofence/{id} + controller: App\Controller\GeofenceController::destroy + methods: [DELETE] diff --git a/src/Controller/GeofenceController.php b/src/Controller/GeofenceController.php index 0411fd39..7ccc4277 100644 --- a/src/Controller/GeofenceController.php +++ b/src/Controller/GeofenceController.php @@ -26,13 +26,53 @@ class GeofenceController extends BaseController $params = $this->initParameters('geofence_list'); - // get query builder $params['areas'] = $this->getDoctrine() + ->getRepository(SupportedArea::class) + ->findAll();; + + return $this->render('geofence/list.html.twig', $params); + } + + public function rows(Request $req) + { + $this->denyAccessUnlessGranted('geofence.list', null, 'No access.'); + + $params = $this->initParameters('geofence_list'); + + // get query builder + $obj_rows = $this->getDoctrine() ->getRepository(SupportedArea::class) ->findAll(); + // add metadata + $meta = [ + 'sort' => 'asc', + 'field' => 'id' + ]; + + // process rows + $rows = []; + foreach($obj_rows as $orow) { + // add row data + $row['id'] = $orow->getID(); + $row['name'] = $orow->getName(); + + // add row metadata + $row['meta'] = [ + 'delete_url' => '' + ]; + + if ($this->isGranted('geofence.delete')) + $row['meta']['delete_url'] = $this->generateUrl('geofence_delete', ['id' => $row['id']]); + + $rows[] = $row; + } + // response - return $this->render('geofence/list.html.twig', $params); + return $this->json([ + 'meta' => $meta, + 'data' => $rows + ]); } public function addForm() @@ -64,4 +104,27 @@ class GeofenceController extends BaseController 'filename' => $filename ]); } + + public function destroy($id) + { + $this->denyAccessUnlessGranted('geofence.delete', null, 'No access.'); + + $params = $this->initParameters('geofence_list'); + + // 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(); + } } diff --git a/templates/geofence/list.html.twig b/templates/geofence/list.html.twig index d26bf7ec..c3c417e9 100644 --- a/templates/geofence/list.html.twig +++ b/templates/geofence/list.html.twig @@ -32,17 +32,19 @@ -
@@ -56,9 +58,10 @@ {% endblock %}