CRUD for domains & playing with symfony stimulus

This commit is contained in:
2023-10-14 03:15:46 -06:00
parent 3ed53ac05e
commit 39e94d8bdc
13 changed files with 622 additions and 368 deletions
+16 -34
View File
@@ -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>
*/