src/Entity/Answer.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Controller\Api\AnswerController;
  5. use App\Repository\AnswerRepository;
  6. use DateTimeImmutable;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. #[ORM\Entity(repositoryClassAnswerRepository::class)]
  12.  
  13. class Answer
  14. {
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column(type'integer')]
  18.     #[Groups("readQuestions")]
  19.     private $id;
  20.     #[ORM\Column(type'string'length255)]
  21.     #[Groups("readQuestions")]
  22.     private $value;
  23.     #[ORM\Column(type'datetime_immutable')]
  24.     private $createdAt;
  25.     #[ORM\ManyToOne(targetEntityQuestion::class, inversedBy'answers'cascade: ["persist"] )]
  26.     // #[Groups("readQuestions")]
  27.     private $question;
  28.     #[ORM\ManyToMany(targetEntityUser::class, mappedBy'answers'cascade: ["persist"])]
  29.     private $users;
  30.     #[ORM\ManyToMany(targetEntityProfile::class, mappedBy'answers')]
  31.     private Collection $profiles;
  32.     #[ORM\OneToMany(mappedBy'answer'targetEntityAnswerTranslation::class, cascade: ["persist"])]
  33.     #[Groups("readQuestions")]
  34.     private Collection $translations;
  35.    
  36.     public function __construct()
  37.     {
  38.         $this->users = new ArrayCollection();
  39.         $this->createdAt = new DateTimeImmutable();
  40.         $this->profiles = new ArrayCollection();
  41.         $this->translations = new ArrayCollection();
  42.     }
  43.     public function __toString()
  44.     {
  45.         return $this->value."->".$this->getQuestion()->getContent();
  46.     }
  47.     public function getId(): ?int
  48.     {
  49.         return $this->id;
  50.     }
  51.     public function getValue(): ?string
  52.     {
  53.         return $this->value;
  54.     }
  55.     public function setValue(string $value): self
  56.     {
  57.         $this->value $value;
  58.         return $this;
  59.     }
  60.     public function getCreatedAt(): ?\DateTimeImmutable
  61.     {
  62.         return $this->createdAt;
  63.     }
  64.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  65.     {
  66.         $this->createdAt $createdAt;
  67.         return $this;
  68.     }
  69.     public function getQuestion(): ?Question
  70.     {
  71.         return $this->question;
  72.     }
  73.     public function setQuestion(?Question $question): self
  74.     {
  75.         $this->question $question;
  76.         return $this;
  77.     }
  78.     /**
  79.      * @return Collection<int, User>
  80.      */
  81.     public function getUsers(): Collection
  82.     {
  83.         return $this->users;
  84.     }
  85.     public function addUser(User $user): self
  86.     {
  87.         if (!$this->users->contains($user)) {
  88.             $this->users[] = $user;
  89.             $user->addAnswer($this);
  90.         }
  91.         return $this;
  92.     }
  93.     public function removeUser(User $user): self
  94.     {
  95.         if ($this->users->removeElement($user)) {
  96.             $user->removeAnswer($this);
  97.         }
  98.         return $this;
  99.     }
  100.     /**
  101.      * @return Collection<int, Profile>
  102.      */
  103.     public function getProfiles(): Collection
  104.     {
  105.         return $this->profiles;
  106.     }
  107.     public function addProfile(Profile $profile): self
  108.     {
  109.         if (!$this->profiles->contains($profile)) {
  110.             $this->profiles->add($profile);
  111.             $profile->addAnswer($this);
  112.         }
  113.         return $this;
  114.     }
  115.     public function removeProfile(Profile $profile): self
  116.     {
  117.         if ($this->profiles->removeElement($profile)) {
  118.             $profile->removeAnswer($this);
  119.         }
  120.         return $this;
  121.     }
  122.     /**
  123.      * @return Collection<int, AnswerTranslation>
  124.      */
  125.     public function getTranslations(): Collection
  126.     {
  127.         return $this->translations;
  128.     }
  129.     public function addTranslation(AnswerTranslation $translation): self
  130.     {
  131.         if (!$this->translations->contains($translation)) {
  132.             $this->translations->add($translation);
  133.             $translation->setAnswer($this);
  134.         }
  135.         return $this;
  136.     }
  137.     public function removeTranslation(AnswerTranslation $translation): self
  138.     {
  139.         if ($this->translations->removeElement($translation)) {
  140.             // set the owning side to null (unless already changed)
  141.             if ($translation->getAnswer() === $this) {
  142.                 $translation->setAnswer(null);
  143.             }
  144.         }
  145.         return $this;
  146.     }
  147. }