<?php
namespace App\Entity;
use App\Constants\ActiveConstants;
use App\Repository\FaqQuestionRepository;
use App\Traits\ActivityTrait;
use App\Traits\TimeTrackTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: FaqQuestionRepository::class)]
#[ORM\HasLifecycleCallbacks]
class FaqQuestion
{
use TimeTrackTrait;
use ActivityTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(type: Types::TEXT)]
private ?string $title = null;
#[ORM\ManyToMany(targetEntity: "App\Entity\Company", inversedBy: 'faqQuestions', cascade: ['persist'], orphanRemoval: false)]
#[ORM\JoinTable(name: 'faq_questions_companies')]
#[ORM\JoinColumn(name: 'question_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
#[ORM\InverseJoinColumn(name: 'company_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
private $companies;
#[Assert\NotNull]
#[ORM\Column(type: Types::JSON, nullable: false)]
private $page = null;
#[ORM\Column(name: 'position', type: 'integer', nullable: true, options: ['unsigned' => true])]
#[Gedmo\SortablePosition]
private ?int $position = 1;
#[ORM\OneToMany(mappedBy: 'faqQuestion', targetEntity: FaqAnswer::class, orphanRemoval: true)]
private Collection $faqAnswers;
#[ORM\ManyToOne(targetEntity: Operator::class, inversedBy: 'faqQuestions')]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
private ?Operator $operator = null;
public function __construct()
{
$this->faqAnswers = new ArrayCollection();
$this->companies = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): static
{
$this->title = $title;
return $this;
}
/**
* Set createdAt.
*
* @param \DateTime|null $createdAt
*
* @return FaqQuestion
*/
public function setCreatedAt($createdAt = null)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt.
*
* @return \DateTime|null
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set updatedAt.
*
* @param \DateTime|null $updatedAt
*
* @return FaqQuestion
*/
public function setUpdatedAt($updatedAt = null)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt.
*
* @return \DateTime|null
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Set active.
*
* @param int $active
*
* @return FaqQuestion
*/
public function setActive($active)
{
$this->active = $active;
return $this;
}
/**
* Get active.
*
* @return int
*/
public function getActive()
{
return $this->active;
}
public function getActiveLabel(): string
{
return $this->active ? ActiveConstants::LABEL_YES : ActiveConstants::LABEL_NO;
}
/**
* @return Collection<int, FaqAnswer>
*/
public function getFaqAnswers(): Collection
{
return $this->faqAnswers;
}
public function addFaqAnswer(FaqAnswer $faqAnswer): static
{
if (!$this->faqAnswers->contains($faqAnswer)) {
$this->faqAnswers->add($faqAnswer);
$faqAnswer->setFaqQuestion($this);
}
return $this;
}
public function removeFaqAnswer(FaqAnswer $faqAnswer): static
{
if ($this->faqAnswers->removeElement($faqAnswer)) {
// set the owning side to null (unless already changed)
if ($faqAnswer->getFaqQuestion() === $this) {
$faqAnswer->setFaqQuestion(null);
}
}
return $this;
}
public function __toString()
{
return $this->getTitle();
}
public function getPage(): array
{
return $this->page;
}
public function setPage(array $page): static
{
foreach ($page as &$value) {
$value = "{$value}";
}
$this->page = $page;
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(?int $position): self
{
$this->position = $position;
return $this;
}
/**
* @return Collection<int, Company>
*/
public function getCompanies(): Collection
{
return $this->companies;
}
public function addCompany(Company $company): static
{
if (!$this->companies->contains($company)) {
$this->companies->add($company);
}
return $this;
}
public function removeCompany(Company $company): static
{
$this->companies->removeElement($company);
return $this;
}
public function getOperator(): ?Operator
{
return $this->operator;
}
public function setOperator(?Operator $operator): static
{
$this->operator = $operator;
return $this;
}
}