Merge branch '133-fix-alerts-for-ios-app-from-rider-app-initiated-events' into 'master'
Resolve "Fix alerts for ios app from rider app initiated events" Closes #133 See merge request jankstudio/resq!119
This commit is contained in:
commit
78a2cf4b36
4 changed files with 67 additions and 6 deletions
12
.env.dist
12
.env.dist
|
|
@ -16,3 +16,15 @@ APP_SECRET=b344cd6cd151ae1d61403ed55806c5ce
|
|||
DATABASE_URL=mysql://db_user:db_password@127.0.0.1:3306/db_name
|
||||
###< doctrine/doctrine-bundle ###
|
||||
GMAPS_API_KEY=insertgmapsapikeyhere
|
||||
|
||||
# rising tide sms gateway
|
||||
RT_USER=rt_user
|
||||
RT_PASS=rt_pass
|
||||
RT_USAGE_TYPE=rt_usage_type
|
||||
RT_SHORTCODE=1234
|
||||
|
||||
|
||||
# mosquitto client
|
||||
MQTT_IP_ADDRESS=localhost
|
||||
MQTT_PORT=1883
|
||||
|
||||
|
|
|
|||
|
|
@ -64,3 +64,8 @@ services:
|
|||
$pass: "%env(RT_PASS)%"
|
||||
$usage_type: "%env(RT_USAGE_TYPE)%"
|
||||
$shortcode: "%env(RT_SHORTCODE)%"
|
||||
|
||||
App\Service\MQTTClient:
|
||||
arguments:
|
||||
$ip_address: "%env(MQTT_IP_ADDRESS)%"
|
||||
$port: "%env(MQTT_PORT)%"
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ use App\Entity\JOEvent;
|
|||
use App\Service\InvoiceCreator;
|
||||
use App\Service\MapTools;
|
||||
use App\Service\HubCounter;
|
||||
use App\Service\MQTTClient;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\DBAL\Connection;
|
||||
|
|
@ -1073,7 +1074,7 @@ class JobOrderController extends BaseController
|
|||
return $this->render('job-order/form.html.twig', $params);
|
||||
}
|
||||
|
||||
public function assigningSubmit(Request $req, ValidatorInterface $validator, $id)
|
||||
public function assigningSubmit(Request $req, ValidatorInterface $validator, MQTTCLient $mclient, $id)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('jo_assign.list', null, 'No access.');
|
||||
|
||||
|
|
@ -1161,7 +1162,7 @@ class JobOrderController extends BaseController
|
|||
$payload = [
|
||||
'event' => 'driver_assigned'
|
||||
];
|
||||
$this->sendEvent($obj, $payload);
|
||||
$mclient->sendEvent($obj, $payload);
|
||||
|
||||
// return successful response
|
||||
return $this->json([
|
||||
|
|
@ -1264,7 +1265,7 @@ class JobOrderController extends BaseController
|
|||
->setWarrantyExpiration($warr_date);
|
||||
}
|
||||
|
||||
public function fulfillmentSubmit(Request $req, ValidatorInterface $validator, $id)
|
||||
public function fulfillmentSubmit(Request $req, ValidatorInterface $validator, MQTTClient $mclient, $id)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('jo_fulfill.list', null, 'No access.');
|
||||
|
||||
|
|
@ -1354,7 +1355,7 @@ class JobOrderController extends BaseController
|
|||
'driver_name' => $rider->getFullName(),
|
||||
'driver_id' => $rider->getID(),
|
||||
];
|
||||
$this->sendEvent($obj, $payload);
|
||||
$mclient->sendEvent($obj, $payload);
|
||||
|
||||
// return successful response
|
||||
return $this->json([
|
||||
|
|
@ -1745,7 +1746,7 @@ class JobOrderController extends BaseController
|
|||
return $this->render('job-order/form.pdf.html.twig', $params);
|
||||
}
|
||||
|
||||
public function cancelJobOrder(Request $req, $id)
|
||||
public function cancelJobOrder(Request $req, MQTTClient $mclient, $id)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('joborder.cancel', null, 'No access.');
|
||||
|
||||
|
|
@ -1794,7 +1795,7 @@ class JobOrderController extends BaseController
|
|||
'reason' => $cancel_reason,
|
||||
'jo_id' => $obj->getID(),
|
||||
];
|
||||
$this->sendEvent($obj, $payload);
|
||||
$mclient->sendEvent($obj, $payload);
|
||||
|
||||
// return successful response
|
||||
return $this->json([
|
||||
|
|
|
|||
43
src/Service/MQTTClient.php
Normal file
43
src/Service/MQTTClient.php
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Mosquitto\Client as MosquittoClient;
|
||||
use App\Entity\JobOrder;
|
||||
|
||||
class MQTTClient
|
||||
{
|
||||
const PREFIX = 'motolite.control.';
|
||||
|
||||
protected $mclient;
|
||||
|
||||
public function __construct($ip_address, $port)
|
||||
{
|
||||
$this->mclient = new MosquittoClient();
|
||||
$this->mclient->connect($ip_address, $port);
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$this->mclient->disconnect();
|
||||
}
|
||||
|
||||
public function publish($channel, $message)
|
||||
{
|
||||
$this->mclient->publish($channel, $message);
|
||||
}
|
||||
|
||||
public function sendEvent(JobOrder $job_order, $payload)
|
||||
{
|
||||
$sessions = $job_order->getCustomer()->getMobileSessions();
|
||||
if (count($sessions) == 0)
|
||||
return;
|
||||
|
||||
foreach ($sessions as $sess)
|
||||
{
|
||||
$phone_num = $sess->getPhoneNumber();
|
||||
$channel = self::PREFIX . $phone_num;
|
||||
$this->publish($channel, json_encode($payload));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue