src/Entity/Gos/ChatbotDialog.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Gos;
  3. use App\Repository\Gos\ChatbotDialogRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=ChatbotDialogRepository::class)
  9.  */
  10. class ChatbotDialog
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="integer", nullable=true)
  20.      */
  21.     private $requiredDataType;
  22.     /**
  23.      * @ORM\Column(type="integer", nullable=true)
  24.      */
  25.     private $returnedDataType;
  26.     /**
  27.      * @ORM\ManyToOne(targetEntity=ChatbotDialog::class, inversedBy="childrenDialogs")
  28.      */
  29.     private $parentDialog;
  30.     /**
  31.      * @ORM\OneToMany(targetEntity=ChatbotDialog::class, mappedBy="parentDialog")
  32.      */
  33.     private $childrenDialogs;
  34.     /**
  35.      * @ORM\Column(type="string", length=255)
  36.      */
  37.     private $title;
  38.     /**
  39.      * @ORM\OneToMany(targetEntity=ChatbotSection::class, mappedBy="parentDialog")
  40.      */
  41.     private $childrenSections;
  42.     /**
  43.      * @ORM\ManyToOne(targetEntity=ChatbotSection::class, inversedBy="chatboxDialogs")
  44.      */
  45.     private $parentSection;
  46.     /**
  47.      * @ORM\Column(type="boolean", options={"default": 0})
  48.      */
  49.     private $isFinalDecideDialog false;
  50.     /**
  51.      * @ORM\Column(type="string", length=255, nullable=true)
  52.      */
  53.     private $officeEmail;
  54.     public function __construct()
  55.     {
  56.         $this->childrenDialogs = new ArrayCollection();
  57.         $this->childrenSections = new ArrayCollection();
  58.     }
  59.     public function getId(): ?int
  60.     {
  61.         return $this->id;
  62.     }
  63.     public function getRequiredDataType(): ?int
  64.     {
  65.         return $this->requiredDataType;
  66.     }
  67.     public function setRequiredDataType(?int $requiredDataType): self
  68.     {
  69.         $this->requiredDataType $requiredDataType;
  70.         return $this;
  71.     }
  72.     public function getReturnedDataType(): ?int
  73.     {
  74.         return $this->returnedDataType;
  75.     }
  76.     public function setReturnedDataType(?int $returnedDataType): self
  77.     {
  78.         $this->returnedDataType $returnedDataType;
  79.         return $this;
  80.     }
  81.     public function getParentDialog(): ?self
  82.     {
  83.         return $this->parentDialog;
  84.     }
  85.     public function setParentDialog(?self $parentDialog): self
  86.     {
  87.         $this->parentDialog $parentDialog;
  88.         return $this;
  89.     }
  90.     public function getChildDialog(): ?ChatbotDialog
  91.     {
  92.         if ($this->getChildrenDialogs()->isEmpty() === false) {
  93.             return $this->getChildrenDialogs()->first();
  94.         }
  95.         return null;
  96.     }
  97.     /**
  98.      * @return Collection|self[]
  99.      */
  100.     public function getChildrenDialogs(): Collection
  101.     {
  102.         return $this->childrenDialogs;
  103.     }
  104.     public function addChildrenQuestion(self $childrenQuestion): self
  105.     {
  106.         if (!$this->childrenDialogs->contains($childrenQuestion)) {
  107.             $this->childrenDialogs[] = $childrenQuestion;
  108.             $childrenQuestion->setParentDialog($this);
  109.         }
  110.         return $this;
  111.     }
  112.     public function removeChildrenQuestion(self $childrenQuestion): self
  113.     {
  114.         if ($this->childrenDialogs->contains($childrenQuestion)) {
  115.             $this->childrenDialogs->removeElement($childrenQuestion);
  116.             // set the owning side to null (unless already changed)
  117.             if ($childrenQuestion->getParentDialog() === $this) {
  118.                 $childrenQuestion->setParentDialog(null);
  119.             }
  120.         }
  121.         return $this;
  122.     }
  123.     public function getTitle(): ?string
  124.     {
  125.         return $this->title;
  126.     }
  127.     public function setTitle(string $title): self
  128.     {
  129.         $this->title $title;
  130.         return $this;
  131.     }
  132.     /**
  133.      * @return Collection|ChatbotSection[]
  134.      */
  135.     public function getChildrenSections(): Collection
  136.     {
  137.         return $this->childrenSections;
  138.     }
  139.     public function addChildrenSection(ChatbotSection $childrenSection): self
  140.     {
  141.         if (!$this->childrenSections->contains($childrenSection)) {
  142.             $this->childrenSections[] = $childrenSection;
  143.             $childrenSection->setParentDialog($this);
  144.         }
  145.         return $this;
  146.     }
  147.     public function removeChildrenSection(ChatbotSection $childrenSection): self
  148.     {
  149.         if ($this->childrenSections->contains($childrenSection)) {
  150.             $this->childrenSections->removeElement($childrenSection);
  151.             // set the owning side to null (unless already changed)
  152.             if ($childrenSection->getParentDialog() === $this) {
  153.                 $childrenSection->setParentDialog(null);
  154.             }
  155.         }
  156.         return $this;
  157.     }
  158.     public function getParentSection(): ?ChatbotSection
  159.     {
  160.         return $this->parentSection;
  161.     }
  162.     public function setParentSection(?ChatbotSection $parentSection): self
  163.     {
  164.         $this->parentSection $parentSection;
  165.         return $this;
  166.     }
  167.     public function findParentSection(): ?ChatbotSection
  168.     {
  169.         if ($this->getParentSection() !== null) {
  170.             return $this->getParentSection();
  171.         }
  172.         if ($this->getParentDialog() !== null) {
  173.             return $this->getParentDialog()->findParentSection();
  174.         }
  175.     }
  176.     public function getIsFinalDecideDialog(): ?bool
  177.     {
  178.         return $this->isFinalDecideDialog;
  179.     }
  180.     public function setIsFinalDecideDialog(bool $isFinalDecideDialog): self
  181.     {
  182.         $this->isFinalDecideDialog $isFinalDecideDialog;
  183.         return $this;
  184.     }
  185.     public function isTheLastDialog(): bool
  186.     {
  187.         return $this->getChildDialog() === null && $this->getChildrenSections()->isEmpty();
  188.     }
  189.     public function getOfficeEmail(): ?string
  190.     {
  191.         return $this->officeEmail;
  192.     }
  193.     public function setOfficeEmail(?string $officeEmail): self
  194.     {
  195.         $this->officeEmail $officeEmail;
  196.         return $this;
  197.     }
  198.     public function findSectionsTree(): string
  199.     {
  200.         $sections = [];
  201.         $section $this->findParentSection();
  202.         while ($section !== null) {
  203.             $sections[] = $section->getTitle();
  204.             if ($section->findParentSection() && $section->findParentSection()->getIsMain() === true) {
  205.                 break;
  206.             }
  207.             $section $section->findParentSection();
  208.         }
  209.         return implode('/'array_reverse($sections));
  210.     }
  211. }