src/Entity/FormAnswer.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\FormAnswerRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. use ApiPlatform\Metadata\ApiFilter;
  11. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  12. #[ORM\Entity(repositoryClassFormAnswerRepository::class)]
  13. #[ApiResource(
  14.     normalizationContext: ['groups' => ['formAnswer:read']],
  15.     denormalizationContext: ['groups' => ['formAnswer:write']],
  16.     order: ['id' => 'DESC']
  17. )]
  18. #[ApiFilter(SearchFilter::class, properties: [
  19.     'form.id' => 'exact'
  20.     'form.name' => 'partial' 
  21. ])]
  22. class FormAnswer
  23. {
  24.     #[ORM\Id]
  25.     #[ORM\GeneratedValue]
  26.     #[ORM\Column]
  27.     #[Groups(['formAnswer:read''formAnswer:write''form:read''form:write'])]
  28.     private ?int $id null;
  29.     #[ORM\ManyToOne(inversedBy'formAnswers')]
  30.     #[Groups(['formAnswer:read''formAnswer:write'])]
  31.     private ?Form $form null;
  32.     #[ORM\OneToMany(mappedBy'formAnswer'targetEntityMediaObject::class)]
  33.     #[Groups(['formAnswer:read''formAnswer:write''form:read''form:write'])]
  34.     private Collection $media;
  35.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  36.     #[Groups(['formAnswer:read''formAnswer:write''form:read''form:write'])]
  37.     private ?\DateTimeInterface $dateEntered null;
  38.     #[ORM\Column(nullabletrue)]
  39.     #[Groups(['formAnswer:read''formAnswer:write''form:read''form:write'])]
  40.     private ?bool $view null;
  41.     #[ORM\OneToMany(mappedBy'form_answer'targetEntityFormAnswerFields::class, cascade:['persist''remove'])]
  42.     #[Groups(['formAnswer:read''formAnswer:write''form:read''form:write'])]
  43.     private Collection $formAnswerFields;
  44.     public function __construct()
  45.     {
  46.         $this->media = new ArrayCollection();
  47.         $this->formAnswerFields = new ArrayCollection();
  48.     }
  49.     public function getId(): ?int
  50.     {
  51.         return $this->id;
  52.     }
  53.     public function getForm(): ?Form
  54.     {
  55.         return $this->form;
  56.     }
  57.     public function setForm(?Form $form): self
  58.     {
  59.         $this->form $form;
  60.         return $this;
  61.     }
  62.     /**
  63.      * @return Collection<int, MediaObject>
  64.      */
  65.     public function getMedia(): Collection
  66.     {
  67.         return $this->media;
  68.     }
  69.     public function addMedium(MediaObject $medium): self
  70.     {
  71.         if (!$this->media->contains($medium)) {
  72.             $this->media->add($medium);
  73.             $medium->setFormAnswer($this);
  74.         }
  75.         return $this;
  76.     }
  77.     public function removeMedium(MediaObject $medium): self
  78.     {
  79.         if ($this->media->removeElement($medium)) {
  80.             // set the owning side to null (unless already changed)
  81.             if ($medium->getFormAnswer() === $this) {
  82.                 $medium->setFormAnswer(null);
  83.             }
  84.         }
  85.         return $this;
  86.     }
  87.     public function getDateEntered(): ?\DateTimeInterface
  88.     {
  89.         return $this->dateEntered;
  90.     }
  91.     public function setDateEntered(\DateTimeInterface $dateEntered): self
  92.     {
  93.         $this->dateEntered $dateEntered;
  94.         return $this;
  95.     }
  96.     public function isView(): ?bool
  97.     {
  98.         return $this->view;
  99.     }
  100.     public function setView(?bool $view): self
  101.     {
  102.         $this->view $view;
  103.         return $this;
  104.     }
  105.     /**
  106.      * @return Collection<int, FormAnswerFields>
  107.      */
  108.     public function getFormAnswerFields(): Collection
  109.     {
  110.         return $this->formAnswerFields;
  111.     }
  112.     public function addFormAnswerField(FormAnswerFields $formAnswerField): self
  113.     {
  114.         if (!$this->formAnswerFields->contains($formAnswerField)) {
  115.             $this->formAnswerFields->add($formAnswerField);
  116.             $formAnswerField->setFormAnswer($this);
  117.         }
  118.         return $this;
  119.     }
  120.     public function removeFormAnswerField(FormAnswerFields $formAnswerField): self
  121.     {
  122.         if ($this->formAnswerFields->removeElement($formAnswerField)) {
  123.             // set the owning side to null (unless already changed)
  124.             if ($formAnswerField->getFormAnswer() === $this) {
  125.                 $formAnswerField->setFormAnswer(null);
  126.             }
  127.         }
  128.         return $this;
  129.     }
  130. }