78 lines
2.1 KiB
PHP
78 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Service\RiderAssignmentHandler;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
|
|
|
use App\Service\RiderAssignmentHandlerInterface;
|
|
use App\Service\MQTTClient;
|
|
use App\Service\APNSClient;
|
|
|
|
use App\Entity\JobOrder;
|
|
use App\Entity\Rider;
|
|
|
|
use App\Ramcar\JOStatus;
|
|
|
|
class ResqRiderAssignmentHandler implements RiderAssignmentHandlerInterface
|
|
{
|
|
protected $em;
|
|
protected $aclient;
|
|
protected $mclient;
|
|
protected $translator;
|
|
|
|
public function __construct(EntityManagerInterface $em, MQTTClient $mclient,
|
|
APNSClient $aclient, TranslatorInterface $translator)
|
|
{
|
|
$this->em = $em;
|
|
$this->mclient = $mclient;
|
|
$this->aclient = $aclient;
|
|
$this->translator = $translator;
|
|
}
|
|
|
|
// assign job order to rider
|
|
public function assignJobOrder(JobOrder $obj, Rider $rider)
|
|
{
|
|
// create the payload
|
|
$payload = [
|
|
'event' => 'driver_assigned'
|
|
];
|
|
|
|
// send event
|
|
$this->mclient->sendEvent($obj, $payload);
|
|
|
|
// check if rider is available
|
|
if ($rider->isAvailable())
|
|
{
|
|
error_log('set rider availability to false');
|
|
// set rider to unavailable
|
|
$rider->setAvailable(false);
|
|
|
|
// send event to rider
|
|
$this->mclient->sendRiderEvent($obj, $payload);
|
|
|
|
// send push notification
|
|
$this->aclient->sendPush($obj, $this->translator->trans('message.rider_otw'));
|
|
|
|
$this->em->flush();
|
|
}
|
|
}
|
|
|
|
// complete job order
|
|
public function fulfillJobOrder(JobOrder $obj, string $image_url, Rider $rider)
|
|
{
|
|
// send to mqtt
|
|
$payload = [
|
|
'event' => 'fulfilled',
|
|
'jo_id' => $obj->getID(),
|
|
'driver_image' => $image_url,
|
|
'driver_name' => $rider->getFullName(),
|
|
'driver_id' => $rider->getID(),
|
|
];
|
|
$this->mclient->sendEvent($obj, $payload);
|
|
|
|
// send fulfill/complete event to rider
|
|
$this->mclient->sendRiderEvent($obj, $payload);
|
|
}
|
|
}
|