src/Entity/Common/Upload.php line 13

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