Kaynağa Gözat

FD3-478 FD3-479 eliminación de HostType y NetGroup

Guillermo Espinoza 7 yıl önce
ebeveyn
işleme
d61d9e5c78

+ 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 %}

+ 1 - 1
composer.lock

@@ -6278,7 +6278,7 @@
         "voryx/restgeneratorbundle": 20
     },
     "prefer-stable": false,
-    "prefer-lowest": true,
+    "prefer-lowest": false,
     "platform": {
         "php": ">=5.5.9"
     },

+ 2 - 1
src/IPv4Bundle/Entity/Host.php

@@ -39,7 +39,8 @@ class Host
     /**
      * @var HostType $hostType
      *
-     * @ORM\ManyToOne(targetEntity="HostType")
+     * @ORM\ManyToOne(targetEntity="HostType", inversedBy="hosts")
+     * @ORM\JoinColumn(onDelete="CASCADE")
      */
     protected $hostType;
 

+ 30 - 1
src/IPv4Bundle/Entity/HostType.php

@@ -2,12 +2,13 @@
 
 namespace IPv4Bundle\Entity;
 
+use Base\AdminBundle\Interfaces\PreRemoveInterface;
 use Doctrine\ORM\Mapping as ORM;
 
 /**
  * @ORM\Entity
  */
-class HostType
+class HostType implements PreRemoveInterface
 {
 
     /**
@@ -41,6 +42,17 @@ class HostType
     protected $opcode;
 
 
+    /**
+     * @ORM\OneToMany(targetEntity="Host", mappedBy="hostType")
+     */
+    protected $hosts;
+
+    /**
+     * @ORM\OneToMany(targetEntity="SubNet", mappedBy="allowedHostType")
+     */
+    protected $subNets;
+
+
     /**
     * @return string
     */
@@ -117,4 +129,21 @@ class HostType
         return $this->opcode;
     }
 
+    /**
+     * @return array
+     */
+    public function getEntitiesForRemove()
+    {
+        $entities = [];
+        if ($this->hosts->count() != 0) {
+            $entities['hosts'] = $this->hosts;
+        }
+
+        if ($this->subNets->count() != 0) {
+            $entities['subNets'] = $this->subNets;
+        }
+
+        return $entities;
+    }
+
 }

+ 24 - 1
src/IPv4Bundle/Entity/NetGroup.php

@@ -2,6 +2,7 @@
 
 namespace IPv4Bundle\Entity;
 
+use Base\AdminBundle\Interfaces\PreRemoveInterface;
 use Base\AdminBundle\Traits\TenancyIdTrait;
 use Base\AdminBundle\Traits\TenancyIdTraitInterface;
 use Doctrine\ORM\Mapping as ORM;
@@ -15,7 +16,7 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  * @UniqueEntity("name")
  * @UniqueEntity("opcode")
  */
-class NetGroup implements TenancyIdTraitInterface
+class NetGroup implements TenancyIdTraitInterface, PreRemoveInterface
 {
 
     use TenancyIdTrait;
@@ -33,6 +34,8 @@ class NetGroup implements TenancyIdTraitInterface
      * @var string $name
      *
      * @ORM\Column(type="string", length=100, unique=true)
+     *
+     * @Assert\NotBlank
      */
     protected $name;
 
@@ -40,9 +43,16 @@ class NetGroup implements TenancyIdTraitInterface
      * @var string $opcode
      *
      * @ORM\Column(type="integer", unique=true)
+     *
+     * @Assert\NotBlank
      */
     protected $opcode;
 
+    /**
+     * @ORM\OneToMany(targetEntity="SubNet", mappedBy="netGroup")
+     */
+    protected $subNets;
+
 
     /**
     * @return string
@@ -100,4 +110,17 @@ class NetGroup implements TenancyIdTraitInterface
         return $this->opcode;
     }
 
+    /**
+     * @return array
+     */
+    public function getEntitiesForRemove()
+    {
+        $entities = [];
+        if ($this->subNets->count() != 0) {
+            $entities['subNets'] = $this->subNets;
+        }
+
+        return $entities;
+    }
+
 }

+ 4 - 2
src/IPv4Bundle/Entity/SubNet.php

@@ -41,7 +41,8 @@ class SubNet implements TenancyIdTraitInterface
     /**
      * @var HostType $allowedHostType
      *
-     * @ORM\ManyToOne(targetEntity="HostType")
+     * @ORM\ManyToOne(targetEntity="HostType", inversedBy="subNets")
+     * @ORM\JoinColumn(onDelete="CASCADE")
      */
     protected $allowedHostType;
 
@@ -55,7 +56,8 @@ class SubNet implements TenancyIdTraitInterface
     /**
      * @var NetGroup $netGroup
      *
-     * @ORM\ManyToOne(targetEntity="NetGroup")
+     * @ORM\ManyToOne(targetEntity="NetGroup", inversedBy="subNets")
+     * @ORM\JoinColumn(onDelete="CASCADE")
      */
     protected $netGroup;