From ff83dec5ceb2113616076f78fed391232076eef1 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 23 Jul 2020 04:40:48 +0000 Subject: [PATCH] Add upload photo event type. #424 --- src/Ramcar/CMBJOEventType.php | 32 ++++++++++--------- .../RiderAPIHandler/CMBRiderAPIHandler.php | 32 +++++++++++++++++++ 2 files changed, 49 insertions(+), 15 deletions(-) diff --git a/src/Ramcar/CMBJOEventType.php b/src/Ramcar/CMBJOEventType.php index 4a26baa4..631b434b 100644 --- a/src/Ramcar/CMBJOEventType.php +++ b/src/Ramcar/CMBJOEventType.php @@ -4,21 +4,22 @@ namespace App\Ramcar; class CMBJOEventType extends NameValue { - const CREATE = 'create'; - const HUB_ASSIGN = 'hub_assign'; - const RIDER_ASSIGN = 'rider_assign'; - const CANCEL = 'cancel'; - const FULFILL = 'fulfill'; - const OPEN_EDIT = 'open_edit'; - const REQUEUE = 'requeue'; - const RIDER_ACCEPT = 'accept'; - const RIDER_IN_TRANSIT = 'rider_in_transit'; - const RIDER_ARRIVE = 'arrive'; - const RIDER_START = 'rider_start'; - const RIDER_EDIT = 'rider_edit'; - const PAID = 'paid'; - const PERFORM = 'perform'; - const RIDER_FINISH = 'finish'; + const CREATE = 'create'; + const HUB_ASSIGN = 'hub_assign'; + const RIDER_ASSIGN = 'rider_assign'; + const CANCEL = 'cancel'; + const FULFILL = 'fulfill'; + const OPEN_EDIT = 'open_edit'; + const REQUEUE = 'requeue'; + const RIDER_ACCEPT = 'accept'; + const RIDER_IN_TRANSIT = 'rider_in_transit'; + const RIDER_ARRIVE = 'arrive'; + const RIDER_START = 'rider_start'; + const RIDER_EDIT = 'rider_edit'; + const PAID = 'paid'; + const PERFORM = 'perform'; + const RIDER_FINISH = 'finish'; + const RIDER_UPLOAD_PHOTO = 'rider_upload_photo'; const COLLECTION = [ 'create' => 'Created', @@ -36,5 +37,6 @@ class CMBJOEventType extends NameValue 'paid' => 'Paid', 'perform' => 'Perform', 'finish' => 'Finish', + 'rider_upload_photo' => 'Rider Upload Photo', ]; } diff --git a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php index 8834a106..ef87523f 100644 --- a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php +++ b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php @@ -522,6 +522,17 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface $jo_event = current($complete_results); $date_complete = $jo_event->getDateHappen()->format('Ymd H:i:s'); } + else + { + // find the time when photos were uploaded + $upload_event_type = CMBJOEventType::RIDER_UPLOAD_PHOTO; + $upload_results = $this->em->getRepository(JOEvent::class)->findby(['type_id' => $upload_event_type, 'rider' => $rider_id, 'job_order' => $jo_id], ['date_happen' => 'DESC']); + if ($upload_results != null) + { + $jo_event = current($upload_results); + $date_complete = $jo_event->getDateHappen()->format('Ymd H:i:s'); + } + } $jo_data[] = [ 'job_order' => [ @@ -856,6 +867,17 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface $jo_event = current($complete_results); $date_complete = $jo_event->getDateHappen()->format('Ymd H:i:s'); } + else + { + // find the time when photos were uploaded + $upload_event_type = CMBJOEventType::RIDER_UPLOAD_PHOTO; + $upload_results = $this->em->getRepository(JOEvent::class)->findby(['type_id' => $upload_event_type, 'rider' => $rider_id, 'job_order' => $jo_id], ['date_happen' => 'DESC']); + if ($upload_results != null) + { + $jo_event = current($upload_results); + $date_complete = $jo_event->getDateHappen()->format('Ymd H:i:s'); + } + } $data = [ 'id' => $jo->getID(), @@ -1805,6 +1827,8 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + $rider = $this->session->getRider(); + // get longitude and latitude // TODO: right now, we're just checking if we get the coordinates $this->getHeaderCoordinates($req); @@ -1973,6 +1997,14 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface } } + // create event for upload photo + $rider_event = new JOEvent(); + $rider_event->setDateHappen(new DateTime()) + ->setTypeID(CMBJOEventType::RIDER_UPLOAD_PHOTO) + ->setJobOrder($jo) + ->setRider($rider); + $this->em->persist($rider_event); + $this->em->flush(); }