src/Entity/CustomerDirectory.php line 21
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM,
Doctrine\DBAL\Types\Types,
Doctrine\Common\Collections\Collection,
Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups,
Symfony\Component\Validator\Constraints as Assert,
Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use App\Entity\Trait\IdTrait,
App\Entity\Trait\UuidTrait,
App\Entity\Trait\TimestampableTrait,
App\Repository\CustomerDirectoryRepository;
#[UniqueEntity(fields: ['parent', 'title'], errorPath: 'title', ignoreNull: false, message: 'This value already exists.')]
#[ORM\UniqueConstraint(fields: ['parent', 'title'])]
#[ORM\Entity(repositoryClass: CustomerDirectoryRepository::class)]
class CustomerDirectory
{
use IdTrait,
UuidTrait,
TimestampableTrait;
#[Assert\NotNull]
#[ORM\ManyToOne(targetEntity: Customer::class, inversedBy: 'directories')]
#[ORM\JoinColumn(onDelete: 'cascade', nullable: false)]
private Customer $parent;
#[Assert\NotBlank]
#[Groups(['read'])]
#[ORM\Column(type: Types::STRING, length: 511)]
private ?string $title = null;
#[ORM\OneToMany(targetEntity: CustomerDirectoryItem::class, mappedBy: 'parent', cascade: ['persist', 'remove'])]
#[ORM\OrderBy(['createdAt' => 'desc'])]
private Collection $items;
public function __construct(Customer $parent)
{
$this->setUuid();
$this->parent = $parent;
$this->items = new ArrayCollection();
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
$parent->addDirectory($this);
}
public function getParent(): Customer
{
return $this->parent;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
/**
* @return Collection|Customer[]
*/
public function getItems(): Collection
{
return $this->items;
}
public function addItem(CustomerDirectoryItem $item): self
{
if ($this->items->contains($item)) {
return $this;
}
$this->items[] = $item;
return $this;
}
public function removeItem(CustomerDirectoryItem $item): self
{
$this->items->removeElement($item);
return $this;
}
}