瀏覽代碼

FD3-576 se muestra host cablemodem, cpe y mta en show de Cablemodem

Espinoza Guillermo 7 年之前
父節點
當前提交
c7f017c2df

+ 32 - 4
src/CablemodemBundle/Admin/CablemodemAdmin.php

@@ -108,6 +108,9 @@ class CablemodemAdmin extends WorkflowBaseAdmin
     }
 
     /**
+     * Agrega en la vista show de Cablemodem un tab DHCP mostrando
+     * Host Cablemodem, CPE y MTA si tiene asociado
+     *
      * @param ShowMapper $showMapper
      */
     protected function addDHCPTab(ShowMapper $showMapper)
@@ -117,14 +120,39 @@ class CablemodemAdmin extends WorkflowBaseAdmin
             ->end()
             ->end();
         }
+        $template = 'CablemodemBundle:CRUD:host_show_field.html.twig';
+        
+        $types = [
+            'Mta',
+            'Cpe',
+        ];
+        
         $showMapper
         ->tab('DHCP')
         ->with('Host')
-        ->add('host', null, array(
-            'template' => 'CablemodemBundle:CRUD:host_show_field.html.twig',
-        ))
-        ->end()
+        ->add('host', null, [
+            'template' => $template,
+        ])
         ->end();
+        
+        foreach ($types as $type) {
+            $method = "get{$type}FixedIp";
+            if ($this->getSubject()->$method()) {
+                $showMapper
+                    ->with($type)
+                    ->add($type, null, [
+                        'template' => $template,
+                        'data' => [
+                            'hostType' => [
+                                $type => $this->get('cablemodem.host_service')->getIdHostType(strtoupper($type)),
+                                ],
+                            ],
+                    ])
+                    ->end();
+            }
+        }
+        
+        $showMapper->end();
     }
 
 }

+ 4 - 0
src/CablemodemBundle/Resources/config/services.yml

@@ -53,3 +53,7 @@ services:
         calls:
             - [setTranslationDomain, [CablemodemBundle]]
         public: true
+        
+    cablemodem.host_service:
+        class: CablemodemBundle\Services\HostService
+        arguments: [ "%dhcp_host_type_get_url%", "@webservice" ]

+ 15 - 1
src/CablemodemBundle/Resources/views/CRUD/host_show_field.html.twig

@@ -1,16 +1,29 @@
 {% set host = get_json('dhcp_host_post_url', { mac: object.mac }) %}
 
+{% if host and object.mtaFixedIP and field_description.options.data is defined and 'Mta' in field_description.options.data.hostType|keys %}
+{% set host = get_json('dhcp_host_post_url', { host: host.id, hostType: field_description.options.data.hostType.Mta }) %}
+{% endif %}
+
+{% if host and object.cpeFixedIP and field_description.options.data is defined and 'Cpe' in field_description.options.data.hostType|keys %}
+{% set host = get_json('dhcp_host_post_url', { host: host.id, hostType: field_description.options.data.hostType.Cpe }) %}
+{% endif %}
+
 {% block field %}
+
 {% if host %}
 <td>
 <table class="table">
     <tbody>
+        {% if host.mac %}
         <tr class="sonata-ba-view-container">
             <th>{{ 'Mac'|trans({}, 'CablemodemBundle') }}</th><td>{{ host.mac }}</td>
         </tr>
+        {% endif %}
+        {% if host.options %}
         <tr class="sonata-ba-view-container">
             <th>{{ 'Options'|trans({}, 'CablemodemBundle') }}</th><td>{{ host.options }}</td>
         </tr>
+        {% endif %}
         <tr class="sonata-ba-view-container">
             <th>{{ 'HostType'|trans({}, 'CablemodemBundle') }}</th><td>{{ host.hostType.name }}</td>
         </tr>
@@ -21,4 +34,5 @@
 </table>
 </td>
 {% endif %}
-{% endblock %}
+
+{% endblock %}

+ 51 - 0
src/CablemodemBundle/Services/HostService.php

@@ -0,0 +1,51 @@
+<?php
+
+namespace CablemodemBundle\Services;
+
+use Buzz\Message\RequestInterface as HttpRequestInterface;
+use WebserviceBundle\Services\Webservice;
+
+class HostService
+{
+    
+    /**
+     * @var Webservice
+     */
+    private $webservice;
+    
+    /**
+     * @var string
+     */
+    private $dhcpHostTypeGetUrl;
+    
+    
+    /**
+     * @param string $dhcpHostTypeGetUrl
+     * @param Webservice $webservice
+     */
+    public function __construct($dhcpHostTypeGetUrl, Webservice $webservice)
+    {
+        $this->dhcpHostTypeGetUrl = $dhcpHostTypeGetUrl;
+        $this->webservice = $webservice;
+    }
+    
+    /**
+     * @param string $name HostType name Cablemodem | MTA | CPE
+     *
+     * @return int
+     */
+    public function getIdHostType($name = 'Cablemodem', $url = null)
+    {
+        $url = $this->webservice->buildUrl($url ?: $this->dhcpHostTypeGetUrl, [
+            'name' => $name,
+        ]);
+        
+        $hostType = null;
+        if ($hostTypeJSON = $this->webservice->makeGetRequest($url, HttpRequestInterface::METHOD_GET, [])) {
+            $hostType = current(json_decode($hostTypeJSON, true))['id'];
+        }
+        
+        return $hostType;
+    }
+    
+}