From 01f5717c1cf1bed851040ec6c7df25494e37a66b Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Sun, 23 Aug 2020 01:09:45 +0800 Subject: [PATCH] Add notification sending when rider rejects JO #472 --- src/Entity/Notification.php | 6 ++++++ src/Service/NotificationManager.php | 6 +++++- src/Service/RiderAPIHandler/CMBRiderAPIHandler.php | 8 +++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Entity/Notification.php b/src/Entity/Notification.php index c702ce25..d024ac68 100644 --- a/src/Entity/Notification.php +++ b/src/Entity/Notification.php @@ -61,6 +61,12 @@ class Notification */ protected $flag_fresh; + public function __construct() + { + $this->flag_read = false; + $this->flag_fresh = true; + } + public function getID() { return $this->id; diff --git a/src/Service/NotificationManager.php b/src/Service/NotificationManager.php index f0a6deec..86de0348 100644 --- a/src/Service/NotificationManager.php +++ b/src/Service/NotificationManager.php @@ -22,7 +22,7 @@ class NotificationManager } // set user_id to 0 for all - public function sendNotification($user_id, $msg) + public function sendNotification($user_id, $msg, $url) { // send mqtt $chan = $this->getChannel($user_id); @@ -31,6 +31,10 @@ class NotificationManager // create notif $notif = new Notification(); + $notif->setUserID($user_id) + ->setIcon('') + ->setMessage($msg) + ->setURL($url); // save to db $this->em->persist($notif); diff --git a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php index 282f6bb6..d7b97186 100644 --- a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php +++ b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php @@ -23,6 +23,7 @@ use App\Service\WarrantyHandler; use App\Service\JobOrderHandlerInterface; use App\Service\InvoiceGeneratorInterface; use App\Service\RiderTracker; +use App\Service\NotificationManager; use App\Entity\RiderSession; use App\Entity\Rider; @@ -53,13 +54,14 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface protected $ic; protected $session; protected $upload_dir; + protected $nm; public function __construct(EntityManagerInterface $em, RedisClientProvider $redis, EncoderFactoryInterface $ef, RiderCache $rcache, string $country_code, MQTTClient $mclient, WarrantyHandler $wh, JobOrderHandlerInterface $jo_handler, InvoiceGeneratorInterface $ic, string $upload_dir, - RiderTracker $rider_tracker) + RiderTracker $rider_tracker, NotificationManager $nm) { $this->em = $em; $this->redis = $redis; @@ -72,6 +74,7 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface $this->ic = $ic; $this->upload_dir = $upload_dir; $this->rider_tracker = $rider_tracker; + $this->nm = $nm; // one device = one session, since we have control over the devices // when a rider logs in, we just change the rider assigned to the device @@ -1154,6 +1157,9 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface $this->mclient->publish($channel, $rider_status); + $notif_url = $this->generateUrl('jo_onestep_edit_form', ['id' => $jo->getID()]); + $this->nm->sendNotification(0, 'Job order has been rejected by rider.', $notif_url); + return $data; }