src/Entity/Survey.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SurveyRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  8. /**
  9.  * @ORM\Entity(repositoryClass=SurveyRepository::class)
  10.  * @ORM\Table(name="app_survey")
  11.  */
  12. class Survey
  13. {
  14.     const TYPE_POLL     'poll';
  15.     const TYPE_QUIZ     'quiz';
  16.     const TYPE_SCORE    'score';
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private int $id;
  23.     /**
  24.      * Название опроса
  25.      * @ORM\Column(type="string", length=255, nullable=true)
  26.      */
  27.     private ?string $title;
  28.     /**
  29.      * Описание опроса
  30.      * @ORM\Column(type="text", nullable=true)
  31.      */
  32.     private ?string $description null;
  33.     /**
  34.      * Название опроса
  35.      * @ORM\Column(type="string", length=255, nullable=true)
  36.      */
  37.     private ?string $titleLocal;
  38.     /**
  39.      * Описание опроса
  40.      * @ORM\Column(type="text", nullable=true)
  41.      */
  42.     private ?string $descriptionLocal null;
  43.     /**
  44.      * @ORM\OneToMany(targetEntity="App\Entity\SurveyImage", mappedBy="survey", cascade={"persist", "remove"}, orphanRemoval=true)
  45.      */
  46.     private Collection $images;
  47.     /**
  48.      * @ORM\OneToMany(targetEntity="App\Entity\Question", mappedBy="survey", cascade={"persist", "remove"})
  49.      */
  50.     private Collection $questions;
  51.     /**
  52.      * @ORM\Column(type="boolean", options={"default": true})
  53.      */
  54.     private bool $isActive true;
  55.     /**
  56.      * @ORM\Column(type="boolean", options={"default": false})
  57.      */
  58.     private bool $isPoll false;
  59.     /**
  60.      * @ORM\ManyToOne(targetEntity="App\Entity\Article", inversedBy="survey")
  61.      * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
  62.      */
  63.     private ?Article $articleSuccess;
  64.     /**
  65.      * @ORM\ManyToOne(targetEntity="App\Entity\Article", inversedBy="survey")
  66.      * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
  67.      */
  68.     private ?Article $articleFailed;
  69.     /**
  70.      * @ORM\ManyToMany(targetEntity="App\Entity\Article", inversedBy="surveys")
  71.      * @ORM\JoinTable(name="survey_articles")
  72.      */
  73.     private Collection $articles;
  74.     /**
  75.      * @ORM\Column(type="integer", options={"default": 0})
  76.      */
  77.     private int $totalCorrect 0;
  78.     /**
  79.      * @ORM\Column(type="string", length=30, options={"default": "poll"})
  80.      */
  81.     private string $type self::TYPE_POLL;
  82.     public function __construct()
  83.     {
  84.         $this->questions = new ArrayCollection();
  85.         $this->images = new ArrayCollection();
  86.         $this->articles = new ArrayCollection();
  87.     }
  88.     public function getId(): int
  89.     {
  90.         return $this->id;
  91.     }
  92.     public function __toString(): ?string
  93.     {
  94.         return $this->getTitle() ?? $this->id;
  95.     }
  96.     public function getTitle(): ?string
  97.     {
  98.         return $this->title;
  99.     }
  100.     public function setTitle(?string $title): self
  101.     {
  102.         $this->title $title;
  103.         return $this;
  104.     }
  105.     public function getDescription(): ?string
  106.     {
  107.         return $this->description;
  108.     }
  109.     public function setDescription(?string $description): self
  110.     {
  111.         $this->description $description;
  112.         return $this;
  113.     }
  114.     public function getTitleLocal(): ?string
  115.     {
  116.         return $this->titleLocal;
  117.     }
  118.     public function setTitleLocal(?string $titleLocal): self
  119.     {
  120.         $this->titleLocal $titleLocal;
  121.         return $this;
  122.     }
  123.     public function getDescriptionLocal(): ?string
  124.     {
  125.         return $this->descriptionLocal;
  126.     }
  127.     public function setDescriptionLocal(?string $descriptionLocal): self
  128.     {
  129.         $this->descriptionLocal $descriptionLocal;
  130.         return $this;
  131.     }
  132.     public function getImages(): Collection
  133.     {
  134.         return $this->images;
  135.     }
  136.     public function addImage(SurveyImage $image): self
  137.     {
  138.         if (!$this->images->contains($image)) {
  139.             $this->images[] = $image;
  140.             $image->setSurvey($this);
  141.         }
  142.         return $this;
  143.     }
  144.     public function removeImage(SurveyImage $image): self
  145.     {
  146.         if ($this->images->removeElement($image)) {
  147.             if ($image->getSurvey() === $this) {
  148.                 $image->setSurvey(null);
  149.             }
  150.         }
  151.         return $this;
  152.     }
  153.     /**
  154.      * @return Collection|Question[]
  155.      */
  156.     public function getQuestions(): Collection
  157.     {
  158.         return $this->questions;
  159.     }
  160.     public function addQuestion(Question $question): self
  161.     {
  162.         if (!$this->questions->contains($question)) {
  163.             $this->questions[] = $question;
  164.             $question->setSurvey($this);
  165.         }
  166.         return $this;
  167.     }
  168.     public function removeQuestion(Question $question): self
  169.     {
  170.         if ($this->questions->removeElement($question)) {
  171.             // set the owning side to null
  172.             if ($question->getSurvey() === $this) {
  173.                 $question->setSurvey(null);
  174.             }
  175.         }
  176.         return $this;
  177.     }
  178.     public function isActive(): bool
  179.     {
  180.         return $this->isActive;
  181.     }
  182.     public function setIsActive(bool $isActive): self
  183.     {
  184.         $this->isActive $isActive;
  185.         return $this;
  186.     }
  187.     public function isPoll(): bool
  188.     {
  189.         return $this->isPoll;
  190.     }
  191.     public function setIsPoll(bool $isPoll): self
  192.     {
  193.         $this->isPoll $isPoll;
  194.         return $this;
  195.     }
  196.     public function getArticleSuccess(): ?Article
  197.     {
  198.         return $this->articleSuccess;
  199.     }
  200.     public function setArticleSuccess(?Article $articleSuccess): self
  201.     {
  202.         $this->articleSuccess $articleSuccess;
  203.         return $this;
  204.     }
  205.     public function getArticleFailed(): ?Article
  206.     {
  207.         return $this->articleFailed;
  208.     }
  209.     public function setArticleFailed(?Article $articleFailed): self
  210.     {
  211.         $this->articleFailed $articleFailed;
  212.         return $this;
  213.     }
  214.     /** @return Collection<int, Article> */
  215.     public function getArticles(): Collection
  216.     {
  217.         return $this->articles;
  218.     }
  219.     public function addArticle(Article $article): self
  220.     {
  221.         if (!$this->articles->contains($article)) {
  222.             $this->articles->add($article);
  223.             $article->addSurvey($this);
  224.         }
  225.         return $this;
  226.     }
  227.     public function removeArticle(Article $article): self
  228.     {
  229.         if ($this->articles->removeElement($article)) {
  230.             $article->removeSurvey($this);
  231.         }
  232.         return $this;
  233.     }
  234.     public function getTotalCorrect(): ?int
  235.     {
  236.         return $this->totalCorrect;
  237.     }
  238.     public function setTotalCorrect(?int $totalCorrect): self
  239.     {
  240.         $this->totalCorrect $totalCorrect;
  241.         return $this;
  242.     }
  243.     public function getType(): ?string
  244.     {
  245.         return $this->type;
  246.     }
  247.     public function setType(?string $type): self
  248.     {
  249.         $this->type $type;
  250.         $this->isPoll $type == self::TYPE_POLL;
  251.         return $this;
  252.     }
  253. }