|
@@ -4,7 +4,7 @@ namespace StatsBundle\Services;
|
|
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
use Doctrine\ORM\EntityRepository;
|
|
|
-use StatsBundle\Entity\StatsDevice;
|
|
|
+use StatsBundle\Entity\Device;
|
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
|
|
use WebserviceBundle\Services\Webservice;
|
|
|
|
|
@@ -29,7 +29,7 @@ class DeviceManager
|
|
|
/**
|
|
|
* @var EntityRepository
|
|
|
*/
|
|
|
- private $statsDeviceRepository;
|
|
|
+ private $deviceRepository;
|
|
|
|
|
|
/**
|
|
|
* @var Webservice
|
|
@@ -46,7 +46,7 @@ class DeviceManager
|
|
|
{
|
|
|
$this->em = $em;
|
|
|
$this->deviceServerRepository = $em->getRepository('StatsBundle:DeviceServer');
|
|
|
- $this->statsDeviceRepository = $em->getRepository('StatsBundle:StatsDevice');
|
|
|
+ $this->deviceRepository = $em->getRepository('StatsBundle:Device');
|
|
|
$this->validator = $validator;
|
|
|
$this->webservice = $webservice;
|
|
|
}
|
|
@@ -71,7 +71,7 @@ class DeviceManager
|
|
|
unset($remoteDevice['id']);
|
|
|
unset($remoteDevice['deviceType']);
|
|
|
unset($remoteDevice['deviceId']);
|
|
|
- $device = $this->create($deviceType, $deviceId, $remoteDevice);
|
|
|
+ $device = $this->create($deviceType, $deviceId, $deviceServer, $remoteDevice);
|
|
|
if ($device) {
|
|
|
$devices[] = $device;
|
|
|
}
|
|
@@ -87,30 +87,34 @@ class DeviceManager
|
|
|
* @param int $deviceId
|
|
|
* @param array $data
|
|
|
*
|
|
|
- * @return StatsDevice
|
|
|
+ * @return Device
|
|
|
*/
|
|
|
- public function create($deviceType, $deviceId, $data = array())
|
|
|
+ public function create($deviceType, $deviceId, $deviceServer, $data = array())
|
|
|
{
|
|
|
$device = null;
|
|
|
- $statsDevice = $this->statsDeviceRepository->findOneBy(array(
|
|
|
+ $_device = $this->deviceRepository->findOneBy(array(
|
|
|
'deviceType' => $deviceType,
|
|
|
'deviceId' => $deviceId,
|
|
|
+ 'deviceServer' => $deviceServer,
|
|
|
));
|
|
|
- if (is_null($statsDevice)) {
|
|
|
- $device = new StatsDevice();
|
|
|
- $device->setDeviceType($deviceType);
|
|
|
- $device->setDeviceId($deviceId);
|
|
|
- foreach ($data as $column => $value) {
|
|
|
- $method = 'set'.ucfirst($column);
|
|
|
- if (method_exists($device, $method)) {
|
|
|
- $device->$method($value);
|
|
|
- }
|
|
|
+ if (is_null($_device)) {
|
|
|
+ $device = new Device();
|
|
|
+ } else {
|
|
|
+ $device = $_device;
|
|
|
+ }
|
|
|
+ $device->setDeviceType($deviceType);
|
|
|
+ $device->setDeviceId($deviceId);
|
|
|
+ $device->setDeviceServer($deviceServer);
|
|
|
+ foreach ($data as $column => $value) {
|
|
|
+ $method = 'set'.ucfirst($column);
|
|
|
+ if (method_exists($device, $method)) {
|
|
|
+ $device->$method($value);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- if ($this->validator->validate($device)->count() == 0) {
|
|
|
- $this->em->persist($device);
|
|
|
- $this->em->flush($device);
|
|
|
- }
|
|
|
+ if ($this->validator->validate($device)->count() == 0) {
|
|
|
+ $this->em->persist($device);
|
|
|
+ $this->em->flush($device);
|
|
|
}
|
|
|
|
|
|
return $device;
|