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/SubTicketTypeController.php b/src/Controller/SubTicketTypeController.php new file mode 100644 index 00000000..55e73292 --- /dev/null +++ b/src/Controller/SubTicketTypeController.php @@ -0,0 +1,276 @@ +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, $em); + + // 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, $em); + + // 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, 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')) + ->setTicketType($ttype); + } + + 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/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/Controller/TicketTypeController.php b/src/Controller/TicketTypeController.php new file mode 100644 index 00000000..4381d83d --- /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="ticket_type_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/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/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/subticket-type/form.html.twig b/templates/subticket-type/form.html.twig new file mode 100644 index 00000000..80f2d59f --- /dev/null +++ b/templates/subticket-type/form.html.twig @@ -0,0 +1,150 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +