Browse Source

Se setea en la nueva ONU el cliente enviado desde el form y la tenencia
actual.

Maximiliano Schvindt 7 năm trước cách đây
mục cha
commit
96038c8dec
1 tập tin đã thay đổi với 14 bổ sung14 xóa
  1. 14 14
      src/FTTHBundle/Controller/ONUController.php

+ 14 - 14
src/FTTHBundle/Controller/ONUController.php

@@ -81,12 +81,13 @@ 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) 
     {
         $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');
@@ -115,38 +116,37 @@ class ONUController extends Controller
             $object = $em->getRepository("FTTHBundle:ONU")->findOneByPonSerialNumber($onu['text']);
             if(is_null($object)) {
                 $object = new ONU();
-                $object->setClientId(1);
-                $object->setTenancyId(1);
+                $object->setClientId($clientId);
+                $object->setTenancyId($tenancy_service->getTenancyIdCurrent());
                 $object->setPonSerialNumber($onu['text']);
                 $em->persist($object);
+                $em->flush();
                 $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'];
             
+            $location = $object->getLocation();
             $action = "update";
             if(is_null($location)) {
                 $location = new Location();
                 $em->persist($location);
-                $object->setLocation($location);
-                $em->persist($object);
                 $em->flush();
+                $object->setLocation($location);
                 $action = "create";
             }
             
-            $return[] = "LOCATION (id {$location->getId()}) {$action} - ONU (id {$object->getId()}) {$onu['text']} - ".json_encode($mapLocation);
+            $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);
         }
 
         $em->flush();