<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\FormRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
#[ORM\Entity(repositoryClass: FormRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['form:read']],
denormalizationContext: ['groups' => ['form:write']],
order: ['id' => 'DESC']
)]
#[ApiFilter(SearchFilter::class, properties: [
'id' => 'exact',
'name' => 'partial'
])]
class Form
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['form:read', 'form:write', 'formAnswer:read', 'formAnswer:write'])]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Groups(['form:read', 'form:write', 'formAnswer:read', 'formAnswer:write'])]
private ?string $name = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
#[Groups(['form:read', 'form:write', 'formAnswer:read', 'formAnswer:write'])]
private ?\DateTimeInterface $date = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(['form:read', 'form:write', 'formAnswer:read', 'formAnswer:write'])]
private ?string $description = null;
#[ORM\OneToMany(mappedBy: 'form', targetEntity: FormFields::class, cascade:['persist', 'remove'])]
#[Groups(['form:read', 'form:write', 'formAnswer:read', 'formAnswer:write'])]
private Collection $formFields;
#[ORM\OneToMany(mappedBy: 'form', targetEntity: FormAnswer::class)]
private Collection $formAnswers;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['form:read', 'form:write', 'formAnswer:read', 'formAnswer:write'])]
private ?string $sendMailAnswet = null;
public function __construct()
{
$this->formFields = new ArrayCollection();
$this->formAnswers = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDate(): ?\DateTimeInterface
{
return $this->date;
}
public function setDate(?\DateTimeInterface $date): self
{
$this->date = $date;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
/**
* @return Collection<int, FormFields>
*/
public function getFormFields(): Collection
{
return $this->formFields;
}
public function addFormField(FormFields $formField): self
{
if (!$this->formFields->contains($formField)) {
$this->formFields->add($formField);
$formField->setForm($this);
}
return $this;
}
public function removeFormField(FormFields $formField): self
{
if ($this->formFields->removeElement($formField)) {
// set the owning side to null (unless already changed)
if ($formField->getForm() === $this) {
$formField->setForm(null);
}
}
return $this;
}
/**
* @return Collection<int, FormAnswer>
*/
public function getFormAnswers(): Collection
{
return $this->formAnswers;
}
public function addFormAnswer(FormAnswer $formAnswer): self
{
if (!$this->formAnswers->contains($formAnswer)) {
$this->formAnswers->add($formAnswer);
$formAnswer->setForm($this);
}
return $this;
}
public function removeFormAnswer(FormAnswer $formAnswer): self
{
if ($this->formAnswers->removeElement($formAnswer)) {
// set the owning side to null (unless already changed)
if ($formAnswer->getForm() === $this) {
$formAnswer->setForm(null);
}
}
return $this;
}
public function getSendMailAnswet(): ?string
{
return $this->sendMailAnswet;
}
public function setSendMailAnswet(?string $sendMailAnswet): static
{
$this->sendMailAnswet = $sendMailAnswet;
return $this;
}
}