<?php
namespace App\Entity\Gos;
use App\Repository\Gos\ChatbotDialogRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ChatbotDialogRepository::class)
*/
class ChatbotDialog
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $requiredDataType;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $returnedDataType;
/**
* @ORM\ManyToOne(targetEntity=ChatbotDialog::class, inversedBy="childrenDialogs")
*/
private $parentDialog;
/**
* @ORM\OneToMany(targetEntity=ChatbotDialog::class, mappedBy="parentDialog")
*/
private $childrenDialogs;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\OneToMany(targetEntity=ChatbotSection::class, mappedBy="parentDialog")
*/
private $childrenSections;
/**
* @ORM\ManyToOne(targetEntity=ChatbotSection::class, inversedBy="chatboxDialogs")
*/
private $parentSection;
/**
* @ORM\Column(type="boolean", options={"default": 0})
*/
private $isFinalDecideDialog = false;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $officeEmail;
public function __construct()
{
$this->childrenDialogs = new ArrayCollection();
$this->childrenSections = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getRequiredDataType(): ?int
{
return $this->requiredDataType;
}
public function setRequiredDataType(?int $requiredDataType): self
{
$this->requiredDataType = $requiredDataType;
return $this;
}
public function getReturnedDataType(): ?int
{
return $this->returnedDataType;
}
public function setReturnedDataType(?int $returnedDataType): self
{
$this->returnedDataType = $returnedDataType;
return $this;
}
public function getParentDialog(): ?self
{
return $this->parentDialog;
}
public function setParentDialog(?self $parentDialog): self
{
$this->parentDialog = $parentDialog;
return $this;
}
public function getChildDialog(): ?ChatbotDialog
{
if ($this->getChildrenDialogs()->isEmpty() === false) {
return $this->getChildrenDialogs()->first();
}
return null;
}
/**
* @return Collection|self[]
*/
public function getChildrenDialogs(): Collection
{
return $this->childrenDialogs;
}
public function addChildrenQuestion(self $childrenQuestion): self
{
if (!$this->childrenDialogs->contains($childrenQuestion)) {
$this->childrenDialogs[] = $childrenQuestion;
$childrenQuestion->setParentDialog($this);
}
return $this;
}
public function removeChildrenQuestion(self $childrenQuestion): self
{
if ($this->childrenDialogs->contains($childrenQuestion)) {
$this->childrenDialogs->removeElement($childrenQuestion);
// set the owning side to null (unless already changed)
if ($childrenQuestion->getParentDialog() === $this) {
$childrenQuestion->setParentDialog(null);
}
}
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
/**
* @return Collection|ChatbotSection[]
*/
public function getChildrenSections(): Collection
{
return $this->childrenSections;
}
public function addChildrenSection(ChatbotSection $childrenSection): self
{
if (!$this->childrenSections->contains($childrenSection)) {
$this->childrenSections[] = $childrenSection;
$childrenSection->setParentDialog($this);
}
return $this;
}
public function removeChildrenSection(ChatbotSection $childrenSection): self
{
if ($this->childrenSections->contains($childrenSection)) {
$this->childrenSections->removeElement($childrenSection);
// set the owning side to null (unless already changed)
if ($childrenSection->getParentDialog() === $this) {
$childrenSection->setParentDialog(null);
}
}
return $this;
}
public function getParentSection(): ?ChatbotSection
{
return $this->parentSection;
}
public function setParentSection(?ChatbotSection $parentSection): self
{
$this->parentSection = $parentSection;
return $this;
}
public function findParentSection(): ?ChatbotSection
{
if ($this->getParentSection() !== null) {
return $this->getParentSection();
}
if ($this->getParentDialog() !== null) {
return $this->getParentDialog()->findParentSection();
}
}
public function getIsFinalDecideDialog(): ?bool
{
return $this->isFinalDecideDialog;
}
public function setIsFinalDecideDialog(bool $isFinalDecideDialog): self
{
$this->isFinalDecideDialog = $isFinalDecideDialog;
return $this;
}
public function isTheLastDialog(): bool
{
return $this->getChildDialog() === null && $this->getChildrenSections()->isEmpty();
}
public function getOfficeEmail(): ?string
{
return $this->officeEmail;
}
public function setOfficeEmail(?string $officeEmail): self
{
$this->officeEmail = $officeEmail;
return $this;
}
public function findSectionsTree(): string
{
$sections = [];
$section = $this->findParentSection();
while ($section !== null) {
$sections[] = $section->getTitle();
if ($section->findParentSection() && $section->findParentSection()->getIsMain() === true) {
break;
}
$section = $section->findParentSection();
}
return implode('/', array_reverse($sections));
}
}