src/Domain/Entity/Documentacion.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Domain\Entity;
  3. use App\Shared\Domain\ApplicationCore\Interfaces\EntityInterface;
  4. use DateTime;
  5. use DateTimeInterface;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Uid\Uuid;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  11. //#[Vich\Uploadable]
  12. class Documentacion implements EntityInterface
  13. {
  14.     private $field;
  15.     private $tramiteKey;
  16.     private ?string $filename null;
  17.     /**
  18.      * @Assert\File(
  19.      *     maxSize = "20M",
  20.      *     mimeTypes = {"application/pdf"},
  21.      *     mimeTypesMessage = "file_format {{ type }} {{ types }}",
  22.      *     uploadErrorMessage = "file_upload {{ limit }}"
  23.      * )
  24.      */
  25.     #[Vich\UploadableField(mapping'upload'fileNameProperty'filename')]
  26.     protected $filenameFile;
  27.     private ?string $descripcion null;
  28.     private ?Uuid $id null;
  29.     private ?Entidad $entidad null;
  30.     private ?DateTimeInterface $createdAt;
  31.     private ?DateTimeInterface $updatedAt;
  32.     private ?DateTimeInterface $deletedAt;
  33.     public function __toString(): string
  34.     {
  35.         // FIX-260608-005 (C0): con la descripción vacía (típico al subir un documento)
  36.         // __toString devolvía "" → el flash "creado con éxito" caía al fallback #<uuid>
  37.         // de AbstractAdmin y mostraba el UUID del documento.
  38.         //
  39.         // FIX-260608-007 (C0 matiz): Enrique + Ignacio confirman 2026-06-08 que el aviso
  40.         // de creación debe mostrar SOLO el nº de expediente (no "nº — nombre de archivo").
  41.         // Si el documento está ligado a un expediente (caso DocumentacionRegistro)
  42.         // devolvemos únicamente su nº de expediente; si no lo está, caemos a una etiqueta
  43.         // legible (descripción o filename) para mantener un toString no-vacío y evitar el
  44.         // fallback #<uuid> de AbstractAdmin. getExpediente() es null-safe para la base.
  45.         $label $this->descripcion ?: ($this->filename ?: 'Documento');
  46.         $num $this->getExpediente()?->getNumeroExpediente();
  47.         return $num ?: $label;
  48.     }
  49.     public function getFilename(): ?string
  50.     {
  51.         return $this->filename;
  52.     }
  53.     public function setFilename(?string $filename): static
  54.     {
  55.         $this->filename $filename;
  56.         return $this;
  57.     }
  58.     public function getCreatedAt(): ?DateTimeInterface
  59.     {
  60.         return $this->createdAt;
  61.     }
  62.     public function setCreatedAt(?DateTimeInterface $createdAt): static
  63.     {
  64.         $this->createdAt $createdAt;
  65.         return $this;
  66.     }
  67.     public function getDescripcion(): ?string
  68.     {
  69.         return $this->descripcion;
  70.     }
  71.     public function setDescripcion(?string $descripcion): static
  72.     {
  73.         $this->descripcion $descripcion;
  74.         return $this;
  75.     }
  76.     public function getId(): ?Uuid
  77.     {
  78.         return $this->id;
  79.     }
  80.     public function getEntidad(): ?Entidad
  81.     {
  82.         return $this->entidad;
  83.     }
  84.     public function setEntidad(?Entidad $entidad): static
  85.     {
  86.         $this->entidad $entidad;
  87.         return $this;
  88.     }
  89.     public function getUpdatedAt(): ?DateTimeInterface
  90.     {
  91.         return $this->updatedAt;
  92.     }
  93.     public function setUpdatedAt(DateTimeInterface $updatedAt): static
  94.     {
  95.         $this->updatedAt $updatedAt;
  96.         return $this;
  97.     }
  98.     public function getDeletedAt(): ?DateTimeInterface
  99.     {
  100.         return $this->deletedAt;
  101.     }
  102.     public function setDeletedAt(?DateTimeInterface $deletedAt): static
  103.     {
  104.         $this->deletedAt $deletedAt;
  105.         return $this;
  106.     }
  107.     /**
  108.      * @return mixed
  109.      */
  110.     public function getFilenameFile()
  111.     {
  112.         return $this->filenameFile;
  113.     }
  114.     /**
  115.      * @param mixed $filenameFile
  116.      * @return Documentacion
  117.      */
  118.     public function setFilenameFile($filenameFile)
  119.     {
  120.         $this->filenameFile $filenameFile;
  121.         if (null !== $filenameFile$this->updatedAt = new DateTime();
  122.         return $this;
  123.     }
  124.     public function getField(): ?string
  125.     {
  126.         return $this->field;
  127.     }
  128.     public function setField(?string $field): static
  129.     {
  130.         $this->field $field;
  131.         return $this;
  132.     }
  133.     public function getTramiteKey(): ?string
  134.     {
  135.         return $this->tramiteKey;
  136.     }
  137.     public function setTramiteKey(?string $tramiteKey): static
  138.     {
  139.         $this->tramiteKey $tramiteKey;
  140.         return $this;
  141.     }
  142.     public function getRegistro()
  143.     {
  144.         return $this instanceof DocumentacionRegistro $this->getNumeroRegistro() : null;
  145.     }
  146.     public function getExpediente()
  147.     {
  148.         return $this instanceof DocumentacionRegistro $this->getExpediente() : null;
  149.     }
  150. }//class