src/Entity/App/Grupo.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity\App;
  3. use App\Utils\Traits\ActivoTrait;
  4. use App\Utils\Traits\PosicionTrait;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
  10. use Gedmo\Timestampable\Traits\TimestampableEntity;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. /**
  13.  * Grupo
  14.  *
  15.  * @ORM\Table(name="grupo", indexes={@ORM\Index(name="IDX_NOMBRE", columns={"nombre"})})
  16.  * @ORM\Entity(repositoryClass="App\Repository\App\GrupoRepository")
  17.  * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
  18.  */
  19. class Grupo
  20. {
  21.     /**
  22.      * @var integer|null
  23.      *
  24.      * @ORM\Column(name="id", type="integer")
  25.      * @ORM\Id
  26.      * @ORM\GeneratedValue
  27.      */
  28.     private $id;
  29.     /**
  30.      * @var string|null
  31.      *
  32.      * @ORM\Column(name="nombre", type="string", length=255)
  33.      * @Assert\NotBlank(message="El valor es requerido")
  34.      */
  35.     private $nombre;
  36.     /**
  37.      * @var string|null
  38.      *
  39.      * @ORM\Column(name="descripcion", type="string", length=255, nullable=true)
  40.      * @Assert\Length(
  41.      *      max = 255,
  42.      *      maxMessage = "La cantidad maxima es {{ limit }} caracteres"
  43.      * )
  44.      */
  45.     private $descripcion;
  46.     /**
  47.      * @var Categoria|null
  48.      *
  49.      * @ORM\ManyToOne(targetEntity="App\Entity\App\Categoria", inversedBy="grupos")
  50.      * @ORM\JoinColumn(name="categoria_id", referencedColumnName="id")
  51.      * @Assert\NotBlank(message="Categoria requerida")
  52.      */
  53.     private $categoria;
  54.     /**
  55.      * @ORM\ManyToMany(targetEntity="App\Entity\App\Tramite", mappedBy="grupos")
  56.      */
  57.     private $tramites;
  58.     use ActivoTrait;
  59.     use PosicionTrait;
  60.     use TimestampableEntity;
  61.     use SoftDeleteableEntity;
  62.     private $originalTramites;
  63.     public function __construct()
  64.     {
  65.         $this->tramites = new ArrayCollection();
  66.     }
  67.     public function addTramite(Tramite $tramite)
  68.     {
  69.         $tramite->setGrupo($this);
  70.         $this->tramites->add($tramite);
  71.     }
  72.     public function removeTramite(Tramite $tramite)
  73.     {
  74.         $this->tramites->removeElement($tramite);
  75.     }
  76.     /**
  77.      * @return int|null
  78.      */
  79.     public function getId(): ?int
  80.     {
  81.         return $this->id;
  82.     }
  83.     /**
  84.      * @return string|null
  85.      */
  86.     public function getNombre(): ?string
  87.     {
  88.         return $this->nombre;
  89.     }
  90.     /**
  91.      * @param string|null $nombre
  92.      */
  93.     public function setNombre(?string $nombre): void
  94.     {
  95.         $this->nombre $nombre;
  96.     }
  97.     /**
  98.      * @return string|null
  99.      */
  100.     public function getDescripcion(): ?string
  101.     {
  102.         return $this->descripcion;
  103.     }
  104.     /**
  105.      * @param string|null $descripcion
  106.      */
  107.     public function setDescripcion(?string $descripcion): void
  108.     {
  109.         $this->descripcion $descripcion;
  110.     }
  111.     /**
  112.      * @return Categoria|null
  113.      */
  114.     public function getCategoria(): ?Categoria
  115.     {
  116.         return $this->categoria;
  117.     }
  118.     /**
  119.      * @param Categoria|null $categoria
  120.      */
  121.     public function setCategoria(?Categoria $categoria): void
  122.     {
  123.         $this->categoria $categoria;
  124.     }
  125.     /**
  126.      * @return Collection
  127.      */
  128.     public function getTramites(): Collection
  129.     {
  130.         return $this->tramites;
  131.     }
  132.     /**
  133.      * @param Collection $tramites
  134.      */
  135.     public function setTramites(Collection $tramites): void
  136.     {
  137.         $this->tramites $tramites;
  138.     }
  139.     public function getOriginalTramites()
  140.     {
  141.         return $this->originalTramites;
  142.     }
  143.     public function setOriginalTramites()
  144.     {
  145.         $this->originalTramites = new ArrayCollection();
  146.         foreach ($this->getTramites() as $tramite) {
  147.             $this->originalTramites->add($tramite);
  148.         }
  149.     }
  150.     public function setOriginalsCollections()
  151.     {
  152.         $this->setOriginalTramites();
  153.     }
  154.     public function getBreadcrumb()
  155.     {
  156.         return $this->getCategoria()->getBreadcrumb(array($this->getCategoria()));
  157.     }
  158.     public function getMaterialesRecursos()
  159.     {
  160.         $materialesRecursos $this->getCategoria()->getMaterialesRecursos();
  161.         $materialesRecursosGrupo = array();
  162.         foreach ($materialesRecursos as $materialRecurso) {
  163.             if ($materialRecurso->getGrupo() && $materialRecurso->getGrupo()->getId() == $this->getId()) {
  164.                 $materialesRecursosGrupo[] = $materialRecurso;
  165.             }
  166.         }
  167.         return $materialesRecursosGrupo;
  168.     }
  169.     public function getAllChilds()
  170.     {
  171.         return $this->getTramites()->toArray();
  172.     }
  173.     public function __toString()
  174.     {
  175.         return $this->getNombre() ?: 'Nuevo grupo';
  176.     }
  177. }