diff --git a/config/routes.yaml b/config/routes.yaml index e2127d9a..8ec676af 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -7,6 +7,8 @@ home: path: / controller: App\Controller\HomeController::index +# auth + login: path: /login controller: App\Controller\SecurityController::login @@ -14,10 +16,48 @@ login: logout: path: /logout +# users + user_list: path: /users controller: App\Controller\UserController::index +# roles + +role_list: + path: /roles + controller: App\Controller\RoleController::index + +role_rows: + path: /roles/rows + controller: App\Controller\RoleController::rows + methods: [POST] + +role_create: + path: /roles/create + controller: App\Controller\RowController::create + +role_create_submit: + path: /roles/create + controller: App\Controller\RowController::createSubmit + methods: [PUT] + +role_update: + path: /roles/{id} + controller: App\Controller\RowController::update + +role_update_submit: + path: /roles/{id} + controller: App\Controller\RowController::updateSubmit + methods: [POST] + +role_delete: + path: /roles/{id} + controller: App\Controller\RoleController::destroy + methods: [DELETE] + +# test + test_acl: path: /test_acl controller: App\Controller\TestController::index diff --git a/src/Controller/RoleController.php b/src/Controller/RoleController.php new file mode 100644 index 00000000..3f195883 --- /dev/null +++ b/src/Controller/RoleController.php @@ -0,0 +1,91 @@ +initParameters('role_list'); + + $qb = $this->getDoctrine() + ->getRepository(Role::class) + ->createQueryBuilder('q') + ->getQuery(); + + // get all rows + $rows = $qb->getResult(Query::HYDRATE_ARRAY); + + return $this->render('role/list.html.twig', $params); + } + + public function rows() + { + // build query + $qb = $this->getDoctrine() + ->getRepository(Role::class) + ->createQueryBuilder('q') + ->getQuery(); + + // get all rows + $rows = $qb->getResult(Query::HYDRATE_ARRAY); + + return $this->json(['data' => $rows]); + } + + public function create() + { + $params = $this->initParameters('role_list'); + + return $this->render('role/form.html.twig', $params); + } + + public function createSubmit() + { + + } + + public function update($id) + { + $params = $this->initParameters('role_list'); + + // get row data + $repo = $this->getDoctrine()->getRepository(Role::class); + $row = $repo->find($id); + + if (!empty($row)) { + $params['row'] = $row; + } else { + throw $this->createNotFoundException('The item does not exist'); + } + + return $this->render('role/form.html.twig', $params); + } + + public function updateSubmit($id) + { + + } + + public function destroy($id) + { + $params = $this->initParameters('role_list'); + + // get row data + $em = $this->getDoctrine()->getManager(); + $row = $em->getRepository(Role::class)->find($id); + + if (!empty($row)) { + // delete this row + $em->remove($row); + $em->flush(); + } else { + throw $this->createNotFoundException('The item does not exist'); + } + } +} diff --git a/templates/role/list.html.twig b/templates/role/list.html.twig new file mode 100644 index 00000000..658889ff --- /dev/null +++ b/templates/role/list.html.twig @@ -0,0 +1,129 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

+ Roles +

+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+ + + + +
+
+
+
+ +
+
+ +
+ +
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} \ No newline at end of file