|
@@ -0,0 +1,147 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace StatsBundle\Admin;
|
|
|
+
|
|
|
+use Base\AdminBundle\Admin\BaseAdmin;
|
|
|
+use Sonata\AdminBundle\Datagrid\DatagridMapper;
|
|
|
+use Sonata\AdminBundle\Datagrid\ListMapper;
|
|
|
+use Sonata\AdminBundle\Form\FormMapper;
|
|
|
+use Sonata\AdminBundle\Show\ShowMapper;
|
|
|
+use DeviceBundle\Utils\DeviceTypes;
|
|
|
+use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
|
|
+use Sonata\AdminBundle\Route\RouteCollection;
|
|
|
+
|
|
|
+class CablemodemAdmin extends BaseAdmin
|
|
|
+{
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param DatagridMapper $datagridMapper
|
|
|
+ */
|
|
|
+ protected function configureDatagridFilters(DatagridMapper $datagridMapper)
|
|
|
+ {
|
|
|
+ $em = $this->get("doctrine.orm.entity_manager");
|
|
|
+ $deviceServer = $this->getParameter("device_server_base");
|
|
|
+ $cmtss = $em->getRepository("StatsBundle:device")->findBy(array('deviceServer' => $deviceServer, 'deviceType' => 'CablemodemBundle\Entity\CMTS'));
|
|
|
+
|
|
|
+ $choices = array();
|
|
|
+ foreach($cmtss as $cmts) {
|
|
|
+ $data = $cmts->jsonExtraData();
|
|
|
+ $name = null;
|
|
|
+ (isset($data['name']))? $name = $data['name'] : $name = $cmts->getIp();
|
|
|
+ $choices[$name] = $cmts->getDeviceId();
|
|
|
+ }
|
|
|
+
|
|
|
+ $datagridMapper
|
|
|
+ ->add('cmtsDeviceId', 'doctrine_orm_string', array(), 'choice', array('choices' => $choices))
|
|
|
+ ->add('deviceServer')
|
|
|
+ ->add('tenancyId')
|
|
|
+ ->add('ip')
|
|
|
+ ->add('mac')
|
|
|
+ ;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param ListMapper $listMapper
|
|
|
+ */
|
|
|
+ protected function configureListFields(ListMapper $listMapper)
|
|
|
+ {
|
|
|
+ $em = $this->get("doctrine.orm.entity_manager");
|
|
|
+ $servers = $em->getRepository("StatsBundle:DeviceServer")->findAll();
|
|
|
+
|
|
|
+ $cmtss_server = $urls_server = array();
|
|
|
+
|
|
|
+ foreach($servers as $deviceServer) {
|
|
|
+ $urls = $this->get('webservice')->getData($deviceServer->getUrl());
|
|
|
+ $urls_server[$deviceServer->getId()] = $urls;
|
|
|
+ $cmtss = $em->getRepository("StatsBundle:device")->findBy(array('deviceServer'=>$deviceServer, 'deviceType' => 'CablemodemBundle\Entity\CMTS'));
|
|
|
+ $cmtss_server[$deviceServer->getId()] = array();
|
|
|
+ foreach($cmtss as $cmts) {
|
|
|
+ $data = $cmts->jsonExtraData();
|
|
|
+ $name = null;
|
|
|
+ if(isset($data['name'])) $name = $data['name'];
|
|
|
+ $cmtss_server[$deviceServer->getId()][$cmts->getDeviceId()] = $name;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //print_r($urls_server);die;
|
|
|
+ $this->parameters = array('urls_server' => $urls_server, 'cmtss_server' => $cmtss_server);
|
|
|
+
|
|
|
+ $listMapper
|
|
|
+ /* ->add('deviceServer') */
|
|
|
+ //->add('extraData','string', array('template' => 'StatsBundle:CmtsInterface:base_list_field_extraData.html.twig'))
|
|
|
+ ->add('cmtsDeviceId', 'string', array('template' => 'StatsBundle:CmtsInterface:base_list_field_cmts.html.twig'))
|
|
|
+ ->add('ip')
|
|
|
+ ->addIdentifier('mac')
|
|
|
+ //->add('jsonExtraData', 'string', array('template' => 'StatsBundle:CmtsInterface:field_extra_data.html.twig'))
|
|
|
+ ->add('txPower')
|
|
|
+ ->add('rxPower')
|
|
|
+ ->add('uptime')
|
|
|
+ ->add('signal','string', array('template' => 'StatsBundle:CmtsInterface:interface_field_signal.html.twig'))
|
|
|
+ ->add('microreflection','string', array('template' => 'StatsBundle:CmtsInterface:interface_field_microreflection.html.twig'))
|
|
|
+ //->add('utilization','string', array('template' => 'StatsBundle:CmtsInterface:interface_field_utilization.html.twig'))
|
|
|
+ //->add('inOctets','string', array('template' => 'StatsBundle:CmtsInterface:interface_field_octets.html.twig'))
|
|
|
+ //->add('outOctets','string', array('template' => 'StatsBundle:CmtsInterface:interface_field_octets.html.twig'))
|
|
|
+ //->add('online','string', array('template' => 'StatsBundle:CmtsInterface:interface_field_count_cablemodem.html.twig'))
|
|
|
+ //->add('offline','string', array('template' => 'StatsBundle:CmtsInterface:interface_field_count_cablemodem.html.twig'))
|
|
|
+
|
|
|
+ ;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param FormMapper $formMapper
|
|
|
+ */
|
|
|
+ protected function configureFormFields(FormMapper $formMapper)
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param ShowMapper $showMapper
|
|
|
+ */
|
|
|
+ protected function configureShowFields(ShowMapper $showMapper)
|
|
|
+ {
|
|
|
+ $interface = $this->getSubject();
|
|
|
+ $cmtsDeviceId = $interface->getCmtsDeviceId();
|
|
|
+ $deviceServer = $interface->getDeviceServer();
|
|
|
+
|
|
|
+ $em = $this->get("doctrine.orm.entity_manager");
|
|
|
+
|
|
|
+ $cmts = $em->getRepository("StatsBundle:device")->findOneBy(array('deviceId' => $cmtsDeviceId, 'deviceServer'=>$deviceServer, 'deviceType' => 'CablemodemBundle\Entity\CMTS'));
|
|
|
+ if($cmts) {
|
|
|
+ $data = $cmts->jsonExtraData();
|
|
|
+ $cmtsName = null;
|
|
|
+ if(isset($data['name'])) $cmtsName = $data['name'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $showMapper
|
|
|
+ ->add('cmtsDeviceId', 'string', array('template' => 'StatsBundle:CmtsInterface:base_show_field_cmts.html.twig','cmtsName' => $cmtsName))
|
|
|
+ ->add('ip')
|
|
|
+ ->add('mac')
|
|
|
+ //->add('jsonExtraData', 'string', array('template' => 'StatsBundle:CmtsInterface:field_extra_data.html.twig', 'extend' => 'base_show_field.html.twig'))
|
|
|
+ ;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param string $action
|
|
|
+ * @param Object $object
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function configureActionButtons($action, $object = null)
|
|
|
+ {
|
|
|
+
|
|
|
+ $actions = parent::configureActionButtons($action, $object);
|
|
|
+ /* if($action == "show") {
|
|
|
+ $actions['show_in_map'] = array('template' => 'StatsBundle:PonPort:map_button.html.twig');
|
|
|
+ } */
|
|
|
+
|
|
|
+ return $actions;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function configureRoutes(RouteCollection $collection)
|
|
|
+ {
|
|
|
+ $collection->remove('delete');
|
|
|
+ $collection->remove('create');
|
|
|
+ $collection->remove('edit');
|
|
|
+ }
|
|
|
+
|
|
|
+}
|