浏览代码

FD3-674 refactory ONUSubscriber. Seteo por default de vlanProfile y onuProfile en ONU

Espinoza Guillermo 6 年之前
父节点
当前提交
ac311f39c8
共有 1 个文件被更改,包括 58 次插入9 次删除
  1. 58 9
      src/FTTHBundle/EventListener/ONUSubscriber.php

+ 58 - 9
src/FTTHBundle/EventListener/ONUSubscriber.php

@@ -5,6 +5,11 @@ namespace FTTHBundle\EventListener;
 use Doctrine\Common\EventSubscriber;
 use Doctrine\ORM\Event\LifecycleEventArgs;
 use FTTHBundle\Entity\ONU;
+use FTTHBundle\Entity\ONUProfile;
+use FTTHBundle\Entity\VLanID;
+use FTTHBundle\Entity\VLanProfile;
+use FTTHBundle\Entity\TContProfile;
+use FTTHBundle\Entity\TrafficProfile;
 use Symfony\Component\HttpFoundation\Session\SessionInterface;
 use Symfony\Component\Translation\TranslatorInterface;
 use WorkflowBundle\Utils\DoctrineEvents;
@@ -125,9 +130,21 @@ class ONUSubscriber implements EventSubscriber
                 }
             }
             
-            if (!$entity->getTrafficProfile()) $this->assignTrafficProfile($args);
-            if (!$entity->getTcontprofile()) $this->assignTConProfile($args);
-            if (!$entity->getVlan()) $this->assignVLanId($args);
+            if (!$entity->getTrafficProfile()) {
+                $this->assignTrafficProfile($args);
+            }
+            if (!$entity->getVlanProfile()) {
+                $this->assignVlanProfile($args);
+            }
+            if (!$entity->getONUProfile()) {
+                $this->assignONUProfile($args);
+            }
+            if (!$entity->getTcontprofile()) {
+                $this->assignTConProfile($args);
+            }
+            if (!$entity->getVlan()) {
+                $this->assignVLanId($args);
+            }
 
             if ($eventName == DoctrineEvents::PRE_UPDATE) {
                 $uow = $this->em->getUnitOfWork();
@@ -181,9 +198,9 @@ class ONUSubscriber implements EventSubscriber
     public function assignTrafficProfile(LifecycleEventArgs $args)
     {
         $obj = $args->getEntityManager()
-                ->getRepository("FTTHBundle:TrafficProfile")
+                ->getRepository(TrafficProfile::class)
                 ->findOneBy(array(
-                    "usedByDefault" => true
+                    "usedByDefault" => true,
                 ));
         if ($obj) {
             $args->getEntity()->setTrafficProfileOut($obj);
@@ -191,6 +208,38 @@ class ONUSubscriber implements EventSubscriber
         }
     }
     
+    /**
+     * @param LifecycleEventArgs $args
+     * @param string $eventName
+     */
+    public function assignVlanProfile(LifecycleEventArgs $args)
+    {
+        $obj = $args->getEntityManager()
+                ->getRepository(VLanProfile::class)
+                ->findOneBy(array(
+                    "usedByDefault" => true,
+                ));
+        if ($obj) {
+            $args->getEntity()->setVlanProfile($obj);
+        }
+    }
+    
+    /**
+     * @param LifecycleEventArgs $args
+     * @param string $eventName
+     */
+    public function assignONUProfile(LifecycleEventArgs $args)
+    {
+        $obj = $args->getEntityManager()
+                ->getRepository(ONUProfile::class)
+                ->findOneBy(array(
+                    "usedByDefault" => true,
+                ));
+        if ($obj) {
+            $args->getEntity()->setONUProfile($obj);
+        }
+    }
+    
     /**
      * @param LifecycleEventArgs $args
      * @param string $eventName
@@ -198,9 +247,9 @@ class ONUSubscriber implements EventSubscriber
     public function assignTConProfile(LifecycleEventArgs $args)
     {
         $obj = $args->getEntityManager()
-                ->getRepository("FTTHBundle:TContProfile")
+                ->getRepository(TContProfile::class)
                 ->findOneBy(array(
-                    "usedByDefault" => true
+                    "usedByDefault" => true,
                 ));
         if ($obj) {
             $args->getEntity()->setTcontprofile($obj);
@@ -214,9 +263,9 @@ class ONUSubscriber implements EventSubscriber
     public function assignVLanId(LifecycleEventArgs $args)
     {
         $obj = $args->getEntityManager()
-                ->getRepository("FTTHBundle:VLanID")
+                ->getRepository(VLanID::class)
                 ->findOneBy(array(
-                    "usedByDefault" => true
+                    "usedByDefault" => true,
                 ));
         if ($obj) {
             $args->getEntity()->setVlan($obj);