get("doctrine.orm.entity_manager"); $deviceServer = $this->getParameter("device_server_base"); $olts = $em->getRepository("StatsBundle:device")->findBy(array('deviceServer' => $deviceServer, 'deviceType' => 'FTTHBundle\Entity\OLT')); $choices = array(); foreach($olts as $olt) { $data = $olt->jsonExtraData(); $name = null; (isset($data['name']))? $name = $data['name'] : $name = $olt->getIp(); $choices[$name] = $olt->getDeviceId(); } $datagridMapper ->add('oltDeviceId', 'doctrine_orm_string', array(), 'choice', array('choices' => $choices)) ->add('ponSerialNumber') ->add('ponPort') ->add('status') ; } /** * @param ListMapper $listMapper */ protected function configureListFields(ListMapper $listMapper) { $em = $this->get("doctrine.orm.entity_manager"); $servers = $em->getRepository("StatsBundle:DeviceServer")->findAll(); $olts_server = $urls_server = array(); foreach($servers as $deviceServer) { $urls = $this->get('webservice')->getData($deviceServer->getUrl()); $urls_server[$deviceServer->getId()] = $urls; $olts = $em->getRepository("StatsBundle:device")->findBy(array('deviceServer'=>$deviceServer, 'deviceType' => 'FTTHBundle\Entity\OLT')); $olts_server[$deviceServer->getId()] = array(); foreach($olts as $olt) { $data = $olt->jsonExtraData(); $name = null; if(isset($data['name'])) $name = $data['name']; $olts_server[$deviceServer->getId()][$olt->getDeviceId()] = $name; } } $this->parameters = array('urls_server' => $urls_server, 'olts_server' => $olts_server); $listMapper ->add('deviceServer') ->add('oltDeviceId', 'string', array('template' => 'StatsBundle:Onu:base_list_field_olt.html.twig')) ->add('ponSerialNumber', 'string', array('template' => 'StatsBundle:Onu:show_link.html.twig')) ->add('ponPort') ->add('status') ->add('txPower', 'string', array('template' => 'StatsBundle:Onu:base_list_field_tx.html.twig')) ->add('rxPower', 'string', array('template' => 'StatsBundle:Onu:base_list_field_rx.html.twig')) ->add('voltage', 'string', array('template' => 'StatsBundle:Onu:base_list_field_voltage.html.twig')) ->add('temperature', 'string', array('template' => 'StatsBundle:Onu:base_list_field_temperature.html.twig')) ->add('uptime', 'string', array('template' => 'StatsBundle:Onu:base_list_field_uptime.html.twig')) ->add('updated') ; } /** * @param FormMapper $formMapper */ protected function configureFormFields(FormMapper $formMapper) { } /** * @param ShowMapper $showMapper */ protected function configureShowFields(ShowMapper $showMapper) { $object = $this->getSubject(); $em = $this->get("doctrine.orm.entity_manager"); $olt = $em->getRepository("StatsBundle:device")->findOneBy(array('deviceId' => $object->getOltDeviceId(), 'deviceServer'=>$object->getDeviceServer(), 'deviceType' => 'FTTHBundle\Entity\OLT')); if($olt) { $data = $olt->jsonExtraData(); $oltName = null; if(isset($data['name'])) $oltName = $data['name']; } $showMapper ->add('oltDeviceId', 'string', array('template' => 'StatsBundle:Onu:base_show_field_olt.html.twig','oltName' => $oltName)) ->add('ponSerialNumber') ->add('ponPort') ->add('status') ->add('txPower', 'string', array('template' => 'StatsBundle:Onu:base_show_field_tx.html.twig')) ->add('rxPower', 'string', array('template' => 'StatsBundle:Onu:base_show_field_rx.html.twig')) ->add('voltage', 'string', array('template' => 'StatsBundle:Onu:base_show_field_voltage.html.twig')) ->add('temperature', 'string', array('template' => 'StatsBundle:Onu:base_show_field_temperature.html.twig')) ->add('updated', 'string', array('template' => 'StatsBundle:Onu:base_show_field_uptime.html.twig')) ; } /** * @param string $action * @param Object $object * * @return array */ public function configureActionButtons($action, $object = null) { $actions = parent::configureActionButtons($action, $object); if($action == "list") { $actions['show_in_map'] = array('template' => 'StatsBundle:Onu:map_button.html.twig'); } elseif($action == "show") { $deviceServer = $object->getDeviceServer(); $urls = $this->get('webservice')->getData($deviceServer->getUrl()); if(isset($urls['url_ftth'])) { $deviceId = $object->getDeviceId(); if(is_null($deviceId)) { if(isset($urls['api_ftth'])) { $apiOnu = "{$urls['api_ftth']}/api/onus.json"; //http://ftth:8000/api/onus.json $oltDeviceId = $object->getOltDeviceId(); $tenancyId = $object->getTenancyId(); $ponSerialNumber = $object->getPonSerialNumber(); $filters = array("tenancyId" => $tenancyId, "olt" => $oltDeviceId, "ponSerialNumber" => $ponSerialNumber); $onu = $this->get('webservice')->getData($apiOnu, $filters); if(empty($onu)) { $translator = $this->get('translator'); $flashbag = $this->get('session')->getFlashBag(); $flashbag->add("error", $translator->trans("msg_no_registered_in_ftth",array(),"StatsBundle")); $url = "{$urls['url_ftth']}/admin/ftth/onu/create?olt={$object->getOltDeviceId()}&psn={$object->getPonSerialNumber()}"; $actions['add_in_ftth'] = array('template' => 'StatsBundle:Onu:ftth_button_add.html.twig'); } elseif(isset($onu[0]['id'])) { $deviceId = $onu[0]['id']; $url = "{$urls['url_ftth']}/admin/ftth/onu/{$deviceId}/show"; $actions['show_in_ftth'] = array('template' => 'StatsBundle:Onu:ftth_button.html.twig'); } } } else { $url = "{$urls['url_ftth']}/admin/ftth/onu/{$deviceId}/show"; $actions['show_in_ftth'] = array('template' => 'StatsBundle:Onu:ftth_button.html.twig'); } $this->parameters = array('url_ftth' => $url); } } return $actions; } protected function configureRoutes(RouteCollection $collection) { $collection->remove('delete'); $collection->remove('create'); $collection->remove('edit'); } }