|
@@ -9,14 +9,17 @@ use ExtraDataBundle\Entity\Traits\ExtraDataTrait;
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
use Symfony\Component\Yaml\Yaml;
|
|
|
+use Base\AdminBundle\Interfaces\PreRemoveBlockCascadeInterface;
|
|
|
+use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
|
|
|
+use Sonata\AdminBundle\Exception\ModelManagerException;
|
|
|
|
|
|
/**
|
|
|
* @ORM\Entity
|
|
|
* @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(name="unique_idx", columns={"name","tenancy_id"})})
|
|
|
- *
|
|
|
+ * @ORM\HasLifecycleCallbacks
|
|
|
* @UniqueEntity(fields={"tenancyId","name"})
|
|
|
*/
|
|
|
-class Profile implements TenancyIdTraitInterface
|
|
|
+class Profile implements TenancyIdTraitInterface, PreRemoveBlockCascadeInterface
|
|
|
{
|
|
|
|
|
|
use TenancyIdTrait;
|
|
@@ -88,6 +91,11 @@ class Profile implements TenancyIdTraitInterface
|
|
|
* @ORM\Column(type="string", nullable=true)
|
|
|
*/
|
|
|
protected $template;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @ORM\OneToMany(targetEntity="Cablemodem", mappedBy="profile", fetch="EXTRA_LAZY")
|
|
|
+ */
|
|
|
+ protected $cablemodems;
|
|
|
|
|
|
|
|
|
public function __construct()
|
|
@@ -95,6 +103,7 @@ class Profile implements TenancyIdTraitInterface
|
|
|
$this->downstream = $this->getDefault('downstream');
|
|
|
$this->upstream = $this->getDefault('upstream');
|
|
|
$this->template = $this->getDefault('template');
|
|
|
+ $this->cablemodems = new \Doctrine\Common\Collections\ArrayCollection();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -306,4 +315,62 @@ class Profile implements TenancyIdTraitInterface
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param Cablemodem $cablemodem
|
|
|
+ * @return Profile
|
|
|
+ */
|
|
|
+ public function addCablemodem(Cablemodem $cablemodem)
|
|
|
+ {
|
|
|
+ $this->cablemodems[] = $cablemodem;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param Cablemodem $cablemodem
|
|
|
+ * @return Profile
|
|
|
+ */
|
|
|
+ public function removeCablemodem(Cablemodem $cablemodem)
|
|
|
+ {
|
|
|
+ $this->cablemodems->removeElement($cablemodem);
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return Doctrine\Common\Collections\Collection
|
|
|
+ */
|
|
|
+ public function getCablemodems()
|
|
|
+ {
|
|
|
+ return $this->cablemodems;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getEntitiesForRemove()
|
|
|
+ {
|
|
|
+ $entities = [];
|
|
|
+ if ($this->cablemodems->count() != 0) {
|
|
|
+ $entities['cablemodems'] = $this->cablemodems;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $entities;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @ORM\PreRemove
|
|
|
+ */
|
|
|
+ public function preRemove(LifecycleEventArgs $event)
|
|
|
+ {
|
|
|
+ $em = $event->getEntityManager();
|
|
|
+ $entity = $event->getEntity();
|
|
|
+
|
|
|
+ if (count($entity->getCablemodems()) > 0) {
|
|
|
+ $error = "This profile has connected cablemodems, so it can't be removed.";
|
|
|
+ throw new ModelManagerException($error);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|