src/Entity/Form.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\FormRepository;
  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(repositoryClassFormRepository::class)]
  13. #[ApiResource(
  14.     normalizationContext: ['groups' => ['form:read']],
  15.     denormalizationContext: ['groups' => ['form:write']],
  16.     order: ['id' => 'DESC']
  17. )]
  18. #[ApiFilter(SearchFilter::class, properties: [
  19.     'id' => 'exact'
  20.     'name' => 'partial' 
  21. ])]
  22. class Form
  23. {
  24.     #[ORM\Id]
  25.     #[ORM\GeneratedValue]
  26.     #[ORM\Column]
  27.     #[Groups(['form:read''form:write''formAnswer:read''formAnswer:write'])]
  28.     private ?int $id null;
  29.     #[ORM\Column(length255)]
  30.     #[Groups(['form:read''form:write''formAnswer:read''formAnswer:write'])]
  31.     private ?string $name null;
  32.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  33.     #[Groups(['form:read''form:write''formAnswer:read''formAnswer:write'])]
  34.     private ?\DateTimeInterface $date null;
  35.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  36.     #[Groups(['form:read''form:write''formAnswer:read''formAnswer:write'])]
  37.     private ?string $description null;
  38.     #[ORM\OneToMany(mappedBy'form'targetEntityFormFields::class, cascade:['persist''remove'])]
  39.     #[Groups(['form:read''form:write''formAnswer:read''formAnswer:write'])]
  40.     private Collection $formFields;
  41.     #[ORM\OneToMany(mappedBy'form'targetEntityFormAnswer::class)]
  42.     private Collection $formAnswers;
  43.     public function __construct()
  44.     {
  45.         $this->formFields = new ArrayCollection();
  46.         $this->formAnswers = new ArrayCollection();
  47.     }
  48.     public function getId(): ?int
  49.     {
  50.         return $this->id;
  51.     }
  52.     public function getName(): ?string
  53.     {
  54.         return $this->name;
  55.     }
  56.     public function setName(string $name): self
  57.     {
  58.         $this->name $name;
  59.         return $this;
  60.     }
  61.     public function getDate(): ?\DateTimeInterface
  62.     {
  63.         return $this->date;
  64.     }
  65.     public function setDate(?\DateTimeInterface $date): self
  66.     {
  67.         $this->date $date;
  68.         return $this;
  69.     }
  70.     public function getDescription(): ?string
  71.     {
  72.         return $this->description;
  73.     }
  74.     public function setDescription(?string $description): self
  75.     {
  76.         $this->description $description;
  77.         return $this;
  78.     }
  79.     /**
  80.      * @return Collection<int, FormFields>
  81.      */
  82.     public function getFormFields(): Collection
  83.     {
  84.         return $this->formFields;
  85.     }
  86.     public function addFormField(FormFields $formField): self
  87.     {
  88.         if (!$this->formFields->contains($formField)) {
  89.             $this->formFields->add($formField);
  90.             $formField->setForm($this);
  91.         }
  92.         return $this;
  93.     }
  94.     public function removeFormField(FormFields $formField): self
  95.     {
  96.         if ($this->formFields->removeElement($formField)) {
  97.             // set the owning side to null (unless already changed)
  98.             if ($formField->getForm() === $this) {
  99.                 $formField->setForm(null);
  100.             }
  101.         }
  102.         return $this;
  103.     }
  104.     /**
  105.      * @return Collection<int, FormAnswer>
  106.      */
  107.     public function getFormAnswers(): Collection
  108.     {
  109.         return $this->formAnswers;
  110.     }
  111.     public function addFormAnswer(FormAnswer $formAnswer): self
  112.     {
  113.         if (!$this->formAnswers->contains($formAnswer)) {
  114.             $this->formAnswers->add($formAnswer);
  115.             $formAnswer->setForm($this);
  116.         }
  117.         return $this;
  118.     }
  119.     public function removeFormAnswer(FormAnswer $formAnswer): self
  120.     {
  121.         if ($this->formAnswers->removeElement($formAnswer)) {
  122.             // set the owning side to null (unless already changed)
  123.             if ($formAnswer->getForm() === $this) {
  124.                 $formAnswer->setForm(null);
  125.             }
  126.         }
  127.         return $this;
  128.     }
  129. }