|
@@ -24,7 +24,7 @@ class DeviceListener
|
|
|
* @var string
|
|
|
*/
|
|
|
private $deviceDeletePostUrl;
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @var string
|
|
|
*/
|
|
@@ -36,13 +36,13 @@ class DeviceListener
|
|
|
* @param string $devicePostUrl
|
|
|
* @param string $deviceDeletePostUrl
|
|
|
*/
|
|
|
- public function __construct(Webservice $webservice, $devicePostUrl, $deviceDeletePostUrl, $devicePutUrl)
|
|
|
+ public function __construct($webservice, $devicePostUrl, $deviceDeletePostUrl, $devicePutUrl)
|
|
|
{
|
|
|
$this->webservice = $webservice;
|
|
|
$this->devicePostUrl = $devicePostUrl;
|
|
|
$this->deviceDeletePostUrl = $deviceDeletePostUrl;
|
|
|
$this->devicePutUrl = $devicePutUrl;
|
|
|
- $this->enabled = true;
|
|
|
+ $this->enabled = true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -50,9 +50,9 @@ class DeviceListener
|
|
|
*/
|
|
|
public function postPersist(LifecycleEventArgs $args)
|
|
|
{
|
|
|
- if(!$this->enabled) return ;
|
|
|
+ if (!$this->enabled) return;
|
|
|
|
|
|
- $this->send($args, $this->devicePostUrl, HttpRequestInterface::METHOD_POST);
|
|
|
+ $this->send($args, $this->devicePostUrl, HttpRequestInterface::METHOD_POST);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -60,28 +60,28 @@ class DeviceListener
|
|
|
*/
|
|
|
public function preRemove(LifecycleEventArgs $args)
|
|
|
{
|
|
|
- if(!$this->enabled) return ;
|
|
|
+ if (!$this->enabled) return;
|
|
|
|
|
|
$entity = $args->getEntity();
|
|
|
if ($entity instanceof DeviceInterface) {
|
|
|
- if($deviceId = $this->getRemoteDeviceId($entity)) {
|
|
|
+ if ($deviceId = $this->getRemoteDeviceId($entity)) {
|
|
|
|
|
|
$data = array('id' => $deviceId);
|
|
|
return $this->webservice->makeGetRequest($this->deviceDeletePostUrl, HttpRequestInterface::METHOD_DELETE, $data);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @param LifecycleEventArgs $args
|
|
|
*/
|
|
|
public function postUpdate(LifecycleEventArgs $args)
|
|
|
{
|
|
|
- if(!$this->enabled) return ;
|
|
|
+ if (!$this->enabled) return;
|
|
|
|
|
|
$entity = $args->getEntity();
|
|
|
if ($entity instanceof DeviceInterface) {
|
|
|
- if($deviceId = $this->getRemoteDeviceId($entity)) {
|
|
|
+ if ($deviceId = $this->getRemoteDeviceId($entity)) {
|
|
|
$url = "{$this->devicePutUrl}{$deviceId}";
|
|
|
$this->send($args, $url, HttpRequestInterface::METHOD_PUT);
|
|
|
} else {
|
|
@@ -98,28 +98,28 @@ class DeviceListener
|
|
|
*/
|
|
|
private function send(LifecycleEventArgs $args, $url, $method)
|
|
|
{
|
|
|
- if(!$this->enabled) return ;
|
|
|
+ if (!$this->enabled) return;
|
|
|
|
|
|
$entity = $args->getEntity();
|
|
|
if ($entity instanceof DeviceInterface) {
|
|
|
$data = $entity->getDeviceData();
|
|
|
$data = $this->addLocationData($entity, $data);
|
|
|
-
|
|
|
+
|
|
|
return $this->webservice->makeGetRequest($url, $method, $data);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Agrega la ubicación de $entity si implementa LocationInterface
|
|
|
- *
|
|
|
+ *
|
|
|
* @param Entity $entity
|
|
|
* @param array $data
|
|
|
- *
|
|
|
+ *
|
|
|
* @return array
|
|
|
*/
|
|
|
private function addLocationData($entity, $data)
|
|
|
{
|
|
|
- if(!$this->enabled) return ;
|
|
|
+ if (!$this->enabled) return;
|
|
|
|
|
|
$locationInterface = 'MapBundle\Entity\Interfaces\LocationInterface';
|
|
|
if (interface_exists($locationInterface) && is_a($entity, $locationInterface)) {
|
|
@@ -127,36 +127,37 @@ class DeviceListener
|
|
|
$extraData['location'] = $entity->getLocation() ? $entity->getLocation()->getData() : array();
|
|
|
$data['extraData'] = json_encode($extraData);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param object $entity
|
|
|
*/
|
|
|
- private function getRemoteDeviceId($entity)
|
|
|
+ private function getRemoteDeviceId($entity)
|
|
|
{
|
|
|
- if(!$this->enabled) return ;
|
|
|
+ if (!$this->enabled) return;
|
|
|
|
|
|
$deviceId = $entity->getId();
|
|
|
$deviceType = get_class($entity);
|
|
|
$tenancyId = $entity->getTenancyId();
|
|
|
-
|
|
|
|
|
|
- $filters = array('deviceId'=>$deviceId,'deviceType'=>$deviceType,'tenancyId'=>$tenancyId);
|
|
|
- $data = $this->webservice->getData("device_post_url",$filters);
|
|
|
+
|
|
|
+ $filters = array('deviceId' => $deviceId, 'deviceType' => $deviceType, 'tenancyId' => $tenancyId);
|
|
|
+ $data = $this->webservice->getData("device_post_url", $filters);
|
|
|
|
|
|
// file_put_contents("/var/flowdat/error.log",json_encode($data));
|
|
|
|
|
|
$deviceId = null;
|
|
|
- if(isset($data[0]))
|
|
|
+ if (isset($data[0]))
|
|
|
$deviceId = $data[0]['id'];
|
|
|
-
|
|
|
+
|
|
|
return $deviceId;
|
|
|
}
|
|
|
|
|
|
- function remoteCheck($enabled = true){
|
|
|
- $this->enabled = $enabled;
|
|
|
+ function remoteCheck($enabled = true)
|
|
|
+ {
|
|
|
+ $this->enabled = $enabled;
|
|
|
}
|
|
|
|
|
|
}
|