187 lines
4.1 KiB
PHP
187 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use App\Repository\DomainRepository;
|
|
use DateTimeInterface;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Gedmo\Mapping\Annotation\Timestampable;
|
|
|
|
#[ORM\Entity(repositoryClass: DomainRepository::class)]
|
|
class Domain
|
|
{
|
|
const SORT_POLICIES = [
|
|
'Recent First' => 'created:desc',
|
|
'Oldest First' => 'created:asc',
|
|
'Rating Desc' => 'rating:desc',
|
|
'Rating Asc' => 'rating:asc',
|
|
];
|
|
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private ?string $domain = null;
|
|
|
|
#[ORM\Column(length: 64)]
|
|
private ?string $ownerToken = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private ?string $name = null;
|
|
|
|
#[ORM\Column]
|
|
private ?bool $enabled = null;
|
|
|
|
#[ORM\Column(length: 32)]
|
|
private ?string $defaultSortPolicy = null;
|
|
|
|
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
|
|
#[Timestampable(on: "update")]
|
|
private ?DateTimeInterface $updatedAt = null;
|
|
|
|
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
|
|
#[Timestampable(on: "create")]
|
|
private ?DateTimeInterface $createdAt = null;
|
|
|
|
#[ORM\OneToMany(mappedBy: 'domain', targetEntity: DomainPage::class)]
|
|
private Collection $domainPages;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->domainPages = new ArrayCollection();
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getDomain(): ?string
|
|
{
|
|
return $this->domain;
|
|
}
|
|
|
|
public function setDomain(string $domain): static
|
|
{
|
|
$this->domain = $domain;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getOwnerToken(): ?string
|
|
{
|
|
return $this->ownerToken;
|
|
}
|
|
|
|
public function setOwnerToken(string $ownerToken): static
|
|
{
|
|
$this->ownerToken = $ownerToken;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getName(): ?string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
public function setName(string $name): static
|
|
{
|
|
$this->name = $name;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function isEnabled(): ?bool
|
|
{
|
|
return $this->enabled;
|
|
}
|
|
|
|
public function setEnabled(bool $enabled): static
|
|
{
|
|
$this->enabled = $enabled;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDefaultSortPolicy(): ?string
|
|
{
|
|
return $this->defaultSortPolicy;
|
|
}
|
|
|
|
public function getDefaultSortPolicyName(): ?string
|
|
{
|
|
if(!$this->getDefaultSortPolicy()) {
|
|
return null;
|
|
}
|
|
|
|
return array_flip(Domain::SORT_POLICIES)[$this->getDefaultSortPolicy()] ?? null;
|
|
}
|
|
|
|
public function setDefaultSortPolicy(string $defaultSortPolicy): static
|
|
{
|
|
$this->defaultSortPolicy = $defaultSortPolicy;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getUpdatedAt(): ?DateTimeInterface
|
|
{
|
|
return $this->updatedAt;
|
|
}
|
|
|
|
public function setUpdatedAt(?DateTimeInterface $updatedAt): static
|
|
{
|
|
$this->updatedAt = $updatedAt;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getCreatedAt(): ?DateTimeInterface
|
|
{
|
|
return $this->createdAt;
|
|
}
|
|
|
|
public function setCreatedAt(DateTimeInterface $createdAt): static
|
|
{
|
|
$this->createdAt = $createdAt;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, DomainPage>
|
|
*/
|
|
public function getDomainPages(): Collection
|
|
{
|
|
return $this->domainPages;
|
|
}
|
|
|
|
public function addDomainPage(DomainPage $domainPage): static
|
|
{
|
|
if (!$this->domainPages->contains($domainPage)) {
|
|
$this->domainPages->add($domainPage);
|
|
$domainPage->setDomain($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeDomainPage(DomainPage $domainPage): static
|
|
{
|
|
if ($this->domainPages->removeElement($domainPage)) {
|
|
// set the owning side to null (unless already changed)
|
|
if ($domainPage->getDomain() === $this) {
|
|
$domainPage->setDomain(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
}
|