CRUD for domains & playing with symfony stimulus
This commit is contained in:
+16
-34
@@ -13,6 +13,13 @@ 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]
|
||||
@@ -41,15 +48,11 @@ class Domain
|
||||
#[Timestampable(on: "create")]
|
||||
private ?DateTimeInterface $createdAt = null;
|
||||
|
||||
#[ORM\OneToMany(mappedBy: 'domain', targetEntity: Comment::class)]
|
||||
private Collection $comments;
|
||||
|
||||
#[ORM\OneToMany(mappedBy: 'domain', targetEntity: DomainPage::class)]
|
||||
private Collection $domainPages;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->comments = new ArrayCollection();
|
||||
$this->domainPages = new ArrayCollection();
|
||||
}
|
||||
|
||||
@@ -111,6 +114,15 @@ class Domain
|
||||
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;
|
||||
@@ -142,36 +154,6 @@ class Domain
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, Comment>
|
||||
*/
|
||||
public function getComments(): Collection
|
||||
{
|
||||
return $this->comments;
|
||||
}
|
||||
|
||||
public function addComment(Comment $comment): static
|
||||
{
|
||||
if (!$this->comments->contains($comment)) {
|
||||
$this->comments->add($comment);
|
||||
$comment->setDomain($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeComment(Comment $comment): static
|
||||
{
|
||||
if ($this->comments->removeElement($comment)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($comment->getDomain() === $this) {
|
||||
$comment->setDomain(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, DomainPage>
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user