Bläddra i källkod

FD3-222 CRUDController para Onu

Guillermo Espinoza 7 år sedan
förälder
incheckning
6ac1b0bcb8

+ 1 - 6
src/StatsBundle/Admin/OnuAdmin.php

@@ -52,15 +52,13 @@ class OnuAdmin extends BaseAdmin
             }
         }
 
-        //print_r($urls_server);die;
         $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('tenancyId')
-            ->addIdentifier('ponSerialNumber')
+            ->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'))
@@ -69,9 +67,6 @@ class OnuAdmin extends BaseAdmin
             ->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')
-            /* ->add('_action', null, array(
-                'actions' => array('show' => array())
-                )) */
         ;
     }
 

+ 46 - 0
src/StatsBundle/Controller/OnuCRUDController.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 OnuCRUDController 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:Onu')->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);
+    }
+
+}

+ 1 - 1
src/StatsBundle/Entity/Onu.php

@@ -8,7 +8,7 @@ use Symfony\Component\Validator\Constraints as Assert;
 
 /**
  * @ORM\Table
- * @ORM\Entity
+ * @ORM\Entity(repositoryClass="StatsBundle\Repository\OnuRepository")
  * @UniqueEntity(fields={"deviceServer", "oltDeviceId", "ponSerialNumber"}, message="errors.duplicate_key")
  * @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(name="unique_idx", columns={"device_server_id", "olt_device_id", "pon_serial_number"})})
  */

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

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

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

@@ -23,7 +23,7 @@ services:
     
     stats.admin.onu:
         class: StatsBundle\Admin\OnuAdmin
-        arguments: [~, StatsBundle\Entity\Onu, SonataAdminBundle:CRUD]
+        arguments: [~, StatsBundle\Entity\Onu, StatsBundle:OnuCRUD]
         tags:
             - { name: sonata.admin, manager_type: orm, group: List, label: ONU, label_catalogue: StatsBundle, label_translator_strategy: sonata.admin.label.strategy.underscore }
         calls:    

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

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

+ 1 - 1
src/StatsBundle/Resources/views/PonPort/base_show.html.twig

@@ -22,7 +22,7 @@
                                 {% set o = onu['onu'] %}
                                 <tr class="sonata-ba-view-container">
                                     <td>{{o.getPonPort()}}</td>
-                                    <td><a href="{{path('admin_stats_onu_show',{'id': o.getId() })}}">{{o.getPonSerialNumber()}}</a></td>
+                                    <td><a href="{{ path('admin_stats_onu_show', { 'id': o.getCustomId() }) }}">{{ o.getPonSerialNumber() }}</a></td>
                                     <td>{% include 'StatsBundle:Templates:onu_field_rx.html.twig' with {'value': onu['rxPower']} only %}</td>
                                     <td>{% include 'StatsBundle:Templates:onu_field_tx.html.twig' with {'value': o.getTxPower()} only %}</td>
                                     <td>{% include 'StatsBundle:Templates:onu_field_rx.html.twig' with {'value': o.getRxPower()} only %}</td>