|
@@ -25,7 +25,7 @@ use FOS\RestBundle\Controller\Annotations\RouteResource;
|
|
|
class ONUController extends Controller
|
|
|
{
|
|
|
|
|
|
- public function importAction()
|
|
|
+ public function importAction()
|
|
|
{
|
|
|
$adminPool = $this->get('sonata.admin.pool');
|
|
|
$webservice = $this->get("webservice");
|
|
@@ -34,25 +34,25 @@ class ONUController extends Controller
|
|
|
|
|
|
$urlObjects = $this->container->hasParameter('remote_get_objects_url');
|
|
|
$urlObjectTypes = $this->container->hasParameter('remote_get_object_type_url');
|
|
|
- $_types = array();
|
|
|
+ $_types = array();
|
|
|
$disabled = false;
|
|
|
$objectTypeId = 0;
|
|
|
|
|
|
- if(!$urlObjects) {
|
|
|
- $flashbag->add("error", $translator->trans("msg_no_defined_ftth_url",array(),"FTTHBundle"));
|
|
|
+ if (!$urlObjects) {
|
|
|
+ $flashbag->add("error", $translator->trans("msg_no_defined_ftth_url", array(), "FTTHBundle"));
|
|
|
$disabled = true;
|
|
|
} else {
|
|
|
- if(!$urlObjectTypes) {
|
|
|
- $flashbag->add("error", $translator->trans("msg_no_defined_ftth_url",array(),"FTTHBundle"));
|
|
|
+ if (!$urlObjectTypes) {
|
|
|
+ $flashbag->add("error", $translator->trans("msg_no_defined_ftth_url", array(), "FTTHBundle"));
|
|
|
$disabled = true;
|
|
|
} else {
|
|
|
$urlObjectTypes = $this->getParameter('remote_get_object_type_url');
|
|
|
$filters = array('name' => 'ONU');
|
|
|
$_types = $webservice->getData($urlObjectTypes, $filters, array(), null, null);
|
|
|
}
|
|
|
-
|
|
|
- if(empty($_types)) {
|
|
|
- $flashbag->add("error", $translator->trans("msg_no_onu_in_map",array(),"FTTHBundle"));
|
|
|
+
|
|
|
+ if (empty($_types)) {
|
|
|
+ $flashbag->add("error", $translator->trans("msg_no_onu_in_map", array(), "FTTHBundle"));
|
|
|
$disabled = true;
|
|
|
$objectTypeId = 0;
|
|
|
} else {
|
|
@@ -60,14 +60,14 @@ class ONUController extends Controller
|
|
|
$objectTypeId = $_types[0]['id'];
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$form = $this->createFormBuilder()
|
|
|
- ->add('mapId', RemoteMapType::class, array('label' => $translator->trans("form.label_map",array(),"FTTHBundle"), 'disabled' => $disabled))
|
|
|
- ->add('clientId', RemoteClientType::class, array('label' => $translator->trans("form.label_client",array(),"FTTHBundle"), 'disabled' => $disabled))
|
|
|
- ->getForm();
|
|
|
-
|
|
|
- $flashbag->add("warning", $translator->trans("msg_select_map",array(),"FTTHBundle"));
|
|
|
-
|
|
|
+ ->add('mapId', RemoteMapType::class, array('label' => $translator->trans("form.label_map", array(), "FTTHBundle"), 'disabled' => $disabled))
|
|
|
+ ->add('clientId', RemoteClientType::class, array('label' => $translator->trans("form.label_client", array(), "FTTHBundle"), 'disabled' => $disabled))
|
|
|
+ ->getForm();
|
|
|
+
|
|
|
+ $flashbag->add("warning", $translator->trans("msg_select_map", array(), "FTTHBundle"));
|
|
|
+
|
|
|
return $this->render('FTTHBundle:ONU:onu_import.html.twig', array(
|
|
|
'base_template' => $adminPool->getTemplate('layout'),
|
|
|
'admin_pool' => $adminPool,
|
|
@@ -83,38 +83,38 @@ class ONUController extends Controller
|
|
|
* Queda pendiente enviar un comando para actualizar masivamente los devices
|
|
|
* /admin/ftth/onu/onu_save?_=1508847664462&limit=100&mapId=3&offset=0&clientId=1
|
|
|
*/
|
|
|
- public function onuSaveAction(Request $request)
|
|
|
+ public function onuSaveAction(Request $request)
|
|
|
{
|
|
|
- $em = $this->get('doctrine')->getManager();
|
|
|
+ $em = $this->get('doctrine')->getManager();
|
|
|
$webservice = $this->get("webservice");
|
|
|
$tenancy_service = $this->get("base_tenancy.tenancy_service");
|
|
|
|
|
|
$mapId = $request->get('mapId');
|
|
|
$clientId = $request->get('clientId');
|
|
|
-
|
|
|
- if(is_null($mapId) || empty($mapId) || is_null($clientId) || empty($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) {
|
|
|
+ foreach ($_onus as $onu) {
|
|
|
$object = $em->getRepository("FTTHBundle:ONU")->findOneByPonSerialNumber($onu['text']);
|
|
|
- if(is_null($object)) {
|
|
|
+ if (is_null($object)) {
|
|
|
$object = new ONU();
|
|
|
$object->setClientId($clientId);
|
|
|
$object->setTenancyId($tenancy_service->getTenancyIdCurrent());
|
|
@@ -123,30 +123,30 @@ class ONUController extends Controller
|
|
|
$em->flush();
|
|
|
$return[] = "ONU create {$onu['text']}";
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$location = $object->getLocation();
|
|
|
$action = "update";
|
|
|
- if(is_null($location)) {
|
|
|
+ if (is_null($location)) {
|
|
|
$location = new Location();
|
|
|
$em->persist($location);
|
|
|
$em->flush();
|
|
|
$object->setLocation($location);
|
|
|
$action = "create";
|
|
|
}
|
|
|
-
|
|
|
- $data = json_decode($onu['vector']['data'],true);
|
|
|
+
|
|
|
+ $data = json_decode($onu['vector']['data'], true);
|
|
|
$mapLocation = $data[0];
|
|
|
$mapLocation['zoom'] = 17;
|
|
|
$mapLocation['onu'] = "{$object->getPonSerialNumber()}";
|
|
|
$mapLocation['map_object_id'] = $onu['id'];
|
|
|
-
|
|
|
+
|
|
|
$location->setJsonExtraData($mapLocation);
|
|
|
$location->setObjectTypeId($objectTypeId);
|
|
|
$location->setMapId($mapId);
|
|
|
-
|
|
|
+
|
|
|
$em->persist($location);
|
|
|
-
|
|
|
- $return[] = "LOCATION (id {$location->getId()}) {$action} - ONU (id {$object->getId()}) {$onu['text']} - ".json_encode($mapLocation);
|
|
|
+
|
|
|
+ $return[] = "LOCATION (id {$location->getId()}) {$action} - ONU (id {$object->getId()}) {$onu['text']} - " . json_encode($mapLocation);
|
|
|
}
|
|
|
|
|
|
$em->flush();
|
|
@@ -162,7 +162,6 @@ class ONUController extends Controller
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* @param Request $request
|
|
|
* @return JsonResponse
|
|
@@ -238,9 +237,9 @@ class ONUController extends Controller
|
|
|
if (isset($extraData['lat']) && isset($extraData['lng'])) {
|
|
|
$distance = $this->distanceGeoPoints($lat, $lng, $extraData['lat'], $extraData['lng'], true);
|
|
|
// divido por 1000 para pasarlo de metros a kilometros
|
|
|
- $naps[$nap->getId()] = ['id' => $nap->getId(), 'name' => $nap->getName(), 'distance' => $distance, 'freePort' => $nap->getFreePort()];
|
|
|
+ $naps[$nap->getId()] = ['id' => $nap->getId(), 'name' => $nap->getName(), 'distance' => $distance, 'freePort' => $nap->getFreePort(), 'address' => $extraData['Address']];
|
|
|
} else {
|
|
|
- $naps[$nap->getId()] = ['id' => $nap->getId(), 'name' => $nap->getName(), 'distance' => -1, 'freePort' => $nap->getFreePort()];
|
|
|
+ $naps[$nap->getId()] = ['id' => $nap->getId(), 'name' => $nap->getName(), 'distance' => -1, 'freePort' => $nap->getFreePort(), 'address' => ''];
|
|
|
}
|
|
|
}
|
|
|
}
|