src/Entity/App/Linda.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity\App;
  3. use App\Utils\CommonFunctions;
  4. use App\Utils\Constants;
  5. use App\Utils\Traits\ActivoTrait;
  6. use App\Utils\Traits\PosicionTrait;
  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\HttpFoundation\File\File;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. /**
  14.  * @ORM\Table(name="linda", indexes={@ORM\Index(name="IDX_TITULO", columns={"titulo"})})
  15.  * @ORM\Entity(repositoryClass="App\Repository\App\LindaRepository")
  16.  * @ORM\HasLifecycleCallbacks()
  17.  * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
  18.  */
  19. class Linda
  20. {
  21.     /**
  22.      * @var int|null
  23.      * @ORM\Column(name="id", type="integer")
  24.      * @ORM\Id
  25.      * @ORM\GeneratedValue
  26.      */
  27.     private $id;
  28.     /**
  29.      * @var string|null
  30.      * @ORM\Column(name="titulo", type="string", length=255)
  31.      * @Assert\NotBlank(message="El título es requerido")
  32.      * @Assert\Length(
  33.      *      max = 255,
  34.      *      maxMessage = "El título no puede tener más de {{ limit }} caracteres"
  35.      * )
  36.      */
  37.     private $titulo;
  38.     /**
  39.      * @var string|null
  40.      * @ORM\Column(name="titulo_boton", type="string", length=255)
  41.      * @Assert\NotBlank(message="El título del botón es requerido")
  42.      * @Assert\Length(
  43.      *      max = 255,
  44.      *      maxMessage = "El título del botón no puede tener más de {{ limit }} caracteres"
  45.      * )
  46.      */
  47.     private $tituloBoton;
  48.     /**
  49.      * @var string|null
  50.      * @ORM\Column(name="link_redireccion", type="string", length=500)
  51.      * @Assert\NotBlank(message="El link de redirección es requerido")
  52.      * @Assert\Regex(
  53.      *     pattern="/^(http[s]?:\/\/){0,1}(www\.){0,1}[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,5}[\.]{0,1}[\/]?/",
  54.      *     message="Ingrese un link correcto"
  55.      * )
  56.      * @Assert\Length(
  57.      *      max = 500,
  58.      *      maxMessage = "El link no puede tener más de {{ limit }} caracteres"
  59.      * )
  60.      */
  61.     private $linkRedireccion;
  62.     /**
  63.      * @var string|null
  64.      * @ORM\Column(name="color", type="string", length=255, nullable=true)
  65.      * @Assert\NotBlank(message="El color es requerido")
  66.      * @Assert\Length(
  67.      *      max = 255,
  68.      *      maxMessage = "El color no puede tener más de {{ limit }} caracteres"
  69.      * )
  70.      */
  71.     private $color;
  72.     /**
  73.      * @var File|null
  74.      * @Assert\Image(
  75.      *     mimeTypes={"image/jpg", "image/jpeg", "image/png", "image/webp"},
  76.      *     mimeTypesMessage="El tipo de imagen tiene que ser JPG, PNG, WEBP",
  77.      *     maxSize="400K"
  78.      * )
  79.      */
  80.     private $file;
  81.     /**
  82.      * @var string|null
  83.      * @ORM\Column(name="imagen", type="string", length=255)
  84.      * @Assert\Length(
  85.      *      max = 255,
  86.      *      maxMessage = "La cantidad máxima es {{ limit }} caracteres"
  87.      * )
  88.      */
  89.     private $imagen;
  90.     /**
  91.      * @var string|null
  92.      * @ORM\Column(name="posicion_contenido", type="string", length=50, nullable=true)
  93.      * @Assert\NotBlank(message="La posición es requerida")
  94.      * @Assert\Length(
  95.      *      max = 50,
  96.      *      maxMessage = "La posición no puede tener más de {{ limit }} caracteres"
  97.      * )
  98.      */
  99.     private $posicionContenido;
  100.     use ActivoTrait;
  101.     use PosicionTrait;
  102.     use TimestampableEntity;
  103.     use SoftDeleteableEntity;
  104.     public function getId(): ?int
  105.     {
  106.         return $this->id;
  107.     }
  108.     public function getTitulo(): ?string
  109.     {
  110.         return $this->titulo;
  111.     }
  112.     public function setTitulo(?string $titulo): void
  113.     {
  114.         $this->titulo $titulo;
  115.     }
  116.     public function getTituloBoton(): ?string
  117.     {
  118.         return $this->tituloBoton;
  119.     }
  120.     public function setTituloBoton(?string $tituloBoton): void
  121.     {
  122.         $this->tituloBoton $tituloBoton;
  123.     }
  124.     public function getLinkRedireccion(): ?string
  125.     {
  126.         return $this->linkRedireccion;
  127.     }
  128.     public function setLinkRedireccion(?string $linkRedireccion): void
  129.     {
  130.         $this->linkRedireccion $linkRedireccion;
  131.     }
  132.     public function getColor(): ?string
  133.     {
  134.         return $this->color;
  135.     }
  136.     public function setColor(?string $color): void
  137.     {
  138.         $this->color $color;
  139.     }
  140.     public function getFile(): ?File
  141.     {
  142.         return $this->file;
  143.     }
  144.     public function setFile(?File $file): void
  145.     {
  146.         $this->file $file;
  147.     }
  148.     public function getImagen(): ?string
  149.     {
  150.         return $this->imagen;
  151.     }
  152.     public function setImagen(?string $imagen): void
  153.     {
  154.         $this->imagen $imagen;
  155.     }
  156.     public function getPosicionContenido(): ?string
  157.     {
  158.         return $this->posicionContenido;
  159.     }
  160.     public function setPosicionContenido(?string $posicionContenido): void
  161.     {
  162.         $this->posicionContenido $posicionContenido;
  163.     }
  164.     private function getDirectoryFile(): string
  165.     {
  166.         $class CommonFunctions::getClassMethod(__CLASS__);
  167.         $class CommonFunctions::camelCaseToSnakeCase($class'-');
  168.         $dir CommonFunctions::getParameter('BASE_PATH_IMAGENES');
  169.         return CommonFunctions::getPathOrURLWithSlash($dir) . $class;
  170.     }
  171.     public function getAbsolutePath(): ?string
  172.     {
  173.         return CommonFunctions::getAbsolutePath($this->getDirectoryFile(), $this->getImagen());
  174.     }
  175.     public function guardarImagen(): void
  176.     {
  177.         $name 'imagen_linda_' $this->getId();
  178.         $filename CommonFunctions::saveUploadedFile($this->getFile(), $this->getDirectoryFile(), $name);
  179.         if ($filename && $filename !== $this->getImagen()) {
  180.             $this->setImagen($filename);
  181.         }
  182.     }
  183.     /**
  184.      * @ORM\PrePersist
  185.      */
  186.     public function prePersist(): void
  187.     {
  188.         $this->setImagen(Constants::NO_IMAGE_ICON);
  189.     }
  190.     /**
  191.      * @ORM\PreRemove
  192.      */
  193.     public function preRemove(): void
  194.     {
  195.         CommonFunctions::removeFile($this->getAbsolutePath());
  196.     }
  197.     public function getImagenBase64(): ?string
  198.     {
  199.         $image null;
  200.         if ($this->getId()) {
  201.             $image CommonFunctions::getBase64OfImage($this->getAbsolutePath(), Constants::DEFAULT_IMAGE);
  202.         }
  203.         return $image;
  204.     }
  205.     public function __toString()
  206.     {
  207.         return $this->getTitulo() ?: 'Nuevo Linda';
  208.     }
  209. }