Browse Source

FD3-414 update ONU y OLT vars. Se agregaron métodos para OLT

Guillermo Espinoza 7 years ago
parent
commit
83e4429ea4

+ 54 - 0
app/Resources/SonataAdminBundle/views/CRUD/delete.html.twig

@@ -0,0 +1,54 @@
+{#
+
+This file is part of the Sonata package.
+
+(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+
+For the full copyright and license information, please view the LICENSE
+file that was distributed with this source code.
+
+#}
+
+{% extends base_template %}
+
+{%- block actions -%}
+    {% include 'SonataAdminBundle:CRUD:action_buttons.html.twig' %}
+{%- endblock -%}
+
+{% block tab_menu %}{{ knp_menu_render(admin.sidemenu(action), {'currentClass' : 'active', 'template': sonata_admin.adminPool.getTemplate('tab_menu_template')}, 'twig') }}{% endblock %}
+
+{% block content %}
+    <div class="sonata-ba-delete">
+
+        <div class="box box-danger">
+            <div class="box-header">
+                <h3 class="box-title">{{ 'title_delete'|trans({}, 'SonataAdminBundle') }}</h3>
+            </div>
+            <div class="box-body">
+                {{ 'message_delete_confirmation'|trans({'%object%': admin.toString(object)}, 'SonataAdminBundle') }}
+
+                {# Muestro mensaje con las entidades relacionadas a eliminar #}
+                {% set pre_remove_entities_message = pre_remove_entities_message(object) %}
+                {% if pre_remove_entities_message != '' %}
+                <br /><br />{{ pre_remove_entities_message|raw }}
+                {% endif %}
+
+            </div>
+            <div class="box-footer clearfix">
+                <form method="POST" action="{{ admin.generateObjectUrl('delete', object) }}">
+                    <input type="hidden" name="_method" value="DELETE">
+                    <input type="hidden" name="_sonata_csrf_token" value="{{ csrf_token }}">
+
+                    <button type="submit" class="btn btn-danger"><i class="fa fa-trash" aria-hidden="true"></i> {{ 'btn_delete'|trans({}, 'SonataAdminBundle') }}</button>
+
+                    {% if admin.hasRoute('edit') and admin.hasAccess('edit', object) %}
+                        {{ 'delete_or'|trans({}, 'SonataAdminBundle') }}
+                        <a class="btn btn-success" href="{{ admin.generateObjectUrl('edit', object) }}">
+                            <i class="fa fa-pencil" aria-hidden="true"></i>
+                            {{ 'link_action_edit'|trans({}, 'SonataAdminBundle') }}</a>
+                    {% endif %}
+                </form>
+            </div>
+        </div>
+    </div>
+{% endblock %}

+ 2 - 2
composer.lock

@@ -1464,7 +1464,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@200.50.168.30:222/VendorSoftwareFlowdat3/BaseAdmin.git",
-                "reference": "63444b34bcb0d5f97eb72265c3e04c3e744e84b3"
+                "reference": "45b0f11a005796b61f27e933fb2f31e853d2a84f"
             },
             "type": "library",
             "autoload": {
@@ -1479,7 +1479,7 @@
                 "bootstrap",
                 "sonata"
             ],
-            "time": "2017-12-26 15:41:06"
+            "time": "2018-01-09 14:48:22"
         },
         {
             "name": "ik/device-bundle",

+ 21 - 3
src/FTTHBundle/Entity/OLT.php

@@ -2,6 +2,7 @@
 
 namespace FTTHBundle\Entity;
 
+use Base\AdminBundle\Interfaces\PreRemoveInterface;
 use Base\AdminBundle\Traits\TenancyIdTrait;
 use Base\AdminBundle\Traits\TenancyIdTraitInterface;
 use Doctrine\ORM\Mapping as ORM;
@@ -23,7 +24,7 @@ use WorkflowBundle\Entity\Traits\WorkflowTrait;
  *
  * @ValidatorAssert\Device
  */
-class OLT implements DeviceInterface, TenancyIdTraitInterface, LocationInterface, WorkflowInterface
+class OLT implements DeviceInterface, TenancyIdTraitInterface, LocationInterface, WorkflowInterface, PreRemoveInterface
 {
 
     use ExtraDataTrait;
@@ -93,14 +94,14 @@ class OLT implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
     protected $model;
 
     /**
-     * @ORM\OneToMany(targetEntity="ONU", mappedBy="olt", fetch="EXTRA_LAZY")
+     * @ORM\OneToMany(targetEntity="ONU", mappedBy="olt", fetch="EXTRA_LAZY", cascade={"remove"})
      *
      * @JMS\MaxDepth(2)
      */
     protected $onus;
 
     /**
-     * @ORM\OneToMany(targetEntity="NAP", mappedBy="olt", fetch="EXTRA_LAZY")
+     * @ORM\OneToMany(targetEntity="NAP", mappedBy="olt", fetch="EXTRA_LAZY", cascade={"remove"})
      *
      * @JMS\MaxDepth(2)
      */
@@ -528,4 +529,21 @@ class OLT implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
         return $this->libraryVersion;
     }
 
+    /**
+     * @return array
+     */
+    public function getEntitiesForRemove()
+    {
+        $entities = [];
+        if ($this->onus->count() != 0) {
+            $entities['onus'] = $this->onus;
+        }
+
+        if ($this->naps->count() != 0) {
+            $entities['naps'] = $this->naps;
+        }
+
+        return $entities;
+    }
+
 }

+ 3 - 0
src/FTTHBundle/Entity/ONU.php

@@ -113,6 +113,8 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
 
     /**
      * @ORM\ManyToOne(targetEntity="OLT", inversedBy="onus", fetch="EXTRA_LAZY")
+     * @ORM\JoinColumn(onDelete="SET NULL")
+     *
      * @JMS\MaxDepth(1)
      */
     protected $olt;
@@ -126,6 +128,7 @@ class ONU implements DeviceInterface, TenancyIdTraitInterface, LocationInterface
 
     /**
      * @ORM\ManyToOne(targetEntity="NAP", inversedBy="onus", fetch="EXTRA_LAZY")
+     * @ORM\JoinColumn(onDelete="SET NULL")
      *
      * @JMS\MaxDepth(1)
      */