<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Utils\Config;
use App\Repository\DocumentRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: DocumentRepository::class)]
#[ApiResource(
collectionOperations: [
'get' => [
'normalization_context' => [
'groups' => 'read:document:collection:get',
],
],
],
itemOperations: [
'get' => [
'normalization_context' => [
'groups' => 'read:document:item:get',
],
],
]
)]
class
Document
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column()]
#[Groups([
'read:document:collection:get',
'read:document:item:get',
'read:photo:collection:get',
'read:photo:item:get',
'read:outfit:collection:get',
'read:outfit:item:get',
])]
private ?int $id = null;
use TimestampableEntity;
#[ORM\Column(length: 255, nullable: true)]
private ?string $filepath = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $imageType = null;
#[ORM\Column(length: 255)]
private ?string $filename = null;
public function __construct()
{
}
public function getAbsolutePath(): string
{
$absoluteDocumentDir = Config::getAbsoluteDocumentDir();
$path = !empty($this->filepath) ? '/'.$this->filepath : '';
return $absoluteDocumentDir.$path.'/'.$this->filename;
}
#[Groups([
'read:document:collection:get',
'read:document:item:get',
'read:photo:collection:get',
'read:photo:item:get',
'read:outfit:collection:get',
'read:outfit:item:get',
'read:photo:collection:post',
])]
public function getUrl(): string
{
$documentUrl = Config::getDocumentUrl();
$path = !empty($this->filepath) ? '/'.$this->filepath : '';
return $documentUrl.$path.'/'.$this->filename;
}
public function getId(): ?int
{
return $this->id;
}
public function getFilepath(): ?string
{
return $this->filepath;
}
public function setFilepath(?string $filepath): self
{
$this->filepath = $filepath;
return $this;
}
public function getImageType(): ?string
{
return $this->imageType;
}
public function setImageType(?string $imageType): self
{
$this->imageType = $imageType;
return $this;
}
public function getFilename(): ?string
{
return $this->filename;
}
public function setFilename(string $filename): self
{
$this->filename = $filename;
return $this;
}
}