<?php
namespace App\Entity\App;
use App\Utils\CommonFunctions;
use App\Utils\Constants;
use App\Utils\Traits\ActivoTrait;
use App\Utils\Traits\PosicionTrait;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\App\TarjetaRepository")
* @ORM\HasLifecycleCallbacks()
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
*/
class Tarjeta
{
const ASPECT_RATIO = array('width' => 1, 'height' => 1);
/**
* @var integer|null
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
private $id;
/**
* @var File|null
*
* @Assert\Image(
* mimeTypes={"image/svg+xml", "image/jpg", "image/jpeg", "image/png"},
* mimeTypesMessage="El tipo de imagen tiene que ser SVG, JPG o PNG",
* maxSize="2M"
* )
*/
private $file;
/**
* @var string|null
* @ORM\Column(type="string", name="titulo")
* @ORM\Column(type="string", nullable=false)
* @Assert\Length(
* max = 5000,
* maxMessage = "La cantidad maxima es {{ limit }} caracteres"
* )
*/
private ?string $titulo;
/**
* @var string|null
* @ORM\Column(type="string", name="descripcion")
* @ORM\Column(type="string", nullable=true)
* @Assert\Length(
* max = 5000,
* maxMessage = "La cantidad maxima es {{ limit }} caracteres"
* )
*/
private ?string $descripcion = null;
/**
* @var Seccion|null
* @ORM\ManyToOne(targetEntity="App\Entity\App\Seccion", inversedBy="tarjetas")
* @ORM\JoinColumn(nullable=false)
*/
private $seccion;
/**
* @var string|null
*
* @ORM\Column(name="link", type="string", length=255)
* @Assert\NotBlank(message="El valor es requerido")
* @Assert\Length(
* max = 255,
* maxMessage = "La cantidad maxima es {{ limit }} caracteres"
* )
*/
private $link;
/**
* @var string|null
*
* @ORM\Column(name="imagen", type="string", length=255)
* @Assert\Length(
* max = 255,
* maxMessage = "La cantidad maxima es {{ limit }} caracteres"
* )
*/
private $imagen;
public function getId(): ?int
{
return $this->id;
}
public function setId(?int $id): void
{
$this->id = $id;
}
public function getFile(): ?File
{
return $this->file;
}
public function setFile(?File $file): void
{
$this->file = $file;
}
public function getTitulo(): ?string
{
return $this->titulo;
}
public function setTitulo(?string $titulo): void
{
$this->titulo = $titulo;
}
public function getDescripcion(): ?string
{
return $this->descripcion;
}
public function setDescripcion(?string $descripcion): void
{
$this->descripcion = $descripcion;
}
public function getSeccion(): ?Seccion
{
return $this->seccion;
}
public function setSeccion(?Seccion $seccion): void
{
$this->seccion = $seccion;
}
public function getLink(): ?string
{
return $this->link;
}
public function setLink(?string $link): void
{
$this->link = $link;
}
public function getImagen(): ?string
{
return $this->imagen;
}
public function setImagen(?string $imagen): void
{
$this->imagen = $imagen;
}
private function getDirectoryFile()
{
$class = CommonFunctions::getClassMethod(__CLASS__);
$class = CommonFunctions::camelCaseToSnakeCase($class, '-');
$dir = CommonFunctions::getParameter('BASE_PATH_IMAGENES');
return CommonFunctions::getPathOrURLWithSlash($dir) . $class;
}
public function guardarImagen()
{
$name = 'imagen_tarjeta_' . $this->getId();
$filename = CommonFunctions::saveUploadedFile($this->getFile(), $this->getDirectoryFile(), $name);
if ($filename && $filename != $this->getImagen()) {
$this->setImagen($filename);
}
}
/**
* @ORM\PrePersist
*/
public function prePersist()
{
$this->setImagen(Constants::NO_IMAGE_ICON);
}
/**
* @ORM\PreRemove
*/
public function preRemove()
{
CommonFunctions::removeFile($this->getAbsolutePath());
}
public function getAbsolutePath()
{
return CommonFunctions::getAbsolutePath($this->getDirectoryFile(), $this->getImagen());
}
public function getImagenBase64()
{
$image = null;
if ($this->getId()) {
$image = CommonFunctions::getBase64OfImage($this->getAbsolutePath(), Constants::DEFAULT_IMAGE);
}
return $image;
}
use ActivoTrait;
use PosicionTrait;
use TimestampableEntity;
use SoftDeleteableEntity;
}