Add cancel event and have mobile sendEvent send to all sessions of a job order #122

This commit is contained in:
Kendrick Chan 2018-05-20 22:45:41 +08:00
parent 276a6d1245
commit 429dc99b29

View file

@ -1364,15 +1364,20 @@ class JobOrderController extends BaseController
protected function sendEvent(JobOrder $job_order, $payload)
{
$session = $job_order->getCustomer()->getMobileSessions();
$sessions = $job_order->getCustomer()->getMobileSessions();
if (count($session) == 0)
return;
$phone_num = $session[0]->getPhoneNumber();
$channel = 'motolite.control.' . $phone_num;
$client = new MosquittoClient();
$client->connect('localhost', 1883);
$client->publish($channel, json_encode($payload));
foreach ($sessions as $sess)
{
$phone_num = $sess->getPhoneNumber();
$channel = 'motolite.control.' . $phone_num;
$client->publish($channel, json_encode($payload));
}
$client->disconnect();
}
@ -1783,6 +1788,13 @@ class JobOrderController extends BaseController
// save
$em->flush();
// send mobile app event
$payload = [
'event' => 'cancelled',
'jo_id' => $obj->getID(),
];
$this->sendEvent($obj, $payload);
// return successful response
return $this->json([
'success' => 'Job order has been cancelled!'