src/Entity/QuestionAnswer.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\QuestionAnswerRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use App\Entity\BasePost;
  9. /**
  10.  * @ORM\Entity(repositoryClass=QuestionAnswerRepository::class)
  11.  * @UniqueEntity("name")
  12.  */
  13. class QuestionAnswer
  14. {
  15.     use BasePost;
  16.     /* overriden relations */
  17.     /**
  18.      * @see BasePost
  19.      * @ORM\ManyToMany(targetEntity="App\Entity\Tag", inversedBy="questionAnswers")
  20.      */
  21.     private $tags;
  22.     /* new relations */
  23.     /**
  24.      * @ORM\ManyToMany(targetEntity="App\Entity\Media", mappedBy="questionAnswers", cascade={"persist", "remove"})
  25.      */
  26.     private $medias;
  27.     /**
  28.      * @ORM\ManyToMany(targetEntity="App\Entity\QuestionAnswer")
  29.      * @ORM\OrderBy({"priority" = "DESC", "name" = "ASC"})
  30.      * @ORM\JoinTable(name="questionanswer_questionanswer_seealso",
  31.      *      joinColumns={@ORM\JoinColumn(name="seealso_questionanswer_source", referencedColumnName="id")},
  32.      *      inverseJoinColumns={@ORM\JoinColumn(name="seealso_questionanswer_target", referencedColumnName="id")}
  33.      * )
  34.      */
  35.     private $seealsoQuestionAnswers;
  36.     /**
  37.      * @ORM\ManyToMany(targetEntity="App\Entity\Structure")
  38.      * @ORM\OrderBy({"priority" = "DESC", "name" = "ASC"})
  39.      */
  40.     private $seealsoStructures;
  41.     public function __construct()
  42.     {
  43.         // BasePost::__construct();
  44.         $this->tags = new ArrayCollection();
  45.         $this->medias = new ArrayCollection();
  46.         $this->seealsoQuestionAnswers = new ArrayCollection();
  47.         $this->seealsoStructures = new ArrayCollection();
  48.     }
  49.     
  50.     public function __toString()
  51.                       {
  52.                           return $this->name;
  53.                       }
  54.     /**
  55.      * @return Collection|Media[]
  56.      */
  57.     public function getMedias(): Collection
  58.     {
  59.         return $this->medias;
  60.     }
  61.     public function addMedia(Media $media): self
  62.     {
  63.         if (!$this->medias->contains($media)) {
  64.             $this->medias[] = $media;
  65.             $media->addQuestionAnswer($this);
  66.         }
  67.         return $this;
  68.     }
  69.     public function removeMedia(Media $media): self
  70.     {
  71.         if ($this->medias->contains($media)) {
  72.             $this->medias->removeElement($media);
  73.             $media->removeQuestionAnswer($this);
  74.         }
  75.         return $this;
  76.     }
  77.     /**
  78.      * @return Collection|QuestionAnswer[]
  79.      */
  80.     public function getSeealsoQuestionAnswers(): Collection
  81.     {
  82.         return $this->seealsoQuestionAnswers;
  83.     }
  84.     public function addSeealsoQuestionAnswer(QuestionAnswer $questionAnswer): self
  85.     {
  86.         if (!$this->seealsoQuestionAnswers->contains($questionAnswer)) {
  87.             $this->seealsoQuestionAnswers[] = $questionAnswer;
  88.             $questionAnswer->addSeealsoQuestionAnswer($this);
  89.         }
  90.         return $this;
  91.     }
  92.     public function removeSeealsoQuestionAnswer(QuestionAnswer $questionAnswer): self
  93.     {
  94.         if ($this->seealsoQuestionAnswers->contains($questionAnswer)) {
  95.             $this->seealsoQuestionAnswers->removeElement($questionAnswer);
  96.             $questionAnswer->removeSeealsoQuestionAnswer($this);
  97.         }
  98.         return $this;
  99.     }
  100.     /**
  101.      * @return Collection|Structure[]
  102.      */
  103.     public function getSeealsoStructures(): Collection
  104.     {
  105.         return $this->seealsoStructures;
  106.     }
  107.     public function addSeealsoStructure(Structure $structure): self
  108.     {
  109.         if (!$this->seealsoStructures->contains($structure)) {
  110.             $this->seealsoStructures[] = $structure;
  111.             $structure->addSeealsoStructure($this);
  112.         }
  113.         return $this;
  114.     }
  115.     public function removeSeealsoStructure(Structure $structure): self
  116.     {
  117.         if ($this->seealsoStructures->contains($structure)) {
  118.             $this->seealsoStructures->removeElement($structure);
  119.             $structure->removeSeealsoStructure($this);
  120.         }
  121.         return $this;
  122.     }
  123. }