src/Entity/Common/Upload.php line 13

  1. <?php
  2. namespace App\Entity\Common;
  3. use Exception;
  4. use App\Entity\AbstractEntity;
  5. use App\Enums\DirectoriesEnum;
  6. use App\Repository\Common\UploadRepository;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassUploadRepository::class)]
  9. class Upload extends AbstractEntity
  10. {
  11.     #[ORM\Column(type'string'length255nullabletrue)]
  12.     private ?string $name=null;
  13.     #[ORM\Column(type'string'length255nullabletrue)]
  14.     private ?string $originalName=null;
  15.     #[ORM\Column(type'integer'nullabletrue)]
  16.     private ?int $directory=null;
  17.     public function getName(): ?string
  18.     {
  19.         return $this->name;
  20.     }
  21.     public function setName(?string $name): self
  22.     {
  23.         $this->name $name;
  24.         return $this;
  25.     }
  26.     public function getOriginalName(): ?string
  27.     {
  28.         return $this->originalName;
  29.     }
  30.     public function setOriginalName(?string $originalName): self
  31.     {
  32.         $this->originalName $originalName;
  33.         return $this;
  34.     }
  35.     public function getDirectory(): ?DirectoriesEnum
  36.     {
  37.         return DirectoriesEnum::from($this->directory);
  38.     }
  39.     public function setDirectory(?int $directory): self
  40.     {
  41.         $this->directory $directory;
  42.         return $this;
  43.     }
  44.     public function getPath(): string
  45.     {
  46.         return "/uploads/" $this->getDirectory()?->getPath() . "/" $this->getName();
  47.     }
  48.     public function getPathPDF(): string
  49.     {
  50.         return "uploads/" $this->getDirectory()?->getPath() . "/" $this->getName();
  51.     }
  52.     public function getBase64(): ?string
  53.     {
  54.         try {
  55.             return "data:image;base64," base64_encode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . $this->getPath()));
  56.         } catch (Exception $exception) {
  57.             return null;
  58.         }
  59.     }
  60. }