123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- <?php
- namespace CablemodemBundle\Entity;
- use Base\AdminBundle\Traits\TenancyIdTrait;
- use Base\AdminBundle\Traits\TenancyIdTraitInterface;
- use Doctrine\ORM\Mapping as ORM;
- 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, PreRemoveBlockCascadeInterface
- {
- use TenancyIdTrait;
- use ExtraDataTrait;
- /**
- * @var bigint $id
- *
- * @ORM\Column(name="id", type="bigint", nullable=false)
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="IDENTITY")
- */
- private $id;
- /**
- * @var string $name
- *
- * @ORM\Column(name="name", type="string", length=100)
- *
- * @Assert\NotNull
- * @Assert\Regex(
- * pattern="/[\w\s\d]+/",
- * match=true,
- * message="El campo contiene caracteres especiales"
- * )
- */
- protected $name;
- /**
- * @var bigint $downstream
- *
- * @ORM\Column(type="bigint", nullable=true)
- */
- protected $downstream;
- /**
- * @var bigint $upstream
- *
- * @ORM\Column(type="bigint", nullable=true)
- */
- protected $upstream;
- /**
- * @var bigint $filtroUpload
- *
- * @ORM\Column(type="bigint", nullable=true)
- */
- protected $filtroUpload;
- /**
- * @var bigint $filtroDownload
- *
- * @ORM\Column(type="bigint", nullable=true)
- */
- protected $filtroDownload;
- /**
- * @var bigint $maxCpe
- *
- * @ORM\Column(type="bigint", nullable=true)
- */
- protected $maxCpe;
-
- /**
- * @var string $template
- *
- * @ORM\Column(type="string", nullable=true)
- */
- protected $template;
- /**
- * @ORM\OneToMany(targetEntity="Cablemodem", mappedBy="profile", fetch="EXTRA_LAZY")
- */
- protected $cablemodems;
-
- public function __construct()
- {
- $this->downstream = $this->getDefault('downstream');
- $this->upstream = $this->getDefault('upstream');
- $this->template = $this->getDefault('template');
- $this->cablemodems = new \Doctrine\Common\Collections\ArrayCollection();
- }
- /**
- * @return string
- */
- public function __toString()
- {
- return (string)$this->name;
- }
- /**
- * @return int
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * @return string
- */
- public function getName()
- {
- return $this->name;
- }
- /**
- * @return bigint
- */
- public function getDownstream()
- {
- return $this->downstream ? $this->downstream : $this->getDefault('downstream');
- }
- /**
- * @return bigint
- */
- public function getUpstream()
- {
- return $this->upstream ? $this->upstream : $this->getDefault('upstream');
- }
- /**
- * @return bigint
- */
- public function getFiltroUpload()
- {
- return $this->filtroUpload;
- }
- /**
- * @return bigint
- */
- public function getFiltroDownload()
- {
- return $this->filtroDownload;
- }
- /**
- * @return bigint
- */
- public function getMaxCpe()
- {
- return $this->maxCpe ? $this->maxCpe : $this->getDefault('max_cpe');
- }
- /**
- * @param string $name
- *
- * @return $this
- */
- public function setName($name)
- {
- $this->name = $name;
- return $this;
- }
- /**
- * @param bigint $downstream
- *
- * @return $this
- */
- public function setDownstream($downstream)
- {
- if(is_null($downstream)) {
- $this->downstream = $this->getDefault('downstream');
- } else {
- $this->downstream = $downstream;
- }
-
- return $this;
- }
- /**
- * @param bigint $upstream
- *
- * @return $this
- */
- public function setUpstream($upstream)
- {
- if(is_null($upstream)) {
- $this->upstream = $this->getDefault('upstream');
- } else {
- $this->upstream = $upstream;
- }
- return $this;
- }
- /**
- * @param bigint $filtroUpload
- *
- * @return $this
- */
- public function setFiltroUpload($filtroUpload)
- {
- $this->filtroUpload = $filtroUpload;
- return $this;
- }
- /**
- * @param bigint $filtroDownload
- *
- * @return $this
- */
- public function setFiltroDownload($filtroDownload)
- {
- $this->filtroDownload = $filtroDownload;
- return $this;
- }
- /**
- * @param bigint $maxCpe
- *
- * @return $this
- */
- public function setMaxCpe($maxCpe)
- {
- $this->maxCpe = $maxCpe;
- return $this;
- }
- /**
- * @return string
- */
- public function getSipDevProxyServer()
- {
- return $this->getData('sipDevProxyServer') ? $this->getData('sipDevProxyServer') : $this->getDefault('sipDevProxyServer');
- }
- /**
- * @return string
- */
- public function getServerVoIP_IP()
- {
- return $this->getData('ServerVoIP_IP') ? $this->getData('ServerVoIP_IP') : $this->getDefault('ServerVoIP_IP');
- }
- /**
- * @return string
- */
- public function getSipDevRegistrar()
- {
- return $this->getData('sipDevRegistrar') ? $this->getData('sipDevRegistrar') : $this->getDefault('sipDevRegistrar');
- }
- /**
- * @param string $name
- *
- * @return mixed
- */
- public function getDefault($name = null)
- {
- global $kernel;
- $dir = $kernel->getProjectDir();
- $values = Yaml::parse(file_get_contents("{$dir}/app/config/profile.yml"));
- $value = null;
- if (!is_null($name) && isset($values[$name])) {
- $value = $values[$name];
- }
- return $value;
- }
-
- /**
- * @return string
- */
- public function getTemplate()
- {
- return $this->template;
- }
-
- /**
- * @param string $template
- *
- * @return Profile
- */
- public function setTemplate($template)
- {
- $this->template = $template;
-
- 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 getEntitiesBlockRemove()
- {
- $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);
- }
-
- }
- }
|