Start on creating snipContent entities for the db content

This commit is contained in:
Tim
2023-04-20 23:23:04 +02:00
parent a405578f93
commit 506a0e8dec
11 changed files with 323 additions and 14 deletions

View File

@ -4,6 +4,8 @@ namespace App\Entity;
use App\Entity\Helpers\TrackedTrait;
use App\Repository\SnipRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: SnipRepository::class)]
@ -22,6 +24,14 @@ class Snip
#[ORM\Column]
private ?bool $public = null;
#[ORM\OneToMany(mappedBy: 'snip', targetEntity: SnipContent::class, orphanRemoval: true)]
private Collection $snipContents;
public function __construct()
{
$this->snipContents = new ArrayCollection();
}
public function __toString(): string
{
return $this->name ?? '';
@ -55,4 +65,34 @@ class Snip
return $this;
}
/**
* @return Collection<int, SnipContent>
*/
public function getSnipContents(): Collection
{
return $this->snipContents;
}
public function addSnipContent(SnipContent $snipContent): self
{
if (!$this->snipContents->contains($snipContent)) {
$this->snipContents->add($snipContent);
$snipContent->setSnip($this);
}
return $this;
}
public function removeSnipContent(SnipContent $snipContent): self
{
if ($this->snipContents->removeElement($snipContent)) {
// set the owning side to null (unless already changed)
if ($snipContent->getSnip() === $this) {
$snipContent->setSnip(null);
}
}
return $this;
}
}