<?php
namespace App\Entity;
use App\Repository\SurveyRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=SurveyRepository::class)
* @ORM\Table(name="app_survey")
*/
class Survey
{
const TYPE_POLL = 'poll';
const TYPE_QUIZ = 'quiz';
const TYPE_SCORE = 'score';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private int $id;
/**
* Название опроса
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $title;
/**
* Описание опроса
* @ORM\Column(type="text", nullable=true)
*/
private ?string $description = null;
/**
* Название опроса
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $titleLocal;
/**
* Описание опроса
* @ORM\Column(type="text", nullable=true)
*/
private ?string $descriptionLocal = null;
/**
* @ORM\OneToMany(targetEntity="App\Entity\SurveyImage", mappedBy="survey", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private Collection $images;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Question", mappedBy="survey", cascade={"persist", "remove"})
*/
private Collection $questions;
/**
* @ORM\Column(type="boolean", options={"default": true})
*/
private bool $isActive = true;
/**
* @ORM\Column(type="boolean", options={"default": false})
*/
private bool $isPoll = false;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Article", inversedBy="survey")
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
*/
private ?Article $articleSuccess;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Article", inversedBy="survey")
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
*/
private ?Article $articleFailed;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Article", inversedBy="surveys")
* @ORM\JoinTable(name="survey_articles")
*/
private Collection $articles;
/**
* @ORM\Column(type="integer", options={"default": 0})
*/
private int $totalCorrect = 0;
/**
* @ORM\Column(type="string", length=30, options={"default": "poll"})
*/
private string $type = self::TYPE_POLL;
public function __construct()
{
$this->questions = new ArrayCollection();
$this->images = new ArrayCollection();
$this->articles = new ArrayCollection();
}
public function getId(): int
{
return $this->id;
}
public function __toString(): ?string
{
return $this->getTitle() ?? $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getTitleLocal(): ?string
{
return $this->titleLocal;
}
public function setTitleLocal(?string $titleLocal): self
{
$this->titleLocal = $titleLocal;
return $this;
}
public function getDescriptionLocal(): ?string
{
return $this->descriptionLocal;
}
public function setDescriptionLocal(?string $descriptionLocal): self
{
$this->descriptionLocal = $descriptionLocal;
return $this;
}
public function getImages(): Collection
{
return $this->images;
}
public function addImage(SurveyImage $image): self
{
if (!$this->images->contains($image)) {
$this->images[] = $image;
$image->setSurvey($this);
}
return $this;
}
public function removeImage(SurveyImage $image): self
{
if ($this->images->removeElement($image)) {
if ($image->getSurvey() === $this) {
$image->setSurvey(null);
}
}
return $this;
}
/**
* @return Collection|Question[]
*/
public function getQuestions(): Collection
{
return $this->questions;
}
public function addQuestion(Question $question): self
{
if (!$this->questions->contains($question)) {
$this->questions[] = $question;
$question->setSurvey($this);
}
return $this;
}
public function removeQuestion(Question $question): self
{
if ($this->questions->removeElement($question)) {
// set the owning side to null
if ($question->getSurvey() === $this) {
$question->setSurvey(null);
}
}
return $this;
}
public function isActive(): bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function isPoll(): bool
{
return $this->isPoll;
}
public function setIsPoll(bool $isPoll): self
{
$this->isPoll = $isPoll;
return $this;
}
public function getArticleSuccess(): ?Article
{
return $this->articleSuccess;
}
public function setArticleSuccess(?Article $articleSuccess): self
{
$this->articleSuccess = $articleSuccess;
return $this;
}
public function getArticleFailed(): ?Article
{
return $this->articleFailed;
}
public function setArticleFailed(?Article $articleFailed): self
{
$this->articleFailed = $articleFailed;
return $this;
}
/** @return Collection<int, Article> */
public function getArticles(): Collection
{
return $this->articles;
}
public function addArticle(Article $article): self
{
if (!$this->articles->contains($article)) {
$this->articles->add($article);
$article->addSurvey($this);
}
return $this;
}
public function removeArticle(Article $article): self
{
if ($this->articles->removeElement($article)) {
$article->removeSurvey($this);
}
return $this;
}
public function getTotalCorrect(): ?int
{
return $this->totalCorrect;
}
public function setTotalCorrect(?int $totalCorrect): self
{
$this->totalCorrect = $totalCorrect;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
$this->isPoll = $type == self::TYPE_POLL;
return $this;
}
}