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;
}
}

107
src/Entity/SnipContent.php Normal file
View File

@@ -0,0 +1,107 @@
<?php
namespace App\Entity;
use App\Repository\SnipContentRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: SnipContentRepository::class)]
class SnipContent
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'snipContents')]
#[ORM\JoinColumn(nullable: false)]
private ?Snip $snip = null;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'child')]
private ?self $parent = null;
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
private Collection $child;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $text = null;
public function __construct()
{
$this->child = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getSnip(): ?Snip
{
return $this->snip;
}
public function setSnip(?Snip $snip): self
{
$this->snip = $snip;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getChild(): Collection
{
return $this->child;
}
public function addChild(self $child): self
{
if (!$this->child->contains($child)) {
$this->child->add($child);
$child->setParent($this);
}
return $this;
}
public function removeChild(self $child): self
{
if ($this->child->removeElement($child)) {
// set the owning side to null (unless already changed)
if ($child->getParent() === $this) {
$child->setParent(null);
}
}
return $this;
}
public function getText(): ?string
{
return $this->text;
}
public function setText(?string $text): self
{
$this->text = $text;
return $this;
}
}