<?php
namespace App\Entity\Messaging;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\App\Messaging\ThemeRepository")
* @Gedmo\Tree(type="materializedPath")
*/
class Theme
{
public const PATH_SEPARATOR = '~';
public const THEME_STAMP = 'theme';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
protected $id;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank
* @Assert\Regex(
* pattern="/~/",
* match=false,
* message="messaging.theme.label_path_seperator"
* )
* @Gedmo\TreePathSource
*/
protected $label;
/**
* @Gedmo\TreeParent
* @ORM\ManyToOne(targetEntity="App\Entity\Messaging\Theme", inversedBy="children")
*/
protected $parent;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Messaging\Theme", mappedBy="parent")
*/
protected $children;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Messaging\Subject", mappedBy="theme", orphanRemoval=true)
*/
protected $subjects;
/**
* @Gedmo\TreePath(appendId=false, separator=App\Entity\Messaging\Theme::PATH_SEPARATOR, endsWithSeparator=false)
* @ORM\Column(name="path", type="string", length=3000, nullable=true)
*/
protected $path;
/**
* @ORM\Column(name="customer_can_see", type="boolean", options={"default": true})
*/
protected bool $customerCanSee = true;
public function __construct()
{
$this->children = new ArrayCollection();
$this->subjects = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(string $label): self
{
$this->label = $label;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection|self[]
*/
public function getChildren(): Collection
{
return $this->children;
}
public function addChildren(self $theme): self
{
if (!$this->children->contains($theme)) {
$this->children[] = $theme;
$theme->setParent($this);
}
return $this;
}
public function removeChildren(self $theme): self
{
if ($this->children->contains($theme)) {
$this->children->removeElement($theme);
if ($theme->getParent() === $this) {
$theme->setParent(null);
}
}
return $this;
}
/**
* @return Collection
*/
public function getSubjects(): Collection
{
return $this->subjects;
}
public function addSubject(Subject $subject): self
{
if (!$this->subjects->contains($subject)) {
$this->subjects[] = $subject;
$subject->setTheme($this);
}
return $this;
}
public function removeSubject(Subject $subject): self
{
if ($this->subjects->contains($subject)) {
$this->subjects->removeElement($subject);
if ($subject->getTheme() === $this) {
$subject->setTheme(null);
}
}
return $this;
}
public function getPath(): string
{
return $this->path;
}
public function setPath(?string $path): self
{
$this->path = $path;
return $this;
}
public function customerCanSee(): bool
{
return $this->customerCanSee;
}
public function setCustomerCanSee(bool $customerCanSee): self
{
$this->customerCanSee = $customerCanSee;
return $this;
}
public function getPathLabel(): string
{
return str_replace(static::PATH_SEPARATOR, ' - ', $this->path);
}
public function __toString()
{
return $this->getPathLabel();
}
}