|
@@ -0,0 +1,144 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+namespace FTTHBundle\Controller;
|
|
|
|
+
|
|
|
|
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
|
|
|
+use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
|
|
+use Symfony\Component\HttpFoundation\Request;
|
|
|
|
+use Symfony\Component\HttpFoundation\JsonResponse;
|
|
|
|
+use Symfony\Component\HttpFoundation\Response;
|
|
|
|
+use MapBundle\Entity\Location;
|
|
|
|
+use FTTHBundle\Entity\ONU;
|
|
|
|
+
|
|
|
|
+use Symfony\Component\Form\Extension\Core\Type\TextType;
|
|
|
|
+use Symfony\Component\Form\Extension\Core\Type\DateType;
|
|
|
|
+use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
|
|
|
+use WebserviceBundle\Form\Type\RemoteClientType;
|
|
|
|
+use MapBundle\Form\Type\RemoteMapType;
|
|
|
|
+
|
|
|
|
+class ONUController extends Controller
|
|
|
|
+{
|
|
|
|
+
|
|
|
|
+ public function importAction()
|
|
|
|
+ {
|
|
|
|
+ //$em = $this->get('doctrine')->getManager();
|
|
|
|
+ $adminPool = $this->get('sonata.admin.pool');
|
|
|
|
+ $webservice = $this->get("webservice");
|
|
|
|
+
|
|
|
|
+ $urlMaps = $this->getParameter('remote_get_map_url');
|
|
|
|
+
|
|
|
|
+ /* Chequeamos que existe el objectType ONU - Esto debe venir definido por defecto luego */
|
|
|
|
+ $urlObjectTypes = $this->getParameter('remote_get_object_type_url');
|
|
|
|
+ $filters = array('name' => 'ONU');
|
|
|
|
+ $_types = $webservice->getData($urlObjectTypes, $filters, array(), null, null);
|
|
|
|
+ $disabled = false;
|
|
|
|
+ $flashbag = $this->get('session')->getFlashBag();
|
|
|
|
+ if(empty($_types)) {
|
|
|
|
+ $flashbag->add("error", "No existen ONUs definidas en el módulo de Mapas.");
|
|
|
|
+ $disabled = true;
|
|
|
|
+ $objectTypeId = 0;
|
|
|
|
+ } else {
|
|
|
|
+ $objectTypeId = $_types[0]['id'];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $form = $this->createFormBuilder()
|
|
|
|
+ ->add('mapId', RemoteMapType::class, array('label' => 'Mapa', 'disabled' => $disabled))
|
|
|
|
+ ->add('clientId', RemoteClientType::class, array('label' => 'Cliente', 'disabled' => $disabled))
|
|
|
|
+ ->getForm();
|
|
|
|
+
|
|
|
|
+ $flashbag->add("warning", "Seleccione el Mapa desde el que se importarán las ONUs y el cliente al que se asociarán.");
|
|
|
|
+
|
|
|
|
+ return $this->render('FTTHBundle:ONU:onu_import.html.twig', array(
|
|
|
|
+ 'base_template' => $adminPool->getTemplate('layout'),
|
|
|
|
+ 'admin_pool' => $adminPool,
|
|
|
|
+ 'admin' => $adminPool->getAdminByClass("FTTHBundle\Entity\ONU"),
|
|
|
|
+ 'objectTypeId' => $objectTypeId,
|
|
|
|
+ 'form' => $form->createView(),
|
|
|
|
+ 'disabled' => $disabled
|
|
|
|
+ ));
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * Queda pendiente enviar un comando para actualizar masivamente los devices
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
+ public function onuSaveAction(Request $request)
|
|
|
|
+ {
|
|
|
|
+ $em = $this->get('doctrine')->getManager();
|
|
|
|
+ $webservice = $this->get("webservice");
|
|
|
|
+
|
|
|
|
+ $mapId = $request->get('mapId');
|
|
|
|
+ $clientId = $request->get('clientId');
|
|
|
|
+
|
|
|
|
+ if(is_null($mapId) || empty($mapId) || is_null($clientId) || empty($clientId)) {
|
|
|
|
+ $response = new Response(
|
|
|
|
+ json_encode(array()),
|
|
|
|
+ Response::HTTP_OK,
|
|
|
|
+ array('content-type' => 'application/json')
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ return $response;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $limit = $request->get('limit');
|
|
|
|
+ $offset = $request->get('offset');
|
|
|
|
+ $objectTypeId = $request->get('objectTypeId');
|
|
|
|
+
|
|
|
|
+ $urlObjectTypes = $this->getParameter('remote_get_objects_url');
|
|
|
|
+
|
|
|
|
+ $filters = array('type' => $objectTypeId, 'map' => $mapId);
|
|
|
|
+ $_onus = $webservice->getData($urlObjectTypes, $filters, array(), $limit, $offset);
|
|
|
|
+
|
|
|
|
+ $return = array();
|
|
|
|
+ foreach($_onus as $onu) {
|
|
|
|
+ $object = $em->getRepository("FTTHBundle:ONU")->findOneByPonSerialNumber($onu['text']);
|
|
|
|
+ if(is_null($object)) {
|
|
|
|
+ $object = new ONU();
|
|
|
|
+ $object->setClientId(1);
|
|
|
|
+ $object->setTenancyId(1);
|
|
|
|
+ $object->setPonSerialNumber($onu['text']);
|
|
|
|
+ $em->persist($object);
|
|
|
|
+ $return[] = "ONU create {$onu['text']}";
|
|
|
|
+ }
|
|
|
|
+ $location = $object->getLocation();
|
|
|
|
+
|
|
|
|
+ $data = json_decode($onu['vector']['data'],true);
|
|
|
|
+ $mapLocation = $data[0];
|
|
|
|
+
|
|
|
|
+ $mapLocation['zoom'] = 17;
|
|
|
|
+ $mapLocation['onu'] = "{$object->getPonSerialNumber()}";
|
|
|
|
+ $mapLocation['map_object_id'] = $onu['id'];
|
|
|
|
+
|
|
|
|
+ $action = "update";
|
|
|
|
+ if(is_null($location)) {
|
|
|
|
+ $location = new Location();
|
|
|
|
+ $em->persist($location);
|
|
|
|
+ $object->setLocation($location);
|
|
|
|
+ $em->persist($object);
|
|
|
|
+ $em->flush();
|
|
|
|
+ $action = "create";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $return[] = "LOCATION (id {$location->getId()}) {$action} - ONU (id {$object->getId()}) {$onu['text']} - ".json_encode($mapLocation);
|
|
|
|
+
|
|
|
|
+ $location->setJsonExtraData($mapLocation);
|
|
|
|
+ $location->setObjectTypeId($objectTypeId);
|
|
|
|
+ $location->setMapId($mapId);
|
|
|
|
+
|
|
|
|
+ $em->persist($location);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $em->flush();
|
|
|
|
+
|
|
|
|
+ $response = new Response(
|
|
|
|
+ json_encode($return),
|
|
|
|
+ Response::HTTP_OK,
|
|
|
|
+ array('content-type' => 'application/json')
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ return $response;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|