src/Entity/Messaging/Theme.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Messaging;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. /**
  9.  * @ORM\Entity(repositoryClass="App\Repository\App\Messaging\ThemeRepository")
  10.  * @Gedmo\Tree(type="materializedPath")
  11.  */
  12. class Theme
  13. {
  14.     public const PATH_SEPARATOR '~';
  15.     public const THEME_STAMP 'theme';
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     protected $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=255)
  24.      * @Assert\NotBlank
  25.      * @Assert\Regex(
  26.      *     pattern="/~/",
  27.      *     match=false,
  28.      *     message="messaging.theme.label_path_seperator"
  29.      * )
  30.      * @Gedmo\TreePathSource
  31.      */
  32.     protected $label;
  33.     /**
  34.      * @Gedmo\TreeParent
  35.      * @ORM\ManyToOne(targetEntity="App\Entity\Messaging\Theme", inversedBy="children")
  36.      */
  37.     protected $parent;
  38.     /**
  39.      * @ORM\OneToMany(targetEntity="App\Entity\Messaging\Theme", mappedBy="parent")
  40.      */
  41.     protected $children;
  42.     /**
  43.      * @ORM\OneToMany(targetEntity="App\Entity\Messaging\Subject", mappedBy="theme", orphanRemoval=true)
  44.      */
  45.     protected $subjects;
  46.     /**
  47.      * @Gedmo\TreePath(appendId=false, separator=App\Entity\Messaging\Theme::PATH_SEPARATOR, endsWithSeparator=false)
  48.      * @ORM\Column(name="path", type="string", length=3000, nullable=true)
  49.      */
  50.     protected $path;
  51.     /**
  52.      * @ORM\Column(name="customer_can_see", type="boolean", options={"default": true})
  53.      */
  54.     protected bool $customerCanSee true;
  55.     public function __construct()
  56.     {
  57.         $this->children = new ArrayCollection();
  58.         $this->subjects = new ArrayCollection();
  59.     }
  60.     public function getId(): ?int
  61.     {
  62.         return $this->id;
  63.     }
  64.     public function getLabel(): ?string
  65.     {
  66.         return $this->label;
  67.     }
  68.     public function setLabel(string $label): self
  69.     {
  70.         $this->label $label;
  71.         return $this;
  72.     }
  73.     public function getParent(): ?self
  74.     {
  75.         return $this->parent;
  76.     }
  77.     public function setParent(?self $parent): self
  78.     {
  79.         $this->parent $parent;
  80.         return $this;
  81.     }
  82.     /**
  83.      * @return Collection|self[]
  84.      */
  85.     public function getChildren(): Collection
  86.     {
  87.         return $this->children;
  88.     }
  89.     public function addChildren(self $theme): self
  90.     {
  91.         if (!$this->children->contains($theme)) {
  92.             $this->children[] = $theme;
  93.             $theme->setParent($this);
  94.         }
  95.         return $this;
  96.     }
  97.     public function removeChildren(self $theme): self
  98.     {
  99.         if ($this->children->contains($theme)) {
  100.             $this->children->removeElement($theme);
  101.             if ($theme->getParent() === $this) {
  102.                 $theme->setParent(null);
  103.             }
  104.         }
  105.         return $this;
  106.     }
  107.     /**
  108.      * @return Collection
  109.      */
  110.     public function getSubjects(): Collection
  111.     {
  112.         return $this->subjects;
  113.     }
  114.     public function addSubject(Subject $subject): self
  115.     {
  116.         if (!$this->subjects->contains($subject)) {
  117.             $this->subjects[] = $subject;
  118.             $subject->setTheme($this);
  119.         }
  120.         return $this;
  121.     }
  122.     public function removeSubject(Subject $subject): self
  123.     {
  124.         if ($this->subjects->contains($subject)) {
  125.             $this->subjects->removeElement($subject);
  126.             if ($subject->getTheme() === $this) {
  127.                 $subject->setTheme(null);
  128.             }
  129.         }
  130.         return $this;
  131.     }
  132.     public function getPath(): string
  133.     {
  134.         return $this->path;
  135.     }
  136.     public function setPath(?string $path): self
  137.     {
  138.         $this->path $path;
  139.         return $this;
  140.     }
  141.     public function customerCanSee(): bool
  142.     {
  143.         return $this->customerCanSee;
  144.     }
  145.     public function setCustomerCanSee(bool $customerCanSee): self
  146.     {
  147.         $this->customerCanSee $customerCanSee;
  148.         return $this;
  149.     }
  150.     public function getPathLabel(): string
  151.     {
  152.         return str_replace(static::PATH_SEPARATOR' - '$this->path);
  153.     }
  154.     public function __toString()
  155.     {
  156.         return $this->getPathLabel();
  157.     }
  158. }