src/Entity/App/AreaGobierno.php line 30

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\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  12. use Symfony\Component\HttpFoundation\File\File;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. /**
  15.  * AreaGobierno
  16.  *
  17.  * @ORM\Table(name="area_gobierno", indexes={@ORM\Index(name="IDX_NOMBRE", columns={"nombre"})})
  18.  * @ORM\Entity(repositoryClass="App\Repository\App\AreaGobiernoRepository")
  19.  * @UniqueEntity(
  20.  *     fields="nombre",
  21.  *     errorPath="nombre",
  22.  *     message="El nombre ya existe"
  23.  * )
  24.  * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
  25.  * @ORM\HasLifecycleCallbacks()
  26.  */
  27. class AreaGobierno
  28. {
  29.     const ASPECT_RATIO = array('width' => 1'height' => 1);
  30.     /**
  31.      * @var integer|null
  32.      *
  33.      * @ORM\Column(name="id", type="integer")
  34.      * @ORM\Id
  35.      * @ORM\GeneratedValue
  36.      */
  37.     private $id;
  38.     /**
  39.      * @var File|null
  40.      *
  41.      * @Assert\Image(
  42.      *     mimeTypes={"image/svg+xml"},
  43.      *     mimeTypesMessage="El tipo de imagen tiene que ser SVG",
  44.      *     maxSize="2M"
  45.      * )
  46.      */
  47.     private $file;
  48.     /**
  49.      * @var string|null
  50.      *
  51.      * @ORM\Column(name="nombre", type="string", length=255)
  52.      * @Assert\NotBlank(message="El valor es requerido")
  53.      * @Assert\Length(
  54.      *      max = 255,
  55.      *      maxMessage = "La cantidad maxima es {{ limit }} caracteres"
  56.      * )
  57.      */
  58.     private $nombre;
  59.     /**
  60.      * @var string|null
  61.      *
  62.      * @ORM\Column(name="descripcion", type="string", length=255, nullable=true)
  63.      * @Assert\Length(
  64.      *      max = 255,
  65.      *      maxMessage = "La cantidad maxima es {{ limit }} caracteres"
  66.      * )
  67.      */
  68.     private $descripcion;
  69.     /**
  70.      * @var string|null
  71.      *
  72.      * @ORM\Column(name="link", type="string", length=255)
  73.      * @Assert\NotBlank(message="El valor es requerido")
  74.      * @Assert\Length(
  75.      *      max = 255,
  76.      *      maxMessage = "La cantidad maxima es {{ limit }} caracteres"
  77.      * )
  78.      */
  79.     private $link;
  80.     /**
  81.      * @var string|null
  82.      *
  83.      * @ORM\Column(name="imagen", type="string", length=255)
  84.      * @Assert\Length(
  85.      *      max = 255,
  86.      *      maxMessage = "La cantidad maxima es {{ limit }} caracteres"
  87.      * )
  88.      */
  89.     private $imagen;
  90.     use ActivoTrait;
  91.     use PosicionTrait;
  92.     use TimestampableEntity;
  93.     use SoftDeleteableEntity;
  94.     /**
  95.      * @var boolean
  96.      *
  97.      * @ORM\Column(name="visible", type="boolean")
  98.      * @Assert\Type(
  99.      *     type="bool",
  100.      *     message="El valor debe ser un bool"
  101.      * )
  102.      */
  103.     private $visible true;
  104.     /**
  105.      * @return bool
  106.      */
  107.     public function isVisible(): bool
  108.     {
  109.         return $this->visible;
  110.     }
  111.     /**
  112.      * @param bool $visible
  113.      */
  114.     public function setVisible(bool $visible): void
  115.     {
  116.         $this->visible $visible;
  117.     }
  118.     /**
  119.      * @return int|null
  120.      */
  121.     public function getId(): ?int
  122.     {
  123.         return $this->id;
  124.     }
  125.     /**
  126.      * @return File|null
  127.      */
  128.     public function getFile(): ?File
  129.     {
  130.         return $this->file;
  131.     }
  132.     /**
  133.      * @param File|null $file
  134.      */
  135.     public function setFile(?File $file): void
  136.     {
  137.         $this->file $file;
  138.     }
  139.     /**
  140.      * @return string|null
  141.      */
  142.     public function getNombre(): ?string
  143.     {
  144.         return $this->nombre;
  145.     }
  146.     /**
  147.      * @param string|null $nombre
  148.      */
  149.     public function setNombre(?string $nombre): void
  150.     {
  151.         $this->nombre $nombre;
  152.     }
  153.     /**
  154.      * @return string|null
  155.      */
  156.     public function getDescripcion(): ?string
  157.     {
  158.         return $this->descripcion;
  159.     }
  160.     /**
  161.      * @param string|null $descripcion
  162.      */
  163.     public function setDescripcion(?string $descripcion): void
  164.     {
  165.         $this->descripcion $descripcion;
  166.     }
  167.     /**
  168.      * @return string|null
  169.      */
  170.     public function getLink(): ?string
  171.     {
  172.         return $this->link;
  173.     }
  174.     /**
  175.      * @param string|null $link
  176.      */
  177.     public function setLink(?string $link): void
  178.     {
  179.         $this->link $link;
  180.     }
  181.     /**
  182.      * @return string|null
  183.      */
  184.     public function getImagen(): ?string
  185.     {
  186.         return $this->imagen;
  187.     }
  188.     /**
  189.      * @param string|null $imagen
  190.      */
  191.     public function setImagen(?string $imagen): void
  192.     {
  193.         $this->imagen $imagen;
  194.     }
  195.     private function getDirectoryFile()
  196.     {
  197.         $class CommonFunctions::getClassMethod(__CLASS__);
  198.         $class CommonFunctions::camelCaseToSnakeCase($class'-');
  199.         $dir CommonFunctions::getParameter('BASE_PATH_IMAGENES');
  200.         return CommonFunctions::getPathOrURLWithSlash($dir) . $class;
  201.     }
  202.     public function getAbsolutePath()
  203.     {
  204.         return CommonFunctions::getAbsolutePath($this->getDirectoryFile(), $this->getImagen());
  205.     }
  206.     public function guardarImagen()
  207.     {
  208.         $name 'imagen_area_gobierno_' $this->getId();
  209.         $filename CommonFunctions::saveUploadedFile($this->getFile(), $this->getDirectoryFile(), $name);
  210.         if ($filename && $filename != $this->getImagen()) {
  211.             $this->setImagen($filename);
  212.         }
  213.     }
  214.     /**
  215.      * @ORM\PrePersist
  216.      */
  217.     public function prePersist()
  218.     {
  219.         $this->setImagen(Constants::NO_IMAGE_ICON);
  220.     }
  221.     /**
  222.      * @ORM\PreRemove
  223.      */
  224.     public function preRemove()
  225.     {
  226.         CommonFunctions::removeFile($this->getAbsolutePath());
  227.     }
  228.     public function getImagenBase64()
  229.     {
  230.         $image null;
  231.         if ($this->getId()) {
  232.             $image CommonFunctions::getBase64OfImage($this->getAbsolutePath(), Constants::DEFAULT_IMAGE);
  233.         }
  234.         return $image;
  235.     }
  236.     public function getValidLink()
  237.     {
  238.         $baseUrl CommonFunctions::getParameterUrl('BASE_URL_DRUPAL'true);
  239.         return preg_replace('/^BASE_URL/'''preg_replace('/^BASE_URL\//'$baseUrl'BASE_URL' $this->getLink()));
  240.     }
  241.     public function __toString()
  242.     {
  243.         return $this->getNombre();
  244.     }
  245. }