<?php
namespace App\Entity;
use App\Service\ImageService;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Table(name: 'image')]
#[ORM\Index(name: 'IX_type_reference_id', columns: ['type', 'reference_id'])]
#[ORM\Index(name: 'IX_hash', columns: ['hash'])]
#[ORM\Entity(repositoryClass: 'App\Entity\Repository\ImageRepository')]
class Image
{
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private $id;
#[ORM\Column(type: 'string', nullable: true)]
private $type;
#[ORM\Column(type: 'string', nullable: true)]
private $path;
#[ORM\Column(type: 'integer', nullable: true)]
private $reference_id;
#[ORM\Column(type: 'string', nullable: true)]
private $license;
#[ORM\Column(type: 'datetime', nullable: true)]
private $date_created;
#[ORM\ManyToOne(targetEntity: 'App\Entity\User', inversedBy: 'image')]
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id')]
private $user;
#[ORM\Column(type: 'boolean', nullable: true)]
private $useS3;
#[ORM\Column(type: 'string', length: 32, nullable: true)]
private $hash;
public function getId(): ?int
{
return $this->id;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
public function getPath(): ?string
{
return $this->path;
}
public function setPath(?string $path): self
{
$this->path = $path;
return $this;
}
public function getReferenceId(): ?int
{
return $this->reference_id;
}
public function setReferenceId(?int $reference_id): self
{
$this->reference_id = $reference_id;
return $this;
}
public function getLicense(): ?string
{
return $this->license;
}
public function setLicense(?string $license): self
{
$this->license = $license;
return $this;
}
public function getDateCreated(): ?\DateTimeInterface
{
return $this->date_created;
}
public function setDateCreated(?\DateTimeInterface $date_created): self
{
$this->date_created = $date_created;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function isRestricted(): bool
{
// which images are restricted
$restrictedTypes = [
ImageService::TYPE_CROP,
ImageService::TYPE_GARDEN
];
return in_array($this->type, $restrictedTypes);
}
public function getUseS3(): ?bool
{
return $this->useS3;
}
public function setUseS3(?bool $useS3): self
{
$this->useS3 = $useS3;
return $this;
}
public function getHash(): ?string
{
return $this->hash;
}
public function setHash(?string $hash): self
{
$this->hash = $hash;
return $this;
}
}