63 lines
1.7 KiB
PHP
63 lines
1.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace App\Domain\Article;
|
||
|
|
|
||
|
|
use App\Domain\Storage\StoragePath;
|
||
|
|
use Doctrine\ORM\Mapping as ORM;
|
||
|
|
use Symfony\Component\Uid\Uuid;
|
||
|
|
|
||
|
|
#[ORM\Entity]
|
||
|
|
#[ORM\Table(name: 'article_photos', schema: 'app')]
|
||
|
|
class ArticlePhoto
|
||
|
|
{
|
||
|
|
#[ORM\Id]
|
||
|
|
#[ORM\Column(type: 'uuid')]
|
||
|
|
private Uuid $id;
|
||
|
|
|
||
|
|
#[ORM\ManyToOne(targetEntity: Article::class, inversedBy: 'photos')]
|
||
|
|
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
|
||
|
|
private Article $article;
|
||
|
|
|
||
|
|
#[ORM\ManyToOne(targetEntity: StoragePath::class)]
|
||
|
|
#[ORM\JoinColumn(nullable: false)]
|
||
|
|
private StoragePath $storagePath;
|
||
|
|
|
||
|
|
#[ORM\Column(type: 'string', length: 500)]
|
||
|
|
private string $filename;
|
||
|
|
|
||
|
|
#[ORM\Column(type: 'boolean')]
|
||
|
|
private bool $isMain;
|
||
|
|
|
||
|
|
#[ORM\Column(type: 'integer')]
|
||
|
|
private int $sortOrder;
|
||
|
|
|
||
|
|
public function __construct(
|
||
|
|
Article $article,
|
||
|
|
StoragePath $storagePath,
|
||
|
|
string $filename,
|
||
|
|
bool $isMain,
|
||
|
|
int $sortOrder,
|
||
|
|
) {
|
||
|
|
$this->id = Uuid::v7();
|
||
|
|
$this->article = $article;
|
||
|
|
$this->storagePath = $storagePath;
|
||
|
|
$this->filename = $filename;
|
||
|
|
$this->isMain = $isMain;
|
||
|
|
$this->sortOrder = $sortOrder;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function getId(): Uuid { return $this->id; }
|
||
|
|
public function getStoragePath(): StoragePath { return $this->storagePath; }
|
||
|
|
public function getFilename(): string { return $this->filename; }
|
||
|
|
public function isMain(): bool { return $this->isMain; }
|
||
|
|
public function getSortOrder(): int { return $this->sortOrder; }
|
||
|
|
public function setSortOrder(int $sortOrder): void { $this->sortOrder = $sortOrder; }
|
||
|
|
|
||
|
|
public function getFullPath(): string
|
||
|
|
{
|
||
|
|
return $this->storagePath->resolveFilePath($this->filename);
|
||
|
|
}
|
||
|
|
}
|