|
@@ -0,0 +1,80 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace StatsBundle\Services;
|
|
|
+
|
|
|
+use Doctrine\ORM\EntityManagerInterface;
|
|
|
+use Doctrine\ORM\EntityRepository;
|
|
|
+use StatsBundle\Entity\Report;
|
|
|
+use Symfony\Component\Validator\Validator\ValidatorInterface;
|
|
|
+use WebserviceBundle\Services\Webservice;
|
|
|
+
|
|
|
+class ReportManager
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * @var EntityManagerInterface
|
|
|
+ */
|
|
|
+ private $em;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var ValidatorInterface
|
|
|
+ */
|
|
|
+ private $validator;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var EntityRepository
|
|
|
+ */
|
|
|
+ private $reportRepository;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var Webservice
|
|
|
+ */
|
|
|
+ private $webservice;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param EntityManagerInterface $em
|
|
|
+ * @param ValidatorInterface $validator
|
|
|
+ * @param Webservice $webservice
|
|
|
+ */
|
|
|
+ public function __construct(EntityManagerInterface $em, ValidatorInterface $validator, Webservice $webservice)
|
|
|
+ {
|
|
|
+ $this->em = $em;
|
|
|
+ $this->reportRepository = $em->getRepository('StatsBundle:Report');
|
|
|
+ $this->validator = $validator;
|
|
|
+ $this->webservice = $webservice;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param string $deviceType
|
|
|
+ * @param string $reportType
|
|
|
+ * @param int $deviceId
|
|
|
+ * @param int $deviceServer
|
|
|
+ * @param int $tenancyId
|
|
|
+ * @param array $data
|
|
|
+ *
|
|
|
+ * @return Report
|
|
|
+ */
|
|
|
+ public function create($deviceType, $reportType, $deviceId, $deviceServer, $tenancyId, $data = array())
|
|
|
+ {
|
|
|
+ $report = new Report();
|
|
|
+ $report->setDeviceType($deviceType);
|
|
|
+ $report->setReportType($reportType);
|
|
|
+ $report->setDeviceId($deviceId);
|
|
|
+
|
|
|
+ $deviceServer = $this->em->getRepository('\StatsBundle\Entity\DeviceServer')->findOneById($deviceServer);
|
|
|
+ $report->setDeviceServer($deviceServer);
|
|
|
+
|
|
|
+ $report->setTenancyId($tenancyId);
|
|
|
+ $report->setJsonExtraData($data);
|
|
|
+ $report->setCreated(new \DateTime());
|
|
|
+
|
|
|
+
|
|
|
+ if ($this->validator->validate($report)->count() == 0) {
|
|
|
+ $this->em->persist($report);
|
|
|
+ $this->em->flush($report);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $report;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|