<?php
namespace App\Entity;
use App\Entity\Enum\ProspectOnStoreFeedbackStateEnum;
use App\Entity\Enum\ProspectOnStoreStatusEnum;
use App\Repository\ProspectOnStoreFeedbackRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=ProspectOnStoreFeedbackRepository::class)
*/
class ProspectOnStoreFeedback
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\OneToOne(targetEntity=ProspectOnStore::class, mappedBy="feedback")
*/
private $prospectOnStore;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="create")
*/
private $created;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $openedDate;
/**
* @ORM\Column(type="string", length=50, unique=true)
*/
private $token;
/**
* @ORM\Column(type="string", length=5, nullable=true)
*/
private $answer;
/**
* @ORM\OneToMany(targetEntity=ProspectOnStore::class, mappedBy="prospectOnStoreFeedbackOrigin")
*/
private $prospectOnStoreGenerated;
/**
* @ORM\Column(type="string", length=5, nullable=true)
*/
private $state;
public function __construct()
{
$this->prospectOnStoreGenerated = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getProspectOnStore(): ?ProspectOnStore
{
return $this->prospectOnStore;
}
public function setProspectOnStore(?ProspectOnStore $prospectOnStore): self
{
$this->prospectOnStore = $prospectOnStore;
$prospectOnStore->setFeedback($this);
return $this;
}
public function getCreated(): ?\DateTimeInterface
{
return $this->created;
}
public function setCreated(?\DateTimeInterface $created): self
{
$this->created = $created;
return $this;
}
public function getOpenedDate(): ?\DateTimeInterface
{
return $this->openedDate;
}
public function setOpenedDate(?\DateTimeInterface $openedDate): self
{
$this->openedDate = $openedDate;
$this->setState(ProspectOnStoreFeedbackStateEnum::OPENED);
return $this;
}
public function getToken(): ?string
{
return $this->token;
}
public function setToken(string $token): self
{
$this->token = $token;
return $this;
}
public function getAnswer(): ?string
{
return $this->answer;
}
public function setAnswer(?string $answer): self
{
$this->answer = $answer;
$this->setState(ProspectOnStoreFeedbackStateEnum::ANSWER);
return $this;
}
/**
* @return Collection|ProspectOnStore[]
*/
public function getProspectOnStoreGenerated(): Collection
{
return $this->prospectOnStoreGenerated;
}
public function addProspectOnStoreGenerated(ProspectOnStore $prospectOnStoreGenerated): self
{
if (!$this->prospectOnStoreGenerated->contains($prospectOnStoreGenerated)) {
$this->prospectOnStoreGenerated[] = $prospectOnStoreGenerated;
$prospectOnStoreGenerated->setProspectOnStoreFeedbackOrigin($this);
}
return $this;
}
public function removeProspectOnStoreGenerated(ProspectOnStore $prospectOnStoreGenerated): self
{
if ($this->prospectOnStoreGenerated->contains($prospectOnStoreGenerated)) {
$this->prospectOnStoreGenerated->removeElement($prospectOnStoreGenerated);
// set the owning side to null (unless already changed)
if ($prospectOnStoreGenerated->getProspectOnStoreFeedbackOrigin() === $this) {
$prospectOnStoreGenerated->setProspectOnStoreFeedbackOrigin(null);
}
}
return $this;
}
public function getState(): ?string
{
return $this->state;
}
public function setState(?string $state): self
{
$this->state = $state;
return $this;
}
/**
* Return true if this feedback can still be answered
* @return bool
*/
public function canBeAnswered(){
return is_null($this->answer) || $this->answer==0 || in_array($this->state, [ProspectOnStoreFeedbackStateEnum::OPENED, ProspectOnStoreFeedbackStateEnum::STORE_CHOICE]);
}
}