<?php
namespace App\Entity\Common;
use App\Entity\AbstractEntity;
use App\Enums\DirectoriesEnum;
use App\Repository\Common\UploadRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=UploadRepository::class)
*/
class Upload extends AbstractEntity
{
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $name=null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $originalName=null;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private ?int $directory=null;
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getOriginalName(): ?string
{
return $this->originalName;
}
public function setOriginalName(?string $originalName): self
{
$this->originalName = $originalName;
return $this;
}
public function getDirectory(): ?DirectoriesEnum
{
return DirectoriesEnum::from($this->directory);
}
public function setDirectory(?int $directory): self
{
$this->directory = $directory;
return $this;
}
public function getPath(): string
{
return "/uploads/" . $this->getDirectory()?->getPath() . "/" . $this->getName();
}
public function getPathPDF(): string
{
return "uploads/" . $this->getDirectory()?->getPath() . "/" . $this->getName();
}
public function getBase64(): ?string
{
try {
return "data:image;base64," . base64_encode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . $this->getPath()));
} catch (\Exception $exception) {
return null;
}
}
}