From 5840aba2a90d5233ad890e90f1178c817cc782dc Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 2 Jun 2022 06:44:51 +0000 Subject: [PATCH 1/5] Add list, create, update, delete for ticket types. #676 --- config/acl.yaml | 35 ++++ config/menu.yaml | 13 ++ config/routes/subticket_type.yaml | 35 ++++ config/routes/ticket_type.yaml | 35 ++++ src/Controller/TicketTypeController.php | 254 ++++++++++++++++++++++++ src/Entity/SubTicketType.php | 63 ++++++ src/Entity/TicketType.php | 45 +++++ templates/ticket-type/form.html.twig | 133 +++++++++++++ templates/ticket-type/list.html.twig | 146 ++++++++++++++ 9 files changed, 759 insertions(+) create mode 100644 config/routes/subticket_type.yaml create mode 100644 config/routes/ticket_type.yaml create mode 100644 src/Controller/TicketTypeController.php create mode 100644 src/Entity/SubTicketType.php create mode 100644 src/Entity/TicketType.php create mode 100644 templates/ticket-type/form.html.twig create mode 100644 templates/ticket-type/list.html.twig diff --git a/config/acl.yaml b/config/acl.yaml index fb623290..ee514ab5 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -518,3 +518,38 @@ access_keys: label: Update - id: dealer.delete label: Delete + + - id: database + label: Database Access + acls: + - id: database.menu + label: Menu + + - id: ticket_type + label: Ticket Type Access + acls: + - id: ticket_type.menu + label: Menu + - id: ticket_type.list + label: List + - id: ticket_type.add + label: Add + - id: ticket_type.update + label: Update + - id: ticket_type.delete + label: Delete + + - id: subticket_type + label: Sub Ticket Type Access + acls: + - id: subticket_type.menu + label: Menu + - id: subticket_type.list + label: List + - id: subticket_type.add + label: Add + - id: subticket_type.update + label: Update + - id: subticket_type.delete + label: Delete + diff --git a/config/menu.yaml b/config/menu.yaml index fc4751fb..f80daadd 100644 --- a/config/menu.yaml +++ b/config/menu.yaml @@ -224,3 +224,16 @@ main_menu: acl: analytics.forecast label: Forecasting parent: analytics + + - id: database + acl: database.menu + label: Database + icon: fa fa-database + - id: ticket_type_list + acl: ticket_type.menu + label: Ticket Types + parent: database + - id: subticket_type_list + acl: subticket_type.menu + label: Sub Ticket Types + parent: database diff --git a/config/routes/subticket_type.yaml b/config/routes/subticket_type.yaml new file mode 100644 index 00000000..fbd80e82 --- /dev/null +++ b/config/routes/subticket_type.yaml @@ -0,0 +1,35 @@ +subticket_type_list: + path: /subticket-types + controller: App\Controller\SubTicketTypeController::index + methods: [GET] + +subticket_type_rows: + path: /subticket-types/rowdata + controller: App\Controller\SubTicketTypeController::datatableRows + methods: [POST] + +subticket_type_add_form: + path: /subticket-types/newform + controller: App\Controller\SubTicketTypeController::addForm + methods: [GET] + +subticket_type_add_submit: + path: /subticket-types + controller: App\Controller\SubTicketTypeController::addSubmit + methods: [POST] + +subticket_type_update_form: + path: /subticket-types/{id} + controller: App\Controller\SubTicketTypeController::updateForm + methods: [GET] + +subticket_type_update_submit: + path: /subticket-types/{id} + controller: App\Controller\SubTicketTypeController::updateSubmit + methods: [POST] + +subticket_type_delete: + path: /subticket-types/{id} + controller: App\Controller\SubTicketTypeController::deleteSubmit + methods: [DELETE] + diff --git a/config/routes/ticket_type.yaml b/config/routes/ticket_type.yaml new file mode 100644 index 00000000..86544069 --- /dev/null +++ b/config/routes/ticket_type.yaml @@ -0,0 +1,35 @@ +ticket_type_list: + path: /ticket-types + controller: App\Controller\TicketTypeController::index + methods: [GET] + +ticket_type_rows: + path: /ticket-types/rowdata + controller: App\Controller\TicketTypeController::datatableRows + methods: [POST] + +ticket_type_add_form: + path: /ticket-types/newform + controller: App\Controller\TicketTypeController::addForm + methods: [GET] + +ticket_type_add_submit: + path: /ticket-types + controller: App\Controller\TicketTypeController::addSubmit + methods: [POST] + +ticket_type_update_form: + path: /ticket-types/{id} + controller: App\Controller\TicketTypeController::updateForm + methods: [GET] + +ticket_type_update_submit: + path: /ticket-types/{id} + controller: App\Controller\TicketTypeController::updateSubmit + methods: [POST] + +ticket_type_delete: + path: /ticket-types/{id} + controller: App\Controller\TicketTypeController::deleteSubmit + methods: [DELETE] + diff --git a/src/Controller/TicketTypeController.php b/src/Controller/TicketTypeController.php new file mode 100644 index 00000000..3023420b --- /dev/null +++ b/src/Controller/TicketTypeController.php @@ -0,0 +1,254 @@ +denyAccessUnlessGranted('ticket_type.list', null, 'No access.'); + + return $this->render('ticket-type/list.html.twig'); + } + + /** + * @IsGranted("ticket_type.list") + */ + public function datatableRows(Request $req) + { + // get query builder + $qb = $this->getDoctrine() + ->getRepository(TicketType::class) + ->createQueryBuilder('q'); + + // get datatable params + $datatable = $req->request->get('datatable'); + + // count total records + $tquery = $qb->select('COUNT(q)'); + $this->setQueryFilters($datatable, $tquery); + $total = $tquery->getQuery() + ->getSingleScalarResult(); + + // get current page number + $page = $datatable['pagination']['page'] ?? 1; + + $perpage = $datatable['pagination']['perpage']; + $offset = ($page - 1) * $perpage; + + // add metadata + $meta = [ + 'page' => $page, + 'perpage' => $perpage, + 'pages' => ceil($total / $perpage), + 'total' => $total, + 'sort' => 'asc', + 'field' => 'id' + ]; + + // build query + $query = $qb->select('q'); + $this->setQueryFilters($datatable, $query); + + // check if sorting is present, otherwise use default + if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) { + $order = $datatable['sort']['sort'] ?? 'asc'; + $query->orderBy('q.' . $datatable['sort']['field'], $order); + } else { + $query->orderBy('q.id', 'asc'); + } + + // get rows for this page + $obj_rows = $query->setFirstResult($offset) + ->setMaxResults($perpage) + ->getQuery() + ->getResult(); + + // process rows + $rows = []; + foreach ($obj_rows as $orow) { + // add row data + $row['id'] = $orow->getID(); + $row['name'] = $orow->getName(); + + // add row metadata + $row['meta'] = [ + 'update_url' => '', + 'delete_url' => '' + ]; + + // add crud urls + if ($this->isGranted('ticket_type.update')) + $row['meta']['update_url'] = $this->generateUrl('ticket_type_update_form', ['id' => $row['id']]); + if ($this->isGranted('ticket_type.delete')) + $row['meta']['delete_url'] = $this->generateUrl('ticket_type_delete', ['id' => $row['id']]); + + $rows[] = $row; + } + + // response + return $this->json([ + 'meta' => $meta, + 'data' => $rows + ]); + } + + /** + * @Menu(selected="ticket_type.list") + * @IsGranted("ticket_type.add") + */ + public function addForm() + { + $ticket_type = new TicketType(); + $params = [ + 'ticket_type' => $ticket_type, + 'mode' => 'create', + ]; + + // response + return $this->render('ticket-type/form.html.twig', $params); + } + + /** + * @IsGranted("ticket_type.add") + */ + public function addSubmit(Request $req, EntityManagerInterface $em, ValidatorInterface $validator) + { + $ticket_type = new TicketType(); + + $this->setObject($ticket_type, $req); + + // validate + $errors = $validator->validate($ticket_type); + + // initialize error list + $error_array = []; + + // add errors to list + foreach ($errors as $error) { + $error_array[$error->getPropertyPath()] = $error->getMessage(); + } + + // check if any errors were found + if (!empty($error_array)) { + // return validation failure response + return $this->json([ + 'success' => false, + 'errors' => $error_array + ], 422); + } + + // validated! save the entity + $em->persist($ticket_type); + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + + } + + /** + * @Menu(selected="dealer_list") + * @ParamConverter("ticket_type", class="App\Entity\TicketType") + * @IsGranted("ticket_type.update") + */ + public function updateForm($id, EntityManagerInterface $em, TicketType $ticket_type) + { + $params = []; + $params['ticket_type'] = $ticket_type; + $params['mode'] = 'update'; + + // response + return $this->render('ticket-type/form.html.twig', $params); + } + + /** + * @ParamConverter("ticket_type", class="App\Entity\TicketType") + * @IsGranted("ticket_type.update") + */ + public function updateSubmit(Request $req, EntityManagerInterface $em, ValidatorInterface $validator, TicketType $ticket_type) + { + $this->setObject($ticket_type, $req); + + // validate + $errors = $validator->validate($ticket_type); + + // initialize error list + $error_array = []; + + // add errors to list + foreach ($errors as $error) { + $error_array[$error->getPropertyPath()] = $error->getMessage(); + } + + // check if any errors were found + if (!empty($error_array)) { + // return validation failure response + return $this->json([ + 'success' => false, + 'errors' => $error_array + ], 422); + } + + // validated! save the entity + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + + /** + * @ParamConverter("ticket_type", class="App\Entity\TicketType") + * @IsGranted("ticket_type.update") + */ + public function deleteSubmit(EntityManagerInterface $em, TicketType $ticket_type) + { + // delete this object + $em->remove($ticket_type); + $em->flush(); + + // response + $response = new Response(); + $response->setStatusCode(Response::HTTP_OK); + $response->send(); + } + + + protected function setObject(TicketType $obj, Request $req) + { + // set and save values + $obj->setName($req->request->get('name')); + } + + protected function setQueryFilters($datatable, QueryBuilder $query) + { + if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) { + $query->where('q.name LIKE :filter') + ->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%'); + } + } + +} diff --git a/src/Entity/SubTicketType.php b/src/Entity/SubTicketType.php new file mode 100644 index 00000000..d992e414 --- /dev/null +++ b/src/Entity/SubTicketType.php @@ -0,0 +1,63 @@ +id; + } + + public function setName($name) + { + $this->name = $name; + return $this; + } + + public function getName() + { + return $this->name; + } + + public function setTicketType(TicketType $ticket_type) + { + $this->ticket_type = $ticket_type; + return $this; + } + + public function getTicketType() + { + return $this->ticket_type; + } +} diff --git a/src/Entity/TicketType.php b/src/Entity/TicketType.php new file mode 100644 index 00000000..b52ebb73 --- /dev/null +++ b/src/Entity/TicketType.php @@ -0,0 +1,45 @@ +id; + } + + public function setName($name) + { + $this->name = $name; + return $this; + } + + public function getName() + { + return $this->name; + } +} diff --git a/templates/ticket-type/form.html.twig b/templates/ticket-type/form.html.twig new file mode 100644 index 00000000..4f3cce8d --- /dev/null +++ b/templates/ticket-type/form.html.twig @@ -0,0 +1,133 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

Ticket Types

+
+
+
+ +
+ +
+
+
+
+
+
+ + + +

+ {% if mode == 'update' %} + Edit Ticket Type + {{ ticket_type.getName() }} + {% else %} + New Ticket Type + {% endif %} +

+
+
+
+
+
+
+ +
+ + +
+
+
+
+
+
+
+ + Back +
+
+
+
+
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} diff --git a/templates/ticket-type/list.html.twig b/templates/ticket-type/list.html.twig new file mode 100644 index 00000000..8b61946c --- /dev/null +++ b/templates/ticket-type/list.html.twig @@ -0,0 +1,146 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

+ Ticket Types +

+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+ + + + +
+
+
+
+ +
+
+ +
+ +
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} -- 2.43.5 From efd402acb144c53cce4042d92c1624e8742fe3d7 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 2 Jun 2022 07:18:37 +0000 Subject: [PATCH 2/5] Add list, create, update, delete for subticket type. #676 --- src/Controller/SubTicketTypeController.php | 271 +++++++++++++++++++++ src/Controller/TicketTypeController.php | 2 +- templates/subticket-type/form.html.twig | 150 ++++++++++++ templates/subticket-type/list.html.twig | 146 +++++++++++ 4 files changed, 568 insertions(+), 1 deletion(-) create mode 100644 src/Controller/SubTicketTypeController.php create mode 100644 templates/subticket-type/form.html.twig create mode 100644 templates/subticket-type/list.html.twig diff --git a/src/Controller/SubTicketTypeController.php b/src/Controller/SubTicketTypeController.php new file mode 100644 index 00000000..da1aead7 --- /dev/null +++ b/src/Controller/SubTicketTypeController.php @@ -0,0 +1,271 @@ +render('subticket-type/list.html.twig'); + } + + /** + * @IsGranted("subticket_type.list") + */ + public function datatableRows(Request $req) + { + // get query builder + $qb = $this->getDoctrine() + ->getRepository(SubTicketType::class) + ->createQueryBuilder('q'); + + // get datatable params + $datatable = $req->request->get('datatable'); + + // count total records + $tquery = $qb->select('COUNT(q)'); + $this->setQueryFilters($datatable, $tquery); + $total = $tquery->getQuery() + ->getSingleScalarResult(); + + // get current page number + $page = $datatable['pagination']['page'] ?? 1; + + $perpage = $datatable['pagination']['perpage']; + $offset = ($page - 1) * $perpage; + + // add metadata + $meta = [ + 'page' => $page, + 'perpage' => $perpage, + 'pages' => ceil($total / $perpage), + 'total' => $total, + 'sort' => 'asc', + 'field' => 'id' + ]; + + // build query + $query = $qb->select('q'); + $this->setQueryFilters($datatable, $query); + + // check if sorting is present, otherwise use default + if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) { + $order = $datatable['sort']['sort'] ?? 'asc'; + $query->orderBy('q.' . $datatable['sort']['field'], $order); + } else { + $query->orderBy('q.id', 'asc'); + } + + // get rows for this page + $obj_rows = $query->setFirstResult($offset) + ->setMaxResults($perpage) + ->getQuery() + ->getResult(); + + // process rows + $rows = []; + foreach ($obj_rows as $orow) { + // add row data + $row['id'] = $orow->getID(); + $row['name'] = $orow->getName(); + + // add row metadata + $row['meta'] = [ + 'update_url' => '', + 'delete_url' => '' + ]; + + // add crud urls + if ($this->isGranted('subticket_type.update')) + $row['meta']['update_url'] = $this->generateUrl('subticket_type_update_form', ['id' => $row['id']]); + if ($this->isGranted('subticket_type.delete')) + $row['meta']['delete_url'] = $this->generateUrl('subticket_type_delete', ['id' => $row['id']]); + + $rows[] = $row; + } + + // response + return $this->json([ + 'meta' => $meta, + 'data' => $rows + ]); + } + + /** + * @Menu(selected="subticket_type.list") + * @IsGranted("subticket_type.add") + */ + public function addForm(EntityManagerInterface $em) + { + $subticket_type = new SubTicketType(); + + $params = [ + 'subticket_type' => $subticket_type, + 'mode' => 'create', + 'sets' => $this->generateFormSets($em), + ]; + + // response + return $this->render('subticket-type/form.html.twig', $params); + } + + /** + * @IsGranted("subticket_type.add") + */ + public function addSubmit(Request $req, EntityManagerInterface $em, ValidatorInterface $validator) + { + $subticket_type = new SubTicketType(); + + $this->setObject($subticket_type, $req); + + // validate + $errors = $validator->validate($subticket_type); + + // initialize error list + $error_array = []; + + // add errors to list + foreach ($errors as $error) { + $error_array[$error->getPropertyPath()] = $error->getMessage(); + } + + // check if any errors were found + if (!empty($error_array)) { + // return validation failure response + return $this->json([ + 'success' => false, + 'errors' => $error_array + ], 422); + } + + // validated! save the entity + $em->persist($subticket_type); + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + + } + + /** + * @Menu(selected="subticket_type_list") + * @ParamConverter("subticket_type", class="App\Entity\SubTicketType") + * @IsGranted("subticket_type.update") + */ + public function updateForm($id, EntityManagerInterface $em, SubTicketType $subticket_type) + { + $params = [ + 'subticket_type' => $subticket_type, + 'mode' => 'update', + 'sets' => $this->generateFormSets($em), + ]; + + // response + return $this->render('subticket-type/form.html.twig', $params); + } + + /** + * @ParamConverter("subticket_type", class="App\Entity\SubTicketType") + * @IsGranted("subticket_type.update") + */ + public function updateSubmit(Request $req, EntityManagerInterface $em, ValidatorInterface $validator, SubTicketType $subticket_type) + { + $this->setObject($subticket_type, $req); + + // validate + $errors = $validator->validate($subticket_type); + + // initialize error list + $error_array = []; + + // add errors to list + foreach ($errors as $error) { + $error_array[$error->getPropertyPath()] = $error->getMessage(); + } + + // check if any errors were found + if (!empty($error_array)) { + // return validation failure response + return $this->json([ + 'success' => false, + 'errors' => $error_array + ], 422); + } + + // validated! save the entity + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + + /** + * @ParamConverter("subticket_type", class="App\Entity\SubTicketType") + * @IsGranted("subticket_type.update") + */ + public function deleteSubmit(EntityManagerInterface $em, SubTicketType $subticket_type) + { + // delete this object + $em->remove($subticket_type); + $em->flush(); + + // response + $response = new Response(); + $response->setStatusCode(Response::HTTP_OK); + $response->send(); + } + + protected function setObject(SubTicketType $obj, Request $req) + { + // set and save values + $obj->setName($req->request->get('name')); + } + + protected function generateFormSets(EntityManagerInterface $em) + { + // get ticket types + $ttypes = $em->getRepository(TicketType::class)->findBy([], ['name' => 'asc']); + $ttypes_set = []; + foreach ($ttypes as $ttype) + { + $ttypes_set[$ttype->getID()] = $ttype->getName(); + } + + return [ + 'ticket_types' => $ttypes_set, + ]; + } + + protected function setQueryFilters($datatable, QueryBuilder $query) + { + if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) { + $query->where('q.name LIKE :filter') + ->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%'); + } + } + +} diff --git a/src/Controller/TicketTypeController.php b/src/Controller/TicketTypeController.php index 3023420b..4381d83d 100644 --- a/src/Controller/TicketTypeController.php +++ b/src/Controller/TicketTypeController.php @@ -169,7 +169,7 @@ class TicketTypeController extends Controller } /** - * @Menu(selected="dealer_list") + * @Menu(selected="ticket_type_list") * @ParamConverter("ticket_type", class="App\Entity\TicketType") * @IsGranted("ticket_type.update") */ diff --git a/templates/subticket-type/form.html.twig b/templates/subticket-type/form.html.twig new file mode 100644 index 00000000..31b688cc --- /dev/null +++ b/templates/subticket-type/form.html.twig @@ -0,0 +1,150 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

Sub Ticket Types

+
+
+
+ +
+ +
+
+
+
+
+
+ + + +

+ {% if mode == 'update' %} + Edit Sub Ticket Type + {{ subticket_type.getName() }} + {% else %} + New Sub Ticket Type + {% endif %} +

+
+
+
+
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+
+
+
+
+ + Back +
+
+
+
+
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} diff --git a/templates/subticket-type/list.html.twig b/templates/subticket-type/list.html.twig new file mode 100644 index 00000000..656878cd --- /dev/null +++ b/templates/subticket-type/list.html.twig @@ -0,0 +1,146 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

+ Sub Ticket Types +

+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+ + + + +
+
+
+
+ +
+
+ +
+ +
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} -- 2.43.5 From 96ce1f81faf736b87df514a92f3e03966cb3ef14 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 2 Jun 2022 13:12:23 +0000 Subject: [PATCH 3/5] Add saving of ticket type for subticket type. #676 --- src/Controller/SubTicketTypeController.php | 13 +++++++++---- templates/subticket-type/form.html.twig | 10 +++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Controller/SubTicketTypeController.php b/src/Controller/SubTicketTypeController.php index da1aead7..55e73292 100644 --- a/src/Controller/SubTicketTypeController.php +++ b/src/Controller/SubTicketTypeController.php @@ -136,7 +136,7 @@ class SubTicketTypeController extends Controller { $subticket_type = new SubTicketType(); - $this->setObject($subticket_type, $req); + $this->setObject($subticket_type, $req, $em); // validate $errors = $validator->validate($subticket_type); @@ -192,7 +192,7 @@ class SubTicketTypeController extends Controller */ public function updateSubmit(Request $req, EntityManagerInterface $em, ValidatorInterface $validator, SubTicketType $subticket_type) { - $this->setObject($subticket_type, $req); + $this->setObject($subticket_type, $req, $em); // validate $errors = $validator->validate($subticket_type); @@ -239,10 +239,15 @@ class SubTicketTypeController extends Controller $response->send(); } - protected function setObject(SubTicketType $obj, Request $req) + protected function setObject(SubTicketType $obj, Request $req, EntityManagerInterface $em) { + // get the ticket type id + $ttype_id = $req->request->get('ticket_type_id', 0); + $ttype = $em->getRepository(TicketType::class)->find($ttype_id); + // set and save values - $obj->setName($req->request->get('name')); + $obj->setName($req->request->get('name')) + ->setTicketType($ttype); } protected function generateFormSets(EntityManagerInterface $em) diff --git a/templates/subticket-type/form.html.twig b/templates/subticket-type/form.html.twig index 31b688cc..80f2d59f 100644 --- a/templates/subticket-type/form.html.twig +++ b/templates/subticket-type/form.html.twig @@ -34,7 +34,7 @@
-
+
@@ -48,16 +48,16 @@ Ticket Type:
- {% for id, label in sets.ticket_types %} - {% if (id == "{{ subticket.getID() }}") %} - + {% if subticket_type.getTicketType %} + {% else %} {% endif %} {% endfor %} - +
-- 2.43.5 From d89f67bc768976fe34dbd0ed48a9b94a7f0caaf9 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 3 Jun 2022 08:34:16 +0000 Subject: [PATCH 4/5] Add the new ticket fields into the ticket form. #676 --- src/Controller/TicketController.php | 116 +++-- src/Entity/Ticket.php | 44 +- templates/ticket/form.html.twig | 645 +++++++++++++++------------- 3 files changed, 480 insertions(+), 325 deletions(-) diff --git a/src/Controller/TicketController.php b/src/Controller/TicketController.php index 0f9f3cd9..7c18ee6f 100644 --- a/src/Controller/TicketController.php +++ b/src/Controller/TicketController.php @@ -9,8 +9,11 @@ use App\Ramcar\SourceOfAwareness; use App\Entity\Ticket; use App\Entity\Customer; use App\Entity\JobOrder; +use App\Entity\TicketType as NewTicketType; +use App\Entity\SubTicketType; use Doctrine\ORM\Query; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Validator\Validator\ValidatorInterface; @@ -128,7 +131,7 @@ class TicketController extends Controller /** * @Menu(selected="ticket_list") */ - public function addForm(Request $req, $customer_id, $job_order_id) + public function addForm(Request $req, EntityManagerInterface $em, $customer_id, $job_order_id) { $this->denyAccessUnlessGranted('ticket.add', null, 'No access.'); @@ -140,7 +143,6 @@ class TicketController extends Controller // get customer data if ($customer_id) { - $em = $this->getDoctrine()->getManager(); $customer = $em->getRepository(Customer::class)->find($customer_id); // make sure this row exists @@ -176,6 +178,8 @@ class TicketController extends Controller $params['redirect_url'] = $this->generateUrl('ticket_list'); $params['soa_types'] = SourceOfAwareness::getCollection(); + $params['sets'] = $this->generateFormSets($em); + // set redirect url if ($customer) { @@ -236,12 +240,16 @@ class TicketController extends Controller $obj = new Ticket(); // get ticket type - $ticket_type = $req->request->get('ticket_type'); - $other_ticket_type = ''; + //$ticket_type = $req->request->get('ticket_type'); + //$other_ticket_type = ''; - if ($ticket_type == TicketType::OTHER) { - $other_ticket_type = $req->request->get('other_ticket_type'); - } + //if ($ticket_type == TicketType::OTHER) { + // $other_ticket_type = $req->request->get('other_ticket_type'); + //} + + // get the "new" ticket type + $ttype_id = $req->request->get('new_ticket_type'); + $sub_ttype_id = $req->request->get('sub_ticket_type'); // get source of awareness if any $soa_type = $req->request->get('source_of_awareness'); @@ -254,8 +262,8 @@ class TicketController extends Controller ->setLastName($last_name) ->setContactNumber($contact_num) ->setStatus($req->request->get('status')) - ->setTicketType($ticket_type) - ->setOtherTicketType($other_ticket_type) + //->setTicketType($ticket_type) + //->setOtherTicketType($other_ticket_type) ->setDetails($req->request->get('details')) ->setPlateNumber($req->request->get('plate_number')) ->setDateCreate(new DateTime()) @@ -280,9 +288,21 @@ class TicketController extends Controller $errors = $validator->validate($obj); // custom validation for other ticket type - if ($ticket_type == TicketType::OTHER && empty($other_ticket_type)) { - $error_array['other_ticket_type'] = 'Ticket type not specified.'; - } + //if ($ticket_type == TicketType::OTHER && empty($other_ticket_type)) { + // $error_array['other_ticket_type'] = 'Ticket type not specified.'; + //} + // get ticket and sub ticket type objects + $ttype = $em->getRepository(NewTicketType::class)->find($ttype_id); + if (empty($ttype)) + $error_array['new_ticket_type'] = 'Ticket type not specified.'; + + $sub_ttype = $em->getRepository(SubTicketType::class)->find($sub_ttype_id); + if (empty($sub_ttype)) + $error_array['sub_ticket_type'] = 'Sub ticket type not specified.'; + + // set the ticket type and sub ticket type for ticket + $obj->setNewTicketType($ttype) + ->setSubTicketType($sub_ttype); // add errors to list foreach ($errors as $error) { @@ -311,22 +331,19 @@ class TicketController extends Controller /** * @Menu(selected="ticket_list") */ - public function updateForm(Request $req, $id) + public function updateForm(Request $req, $id, EntityManagerInterface $em) { $this->denyAccessUnlessGranted('ticket.update', null, 'No access.'); $params['mode'] = 'update'; // get row data - $em = $this->getDoctrine()->getManager(); $obj = $em->getRepository(Ticket::class)->find($id); // make sure this row exists if (empty($obj)) throw $this->createNotFoundException('The item does not exist'); - // $em = $this->getDoctrine()->getManager(); - $customer = $obj->getCustomer(); $job_order = $obj->getJobOrder(); @@ -339,6 +356,8 @@ class TicketController extends Controller $params['redirect_url'] = $this->generateUrl('ticket_list'); $params['soa_types'] = SourceOfAwareness::getCollection(); + $params['sets'] = $this->generateFormSets($em); + // set redirect url if ($customer) { @@ -428,12 +447,16 @@ class TicketController extends Controller } // get ticket type - $ticket_type = $req->request->get('ticket_type'); - $other_ticket_type = ''; + //$ticket_type = $req->request->get('ticket_type'); + //$other_ticket_type = ''; - if ($ticket_type == TicketType::OTHER) { - $other_ticket_type = $req->request->get('other_ticket_type'); - } + //if ($ticket_type == TicketType::OTHER) { + // $other_ticket_type = $req->request->get('other_ticket_type'); + //} + + // get the "new" ticket type + $ttype_id = $req->request->get('new_ticket_type'); + $sub_ttype_id = $req->request->get('sub_ticket_type'); // get source of awareness if any $soa_type = $req->request->get('source_of_awareness'); @@ -446,8 +469,8 @@ class TicketController extends Controller ->setLastName($last_name) ->setContactNumber($contact_num) ->setStatus($req->request->get('status')) - ->setTicketType($ticket_type) - ->setOtherTicketType($other_ticket_type) + //->setTicketType($ticket_type) + //->setOtherTicketType($other_ticket_type) ->setDetails($req->request->get('details')) ->setPlateNumber($req->request->get('plate_number')) ->setSourceOfAwareness($soa_type) @@ -460,9 +483,21 @@ class TicketController extends Controller $errors = $validator->validate($obj); // custom validation for other ticket type - if ($ticket_type == TicketType::OTHER && empty($other_ticket_type)) { - $error_array['other_ticket_type'] = 'Ticket type not specified.'; - } + //if ($ticket_type == TicketType::OTHER && empty($other_ticket_type)) { + // $error_array['other_ticket_type'] = 'Ticket type not specified.'; + //} + // get ticket and sub ticket type objects + $ttype = $em->getRepository(NewTicketType::class)->find($ttype_id); + if (empty($ttype)) + $error_array['new_ticket_type'] = 'Ticket type not specified.'; + + $sub_ttype = $em->getRepository(SubTicketType::class)->find($sub_ttype_id); + if (empty($sub_ttype)) + $error_array['sub_ticket_type'] = 'Sub ticket type not specified.'; + + // set the ticket type and sub ticket type for ticket + $obj->setNewTicketType($ttype) + ->setSubTicketType($sub_ttype); // add errors to list foreach ($errors as $error) { @@ -508,6 +543,35 @@ class TicketController extends Controller $response->send(); } + protected function generateFormSets(EntityManagerInterface $em) + { + // get ticket types + $ttypes = $em->getRepository(NewTicketType::class)->findBy([], ['name' => 'asc']); + $ttypes_set = []; + foreach ($ttypes as $ttype) + { + $ttypes_set[$ttype->getID()] = $ttype->getName(); + } + + // get sub ticket types + $sub_ttypes = $em->getRepository(SubTicketType::class)->findBy([], ['name' => 'asc']); + $sub_ttypes_set = []; + foreach ($sub_ttypes as $sub_ttype) + { + $sub_ttypes_set[] = [ + 'id' => $sub_ttype->getID(), + 'name' => $sub_ttype->getName(), + 'ticket_type_id' => $sub_ttype->getTicketType()->getID(), + ]; + } + + return [ + 'new_ticket_types' => $ttypes_set, + 'sub_ticket_types' => $sub_ttypes_set, + ]; + } + + // check if datatable filter is present and append to query protected function setQueryFilters($datatable, &$query, $qb) { if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) { diff --git a/src/Entity/Ticket.php b/src/Entity/Ticket.php index a3218c47..c8efee8f 100644 --- a/src/Entity/Ticket.php +++ b/src/Entity/Ticket.php @@ -2,7 +2,7 @@ namespace App\Entity; -use App\Ramcar\TicketType; +use App\Ramcar\TicketType as LegacyTicketType; use App\Ramcar\TicketStatus; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; @@ -44,8 +44,7 @@ class Ticket // ticket type /** - * @ORM\Column(type="string", length=15) - * @Assert\NotBlank() + * @ORM\Column(type="string", length=15, nullable=true) */ protected $ticket_type; @@ -120,6 +119,20 @@ class Ticket */ protected $remarks; + // new ticket type + /** + * @ORM\ManyToOne(targetEntity="TicketType", inversedBy="tickets") + * @ORM\JoinColumn(name="ticket_type_id", referencedColumnName="id", nullable=true) + */ + protected $new_ticket_type; + + // sub ticket type + /** + * @ORM\ManyToOne(targetEntity="SubTicketType", inversedBy="subtickets") + * @ORM\JoinColumn(name="subticket_type_id", referencedColumnName="id", nullable=true) + */ + protected $subticket_type; + public function __construct() { $this->date_create = new DateTime(); @@ -182,10 +195,10 @@ class Ticket public function getTicketTypeText() { - if ($this->ticket_type == TicketType::OTHER) { + if ($this->ticket_type == LegacyTicketType::OTHER) { return $this->other_ticket_type; } else { - $types = TicketType::getCollection(); + $types = LegacyTicketType::getCollection(); return $types[$this->ticket_type] ?? ""; } } @@ -300,4 +313,25 @@ class Ticket return $this->remarks; } + public function setNewTicketType(TicketType $new_ticket_type = null) + { + $this->new_ticket_type = $new_ticket_type; + return $this; + } + + public function getNewTicketType() + { + return $this->new_ticket_type; + } + + public function setSubTicketType(SubTicketType $subticket_type = null) + { + $this->subticket_type = $subticket_type; + return $this; + } + + public function getSubTicketType() + { + return $this->subticket_type; + } } diff --git a/templates/ticket/form.html.twig b/templates/ticket/form.html.twig index 2196e790..da0bca86 100644 --- a/templates/ticket/form.html.twig +++ b/templates/ticket/form.html.twig @@ -1,321 +1,378 @@ {% extends 'base.html.twig' %} {% block body %} - -
-
-
-

Tickets

+ +
+
+
+

Tickets

+
+
+
+ +
+ +
+
+
+
+
+
+ + + +

+ {% if mode == 'update' %} + Edit Ticket + {{ obj.getID }} + {% else %} + New Ticket + {% if customer %} + for {{ customer.getFirstName ~ " " ~ customer.getLastName }} + {% endif %} + {% endif %} +

+
+
+
+ +
+
+ {% if (mode == 'update') and (obj.getTicketType != null) %} +
+
+ + + +
+
+ + + +
+
+ {% endif %} +
+
+ + + +
+
+ + + +
+
+
+
+ + + +
+
+ + + +
+
+
+
+ +
+ {% trans %}country_code_prefix{% endtrans %} + + +
+
+
+
+
+ + + +
+
+
+
+ + + +
+
+
+
+ + + +
+
+
+
+ + + +
+
+
+
+ + + +
+
+
+
+ + + +
+ {% if job_order %} +
+ + +
+ {% endif %} +
+
+ + {% if mode == 'update' %} +
+
+
+

+ Related Tickets +

+
+
+
+ +
+
+
+ {% endif %} +
+
+
+
+
+ + Back +
+
+
+
+
- -
- -
-
-
-
-
-
- - - -

- {% if mode == 'update' %} - Edit Ticket - {{ obj.getID }} - {% else %} - New Ticket - {% if customer %} - for {{ customer.getFirstName ~ " " ~ customer.getLastName }} - {% endif %} - {% endif %} -

-
-
-
-
-
-
-
-
- - - -
-
- - - -
-
-
-
- - - -
-
- - - -
-
-
-
- -
- {% trans %}country_code_prefix{% endtrans %} - - -
-
-
-
-
- - - -
-
-
-
- - - -
-
-
-
- - - -
-
-
-
- - - -
-
-
-
- - - -
-
-
-
- - - -
- {% if job_order %} -
- - -
- {% endif %} -
-
- - {% if mode == 'update' %} -
-
-
-

- Related Tickets -

-
-
-
- -
-
-
- {% endif %} -
-
-
-
-
- - Back -
-
-
-
-
-
-
-
-
+
{% endblock %} {% block scripts %} - + var ticketTable = $("#data-related-tickets").mDatatable(ticketOptions); + {% endif %} +}); + +var subticket_type_list = {{ sets.sub_ticket_types|json_encode|raw }}; + +// populate sub ticket type field +$('form').on('change', '#new-ticket-type', function() { + console.log('ticket type change'); + var ticket_type_id = $(this).val(); + + // build options for sub ticket type based on selected ticket type + var options = ''; + for (var i in subticket_type_list) { + if (subticket_type_list[i].ticket_type_id == ticket_type_id) { + options += '' + } + } + + $('#sub-ticket-type').html(options); +}); + + {% endblock %} -- 2.43.5 From 3b80fee75fd068f15a1575b02e85abfb14b1c0ec Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 3 Jun 2022 09:55:44 +0000 Subject: [PATCH 5/5] Add mysqldumps for ticket types and subticket types. #676 --- utils/ticket_types/subticket_type.sql | 54 +++++++++++++++++++++++++++ utils/ticket_types/ticket_type.sql | 51 +++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 utils/ticket_types/subticket_type.sql create mode 100644 utils/ticket_types/ticket_type.sql diff --git a/utils/ticket_types/subticket_type.sql b/utils/ticket_types/subticket_type.sql new file mode 100644 index 00000000..2369e98d --- /dev/null +++ b/utils/ticket_types/subticket_type.sql @@ -0,0 +1,54 @@ +-- MySQL dump 10.19 Distrib 10.3.32-MariaDB, for Linux (x86_64) +-- +-- Host: localhost Database: resq +-- ------------------------------------------------------ +-- Server version 10.3.32-MariaDB + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `subticket_type` +-- + +DROP TABLE IF EXISTS `subticket_type`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `subticket_type` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `ticket_type_id` int(11) DEFAULT NULL, + `name` varchar(80) COLLATE utf8_unicode_ci NOT NULL, + PRIMARY KEY (`id`), + KEY `IDX_F18521A4C980D5C1` (`ticket_type_id`), + CONSTRAINT `FK_F18521A4C980D5C1` FOREIGN KEY (`ticket_type_id`) REFERENCES `ticket_type` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=38 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `subticket_type` +-- + +LOCK TABLES `subticket_type` WRITE; +/*!40000 ALTER TABLE `subticket_type` DISABLE KEYS */; +INSERT INTO `subticket_type` VALUES (1,1,'Hub / Distributor'),(2,1,'Rider / Technician'),(3,1,'Service Procedure (Incomplete Document/s)'),(4,1,'Agent'),(5,1,'Wrong Battery'),(6,2,'Delivery Time'),(7,2,'Line Up Status'),(8,2,'Recharged / Replacement Battery'),(9,3,'Battery Brand'),(10,3,'Battery Life Span'),(11,3,'Battery Price and Trade-in'),(12,3,'Battery Specifications'),(13,3,'Battery Warranty'),(14,3,'Call Out Request'),(15,3,'Dealership'),(16,3,'Distributor Call'),(17,3,'For Generator Set (GenSet)'),(18,3,'Grab'),(19,3,'Mode of Payment'),(20,3,'Motorcycle Batteries'),(21,3,'Operating Hours'),(22,3,'Outlet nearby details (Province)'),(23,3,'Pezza or EWT'),(24,3,'Promo or Discount'),(25,3,'PVC'),(26,3,'ResQ Services and Fee'),(27,3,'Service Fee'),(28,3,'Serviceable Area'),(29,3,'Shell'),(30,3,'VAT Exempt'),(31,3,'Warranty Claim / Procedures'),(32,3,'Test Call'),(33,4,'Ghost Call'),(34,4,'Line Cut'),(35,4,'System Problem'),(36,4,'Transferred Calls'),(37,4,'VPN Down'); +/*!40000 ALTER TABLE `subticket_type` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2022-06-03 9:53:08 diff --git a/utils/ticket_types/ticket_type.sql b/utils/ticket_types/ticket_type.sql new file mode 100644 index 00000000..137b7042 --- /dev/null +++ b/utils/ticket_types/ticket_type.sql @@ -0,0 +1,51 @@ +-- MySQL dump 10.19 Distrib 10.3.32-MariaDB, for Linux (x86_64) +-- +-- Host: localhost Database: resq +-- ------------------------------------------------------ +-- Server version 10.3.32-MariaDB + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `ticket_type` +-- + +DROP TABLE IF EXISTS `ticket_type`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `ticket_type` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(25) COLLATE utf8_unicode_ci NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `ticket_type` +-- + +LOCK TABLES `ticket_type` WRITE; +/*!40000 ALTER TABLE `ticket_type` DISABLE KEYS */; +INSERT INTO `ticket_type` VALUES (1,'Complaint'),(2,'Follow up'),(3,'Inquiry'),(4,'Others'); +/*!40000 ALTER TABLE `ticket_type` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2022-06-03 9:52:51 -- 2.43.5