diff --git a/config/acl.yaml b/config/acl.yaml index abd73118..e4fcc744 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -429,3 +429,11 @@ access_keys: - id: analytics.forecast label: Forecasting + - id: notifications + label: Notifications + acls: + - id: notification.menu + label: Menu + - id: notification.list + label: List + diff --git a/config/menu.yaml b/config/menu.yaml index 9f28b315..0310fc36 100644 --- a/config/menu.yaml +++ b/config/menu.yaml @@ -177,3 +177,12 @@ main_menu: acl: review.list label: Reviews parent: partner + + - id: notification + acl: notification.menu + label: Notifications + icon: flaticon-bell + - id: notification_list + acl: notification.list + label: Notifications + parent: notification diff --git a/config/routes/notification.yaml b/config/routes/notification.yaml new file mode 100644 index 00000000..b61f6a64 --- /dev/null +++ b/config/routes/notification.yaml @@ -0,0 +1,8 @@ +notification_list: + path: /notifications + controller: App\Controller\NotificationController::index + +notification_rows: + path: /notifications/rows + controller: App\Controller\NotificationController::rows + methods: [POST] diff --git a/src/Controller/NotificationController.php b/src/Controller/NotificationController.php new file mode 100644 index 00000000..4b55916b --- /dev/null +++ b/src/Controller/NotificationController.php @@ -0,0 +1,100 @@ +denyAccessUnlessGranted('notification.list', null, 'No access.'); + + return $this->render('notification/list.html.twig'); + } + + public function rows(Request $req) + { + $this->denyAccessUnlessGranted('notification.list', null, 'No access.'); + + // get current user + $user = $this->getUser(); + + // build query + $qb = $this->getDoctrine() + ->getRepository(Notification::class) + ->createQueryBuilder('q'); + + // get datatable params + $datatable = $req->request->get('datatable'); + + // count total records + $tquery = $qb->select('COUNT(q)'); + + // find by user + $tquery->andWhere('q.user = :user') + ->setParameter('user', $user); + + $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'); + + // find by user + $query->andWhere('q.user = :user') + ->setParameter('user', $user); + + // order by date_create desc + $query->orderBy('q.date_create', 'desc'); + + // 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['message'] = $orow->getMessage(); + $row['notif_type'] = $orow->getNotificationTypeName(); + + $rows[] = $row; + } + + // response + return $this->json([ + 'meta' => $meta, + 'data' => $rows + ]); + } +} diff --git a/src/Entity/Notification.php b/src/Entity/Notification.php index f24f967c..82a5d3a6 100644 --- a/src/Entity/Notification.php +++ b/src/Entity/Notification.php @@ -82,6 +82,17 @@ class Notification return $this->date_create; } + public function setMessage($message) + { + $this->message = $message; + return $this; + } + + public function getMessage() + { + return $this->message; + } + public function isNotificationRead() { return $this->flag_read; @@ -126,7 +137,7 @@ class Notification return $this->notif_type; } - public function getNotficationTypeName() + public function getNotificationTypeName() { return NotificationType::getName($this->notif_type); } diff --git a/src/Ramcar/NotificationType.php b/src/Ramcar/NotificationType.php index 3591fe90..630cda7b 100644 --- a/src/Ramcar/NotificationType.php +++ b/src/Ramcar/NotificationType.php @@ -4,11 +4,11 @@ namespace App\Ramcar; class NotificationType extends NameValue { - const CANCELLED = 'cancelled'; - const REJECTED = 'rejected'; + const CANCELLATION = 'cancellation'; + const REJECTION = 'rejection'; const COLLECTION = [ - 'cancelled' => 'Cancelled', - 'rejected' => 'Rejected', + 'cancellation' => 'Cancellation', + 'rejection' => 'Rejection', ]; } diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 83188826..bad04db8 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -1500,6 +1500,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface // get images if any $jo_extra = $obj->getJOExtra(); $pic_array = []; + $params['signature'] = null; if ($jo_extra != null) { $b_speed_img = $jo_extra->getBeforeSpeedImageFilename(); diff --git a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php index d0bbcdb5..72e1d5ac 100644 --- a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php +++ b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php @@ -3,6 +3,7 @@ namespace App\Service\RiderAPIHandler; use Doctrine\ORM\EntityManagerInterface; + use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface; @@ -14,6 +15,7 @@ use App\Ramcar\InvoiceStatus; use App\Ramcar\CMBModeOfPayment; use App\Ramcar\InvoiceCriteria; use App\Ramcar\CMBCancelReason; +use App\Ramcar\NotificationType; use App\Service\RiderAPIHandlerInterface; use App\Service\RedisClientProvider; @@ -33,6 +35,7 @@ use App\Entity\BatteryModel; use App\Entity\BatterySize; use App\Entity\JobOrder; use App\Entity\JOExtra; +use App\Entity\Notification; use DateTime; use DateInterval; @@ -886,6 +889,14 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface ->setRider($rider); $this->em->persist($event); + // add to notifications + $notif = new Notification(); + $notif->setJobOrder($jo) + ->setMessage($rider->getFullName() . ' cancelled Job Order# ' . $jo->getID()) + ->setNotificationType(NotificationType::CANCELLATION) + ->setUser($jo->getCreatedBy()); + $this->em->persist($notif); + $this->em->flush(); return $data; @@ -945,6 +956,14 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface ->setRider($rider); $this->em->persist($event); + // add to notifications + $notif = new Notification(); + $notif->setJobOrder($jo) + ->setMessage($rider->getFullName() . ' rejected Job Order# ' . $jo->getID()) + ->setNotificationType(NotificationType::REJECTION) + ->setUser($jo->getCreatedBy()); + $this->em->persist($notif); + $this->em->flush(); // send mqtt event diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index 3fb94720..a133e728 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -511,7 +511,9 @@