src/Entity/Ajustes/Pagina.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Ajustes;
  3. use App\Repository\Ajustes\PaginaRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\Common\Collections\Criteria;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\String\Slugger\AsciiSlugger;
  10. /**
  11.  * @ORM\Entity(repositoryClass=PaginaRepository::class)
  12.  * @UniqueEntity(fields="PagSlug", message="Ya existe otra página con ese Slug.")
  13.  */
  14. class Pagina
  15. {
  16.     public const BASEDIR '/pages/privado/ajustes/paginas';
  17.     public const ICON_CLASS 'fas fa-scroll';
  18.     public const ICON '<i class="'.self::ICON_CLASS.'"></i>';
  19.     public const LUGAR_MENU 1;
  20.     public const LUGAR_FOOTER 2;
  21.     public const LUGAR_NONE 3;
  22.     public const LUGAR_INICIO 4;
  23.     public const LUGAR = [
  24.         'pagina.lugares.menu' => self::LUGAR_MENU,
  25.         'pagina.lugares.footer' => self::LUGAR_FOOTER,
  26.         'pagina.lugares.ninguno' => self::LUGAR_NONE,
  27.         'pagina.lugares.inicio' => self::LUGAR_INICIO,
  28.     ];
  29.     public const STATUS = [
  30.         'pagina.estados.activo' => self::STATUS_ACTIVE,
  31.         'pagina.estados.inactivo' => self::STATUS_INACTIVE,
  32.     ];
  33.     public const STATUS_ACTIVE true;
  34.     public const STATUS_INACTIVE false;
  35.     /**
  36.      * @ORM\Id
  37.      * @ORM\GeneratedValue
  38.      * @ORM\Column(type="integer")
  39.      */
  40.     private $id;
  41.     /**
  42.      * @ORM\Column(type="string", length=180, unique=true)
  43.      */
  44.     private $PagSlug;
  45.     /**
  46.      * @ORM\Column(type="string", length=255)
  47.      */
  48.     private $PagNombre;
  49.     /**
  50.      * @ORM\Column(type="string", length=255)
  51.      */
  52.     private $PagTitulo;
  53.     /**
  54.      * @ORM\Column(type="string", length=255, nullable=true)
  55.      */
  56.     private $PagPalabrasClave;
  57.     /**
  58.      * @ORM\Column(type="string", length=255, nullable=true)
  59.      */
  60.     private $PagMetaDescripcion;
  61.     /**
  62.      * @ORM\Column(type="string", length=255)
  63.      */
  64.     private $PagIdioma;
  65.     /**
  66.      * @ORM\Column(type="boolean")
  67.      */
  68.     private $PagEstado;
  69.     /**
  70.      * @ORM\Column(type="integer", nullable=true)
  71.      */
  72.     private $PagPosicion;
  73.     /**
  74.      * @ORM\Column(type="smallint", nullable=true)
  75.      */
  76.     private $PagLugar;
  77.     /**
  78.      * @ORM\ManyToOne(targetEntity=Pagina::class, inversedBy="PagHijos")
  79.      */
  80.     private $PagPadre;
  81.     /**
  82.      * @ORM\OneToMany(targetEntity=Pagina::class, mappedBy="PagPadre")
  83.      */
  84.     private $PagHijos;
  85.     /**
  86.      * @ORM\Column(type="text", nullable=true)
  87.      */
  88.     private $PagContenidoHtml;
  89.     public function __construct()
  90.     {
  91.         $this->PagHijos = new ArrayCollection();
  92.     }
  93.     public function __toString()
  94.     {
  95.         return (string) $this->PagNombre;
  96.     }
  97.     public function getId(): ?int
  98.     {
  99.         return $this->id;
  100.     }
  101.     public function getPagSlug(): ?string
  102.     {
  103.         return $this->PagSlug;
  104.     }
  105.     public function setPagSlug(string $PagSlug): self
  106.     {
  107.         $slugger = new AsciiSlugger();
  108.         $slug $slugger->slug($PagSlug);
  109.         $this->PagSlug $slug;
  110.         return $this;
  111.     }
  112.     public function getPagNombre(): ?string
  113.     {
  114.         return $this->PagNombre;
  115.     }
  116.     public function setPagNombre(string $PagNombre): self
  117.     {
  118.         $this->PagNombre $PagNombre;
  119.         return $this;
  120.     }
  121.     public function getPagTitulo(): ?string
  122.     {
  123.         return $this->PagTitulo;
  124.     }
  125.     public function setPagTitulo(string $PagTitulo): self
  126.     {
  127.         $this->PagTitulo $PagTitulo;
  128.         return $this;
  129.     }
  130.     public function getPagPalabrasClave(): ?string
  131.     {
  132.         return $this->PagPalabrasClave;
  133.     }
  134.     public function setPagPalabrasClave(?string $PagPalabrasClave): self
  135.     {
  136.         $this->PagPalabrasClave $PagPalabrasClave;
  137.         return $this;
  138.     }
  139.     public function getPagMetaDescripcion(): ?string
  140.     {
  141.         return $this->PagMetaDescripcion;
  142.     }
  143.     public function setPagMetaDescripcion(?string $PagMetaDescripcion): self
  144.     {
  145.         $this->PagMetaDescripcion $PagMetaDescripcion;
  146.         return $this;
  147.     }
  148.     public function getPagIdioma(): ?string
  149.     {
  150.         return $this->PagIdioma;
  151.     }
  152.     public function setPagIdioma(string $PagIdioma): self
  153.     {
  154.         $this->PagIdioma $PagIdioma;
  155.         return $this;
  156.     }
  157.     public function getPagEstado(): ?bool
  158.     {
  159.         return $this->PagEstado;
  160.     }
  161.     public function setPagEstado(bool $PagEstado): self
  162.     {
  163.         $this->PagEstado $PagEstado;
  164.         return $this;
  165.     }
  166.     public function getPagEstadoTag(string $text ''): string
  167.     {
  168.         return $this->PagEstado ?
  169.             '<span class="badge badge-light-success">'.$text.'</span>' :
  170.             '<span class="badge badge-light-danger">'.$text.'</span>'
  171.         ;
  172.     }
  173.     public function getPagEstadoText(): string
  174.     {
  175.         return false === array_search($this->PagEstadoself::STATUS) ? 'pagina.estados.none' array_search($this->PagEstadoself::STATUS);
  176.     }
  177.     public function getPagPosicion(): ?int
  178.     {
  179.         return $this->PagPosicion;
  180.     }
  181.     public function setPagPosicion(?int $PagPosicion): self
  182.     {
  183.         $this->PagPosicion $PagPosicion;
  184.         return $this;
  185.     }
  186.     public function getPagLugar(): ?int
  187.     {
  188.         return $this->PagLugar;
  189.     }
  190.     public function setPagLugar(?int $PagLugar): self
  191.     {
  192.         $this->PagLugar $PagLugar;
  193.         return $this;
  194.     }
  195.     public function updatePagLugarByText(string $text): self
  196.     {
  197.         $this->setPagLugar($this->getPagLugarByText($text));
  198.         return $this;
  199.     }
  200.     public function getPagLugarByText(string $text): int
  201.     {
  202.         return isset(self::LUGAR[$text]) ? self::LUGAR[$text] : 'pagina.lugares.otra';
  203.     }
  204.     public function getPagLugarText(): ?string
  205.     {
  206.         return false === array_search($this->PagLugarself::LUGAR) ? 'pagina.lugares.otra' array_search($this->PagLugarself::LUGAR);
  207.     }
  208.     public function getPagPadre(): ?self
  209.     {
  210.         return $this->PagPadre;
  211.     }
  212.     public function setPagPadre(?self $PagPadre): self
  213.     {
  214.         $this->PagPadre $PagPadre;
  215.         return $this;
  216.     }
  217.     public function getPagPadresActive(): Collection
  218.     {
  219.         return $this->id->matching(
  220.             Criteria::create()
  221.                 ->andWhere(Criteria::expr()->eq('PagEstado',true))
  222.                 ->andWhere(Criteria::expr()->eq('PagPadre',null))
  223.         );
  224.     }
  225.     /**
  226.      * @return Collection<int, self>
  227.      */
  228.     public function getPagHijos(): Collection
  229.     {
  230.         return $this->PagHijos;
  231.     }
  232.     public function addPagHijo(self $pagHijo): self
  233.     {
  234.         if (!$this->PagHijos->contains($pagHijo)) {
  235.             $this->PagHijos[] = $pagHijo;
  236.             $pagHijo->setPagPadre($this);
  237.         }
  238.         return $this;
  239.     }
  240.     public function removePagHijo(self $pagHijo): self
  241.     {
  242.         if ($this->PagHijos->removeElement($pagHijo)) {
  243.             // set the owning side to null (unless already changed)
  244.             if ($pagHijo->getPagPadre() === $this) {
  245.                 $pagHijo->setPagPadre(null);
  246.             }
  247.         }
  248.         return $this;
  249.     }
  250.     public function getPagContenidoHtml(): ?string
  251.     {
  252.         return $this->PagContenidoHtml;
  253.     }
  254.     public function setPagContenidoHtml(?string $PagContenidoHtml): self
  255.     {
  256.         $this->PagContenidoHtml $PagContenidoHtml;
  257.         return $this;
  258.     }
  259. }