diff --git a/src/Controller/CAPI/CustomerWarrantyController.php b/src/Controller/CAPI/CustomerWarrantyController.php index 1b306cf6..3a7c699a 100644 --- a/src/Controller/CAPI/CustomerWarrantyController.php +++ b/src/Controller/CAPI/CustomerWarrantyController.php @@ -2,6 +2,8 @@ namespace App\Controller\CAPI; +use Catalyst\APIBundle\Entity\User as APIUser; + use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\KernelInterface; @@ -315,7 +317,11 @@ class CustomerWarrantyController extends APIController 'invoice' => $req->request->get('invoice'), ]; $action = 'create/update'; - $source = WarrantySource::CAPI; + + // get the api_user that made the call so that it gets added to the source + // source becomes CAPI_USER_ + $username = $this->getAPIUsername($em, $user_id); + $source = 'CAPI_USER_' . $username; error_log('SOURCE: ' . $source); @@ -582,4 +588,15 @@ class CustomerWarrantyController extends APIController $rt->sendSMS($clean_num, 'MOTOLITE', $message); } + protected function getAPIUsername($em, $user_id) + { + $api_user_result = $em->getRepository(APIUser::class)->findBy(['api_key' => $user_id]); + $username = ''; + foreach ($api_user_result as $api_user) + { + $username = $api_user->getName(); + } + + return $username; + } } diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index f5386d55..2dc0d837 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -2,6 +2,8 @@ namespace App\Controller\CAPI; +use Catalyst\APIBundle\Entity\User as APIUser; + use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Doctrine\ORM\Query; @@ -191,7 +193,12 @@ class WarrantyController extends APIController 'mobile_number' => $mnum, ]; $action = 'create'; - $source = WarrantySource::CAPI; + + // get the api_user that made the call so that it gets added to the source + // source becomes CAPI_USER_ + $username = $this->getAPIUsername($em, $user_id); + + $source = 'CAPI_USER_' . $username; $msg = $this->checkRequiredParameters($req, $params); error_log('msg - ' . $msg); @@ -322,7 +329,12 @@ class WarrantyController extends APIController 'id' => $id, ]; $action = 'claim'; - $source = WarrantySource::CAPI; + + // get the api_user that made the call so that it gets added to the source + // source becomes CAPI_USER_ + $username = $this->getAPIUsername($em, $user_id); + $source = 'CAPI_USER_' . $username; + $msg = $this->checkRequiredParameters($req, $params); if ($msg) @@ -777,4 +789,16 @@ class WarrantyController extends APIController return $customers; } + protected function getAPIUsername($em, $user_id) + { + $api_user_result = $em->getRepository(APIUser::class)->findBy(['api_key' => $user_id]); + $username = ''; + foreach ($api_user_result as $api_user) + { + $username = $api_user->getName(); + } + + return $username; + } + } diff --git a/src/Ramcar/WarrantySource.php b/src/Ramcar/WarrantySource.php index 3c16ee89..be9c47e1 100644 --- a/src/Ramcar/WarrantySource.php +++ b/src/Ramcar/WarrantySource.php @@ -10,6 +10,7 @@ class WarrantySource extends NameValue const BULK_UPLOAD = 'bulk_upload'; const MOBILE = 'mobile'; const COMMAND = 'command'; + const UNKNOWN = 'unknown'; const COLLECTION = [ 'capi' => 'Third Party API', @@ -18,6 +19,7 @@ class WarrantySource extends NameValue 'bulk_upload' => 'Bulk Upload', 'mobile' => 'Mobile API', 'command' => 'Command', + 'unknown' => 'Unknown', ]; }