Browse Source

Se crea clave compuesta para poder acceder a los elementos independientemente del id que tengan. Esto sigue en sintonía con la ONUs que también utilizan claves compuestas.

Maxi Schvindt 7 years ago
parent
commit
5270c69987

+ 1 - 1
src/StatsBundle/Admin/CablemodemAdmin.php

@@ -83,7 +83,7 @@ class CablemodemAdmin extends BaseAdmin
         $listMapper
             ->add('cmtsDeviceId', 'string', array('template' => 'StatsBundle:CmtsInterface:base_list_field_cmts.html.twig'))
             ->add('ip')
-            ->addIdentifier('mac')
+            ->add('mac', 'string', array('template' => 'StatsBundle:Cablemodem:show_link.html.twig'))
             ->add('index')
             ->add('upIf',null, array('template' => 'StatsBundle:Cablemodem:field_interface_index.html.twig','typeIf' => 'upstream'))
             ->add('downIf',null, array('template' => 'StatsBundle:Cablemodem:field_interface_index.html.twig','typeIf' => 'downstream'))

+ 1 - 0
src/StatsBundle/Admin/CmtsInterfaceAdmin.php

@@ -127,6 +127,7 @@ class CmtsInterfaceAdmin extends BaseAdmin
             $row['txPower'] = $cm->getTxPower();
             $row['rxPower'] = $cm->getRxPower();
             $row['rxPowerCmts'] = $cm->getRxPowerCmts();
+            $row['cm'] = $cm;
 
             $_cms[$index] = $row;
 

+ 46 - 0
src/StatsBundle/Controller/CablemodemCRUDController.php

@@ -0,0 +1,46 @@
+<?php
+
+namespace StatsBundle\Controller;
+
+use Base\AdminBundle\Controller\CRUDController;
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
+use Symfony\Component\Security\Core\Exception\AccessDeniedException;
+
+class CablemodemCRUDController extends CRUDController
+{
+
+    /**
+     * Show action.
+     *
+     * @param int|string|null $id
+     *
+     * @return Response
+     *
+     * @throws NotFoundHttpException If the object does not exist
+     * @throws AccessDeniedException If access is not granted
+     */
+    public function showAction($id = null)
+    {
+        $request = $this->getRequest();
+        $id = $request->get($this->admin->getIdParameter());
+
+        $object = $this->admin->getRepository('StatsBundle:Cablemodem')->findByCustomId($id);
+
+        $this->admin->checkAccess('show', $object);
+
+        $preResponse = $this->preShow($request, $object);
+        if ($preResponse !== null) {
+            return $preResponse;
+        }
+
+        $this->admin->setSubject($object);
+
+        return $this->render($this->admin->getTemplate('show'), array(
+                    'action' => 'show',
+                    'object' => $object,
+                    'elements' => $this->admin->getShow(),
+                        ), null);
+    }
+
+}

+ 18 - 2
src/StatsBundle/Entity/Cablemodem.php

@@ -13,7 +13,7 @@ use Base\AdminBundle\Traits\TenancyIdTraitInterface;
 
 /**
  * @ORM\Table
- * @ORM\Entity
+ * @ORM\Entity(repositoryClass="StatsBundle\Repository\CablemodemRepository")
  * @UniqueEntity(fields={"deviceServer", "cmtsDeviceId", "mac"}, message="errors.duplicate_key")
  * @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(name="unique_idx", columns={"device_server_id", "cmts_device_id", "mac"})})
  */
@@ -262,7 +262,7 @@ class Cablemodem implements TenancyIdTraitInterface
      */
     public function getMac()
     {
-        return $this->mac;
+        return strtoupper($this->mac);
     }
 
     /**
@@ -715,4 +715,20 @@ class Cablemodem implements TenancyIdTraitInterface
     {
         return $this->microreflectionCmts;
     }
+
+    /**
+     * @return string
+     */
+    public function getCustomId()
+    {
+        return sprintf('%s~%s~%s', strtolower($this->mac), $this->cmtsDeviceId, $this->deviceServer->getId());
+    }
+
+    /**
+     * @return string
+     */
+    public function __toString()
+    {
+        return sprintf('%s', strtoupper($this->mac));
+    }
 }

+ 26 - 0
src/StatsBundle/Repository/CablemodemRepository.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace StatsBundle\Repository;
+
+class CablemodemRepository extends \Doctrine\ORM\EntityRepository
+{
+
+    /**
+     * @param string $customId
+     * 
+     * @return Onu|null
+     */
+    public function findByCustomId($customId)
+    {
+        list($mac, $cmtsDeviceId, $deviceServerId) = explode('~', $customId);
+        $qb = $this->createQueryBuilder('Cablemodem')
+            ->join('Cablemodem.deviceServer', 'deviceServer')
+            ->where('Cablemodem.mac = :mac')->setParameter('mac', $mac)
+            ->andWhere('Cablemodem.cmtsDeviceId = :cmtsDeviceId')->setParameter('cmtsDeviceId', $cmtsDeviceId)
+            ->andWhere('deviceServer.id = :deviceServerId')->setParameter('deviceServerId', $deviceServerId)
+        ;
+
+        return $qb->getQuery()->getOneOrNullResult();
+    }
+
+}

+ 1 - 1
src/StatsBundle/Resources/config/services.yml

@@ -64,7 +64,7 @@ services:
     
     stats.admin.cablemodem:
         class: StatsBundle\Admin\CablemodemAdmin
-        arguments: [~, StatsBundle\Entity\Cablemodem, SonataAdminBundle:CRUD]
+        arguments: [~, StatsBundle\Entity\Cablemodem, StatsBundle:CablemodemCRUD]
         tags:
             - { name: sonata.admin, manager_type: orm, group: List, label: Cablemodem, label_catalogue: StatsBundle, label_translator_strategy: sonata.admin.label.strategy.underscore }
         calls:    

+ 3 - 0
src/StatsBundle/Resources/views/Cablemodem/show_link.html.twig

@@ -0,0 +1,3 @@
+<td>
+    <a href="{{ path('admin_stats_cablemodem_show', { 'id': object.getCustomId() }) }}">{{ object.getMac() }}</a>
+</td>

+ 2 - 2
src/StatsBundle/Resources/views/CmtsInterface/base_show.html.twig

@@ -31,8 +31,8 @@
                                         <td>{{cm['index']}}</td>
                                         <td>{% include 'StatsBundle:Templates:macro_status.html.twig' with {'value': cm['status']} only %}</td>
                                         <td>{{cm['ip']}}</td>
-                                        <td>{{cm['mac']}}</td>
-                                        {# <td><a href="{{ path('admin_stats_cablemodem_show', { 'id': o.getCustomId() }) }}">{{ o.getPonSerialNumber() }}</a></td> #}
+                                        {# <td>{{cm['mac']}}</td> #}
+                                        {% include 'StatsBundle:Cablemodem:show_link.html.twig' with {'object': cm['cm']} only %}
                                         <td>{% include 'StatsBundle:Templates:cm_field_rx.html.twig' with {'value': cm['rxPower']} only %}</td>
                                         <td>{% include 'StatsBundle:Templates:cm_field_tx.html.twig' with {'value': cm['txPower']} only %}</td>
                                         <td>{% include 'StatsBundle:Templates:cm_field_rx.html.twig' with {'value': cm['rxPowerCmts']} only %}</td>