<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\FormAnswerRepository;
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: FormAnswerRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['formAnswer:read']],
denormalizationContext: ['groups' => ['formAnswer:write']],
order: ['id' => 'DESC']
)]
#[ApiFilter(SearchFilter::class, properties: [
'form.id' => 'exact',
'form.name' => 'partial'
])]
class FormAnswer
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['formAnswer:read', 'formAnswer:write', 'form:read', 'form:write'])]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'formAnswers')]
#[Groups(['formAnswer:read', 'formAnswer:write'])]
private ?Form $form = null;
#[ORM\OneToMany(mappedBy: 'formAnswer', targetEntity: MediaObject::class)]
#[Groups(['formAnswer:read', 'formAnswer:write', 'form:read', 'form:write'])]
private Collection $media;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
#[Groups(['formAnswer:read', 'formAnswer:write', 'form:read', 'form:write'])]
private ?\DateTimeInterface $dateEntered = null;
#[ORM\Column(nullable: true)]
#[Groups(['formAnswer:read', 'formAnswer:write', 'form:read', 'form:write'])]
private ?bool $view = null;
#[ORM\OneToMany(mappedBy: 'form_answer', targetEntity: FormAnswerFields::class, cascade:['persist', 'remove'])]
#[Groups(['formAnswer:read', 'formAnswer:write', 'form:read', 'form:write'])]
private Collection $formAnswerFields;
public function __construct()
{
$this->media = new ArrayCollection();
$this->formAnswerFields = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getForm(): ?Form
{
return $this->form;
}
public function setForm(?Form $form): self
{
$this->form = $form;
return $this;
}
/**
* @return Collection<int, MediaObject>
*/
public function getMedia(): Collection
{
return $this->media;
}
public function addMedium(MediaObject $medium): self
{
if (!$this->media->contains($medium)) {
$this->media->add($medium);
$medium->setFormAnswer($this);
}
return $this;
}
public function removeMedium(MediaObject $medium): self
{
if ($this->media->removeElement($medium)) {
// set the owning side to null (unless already changed)
if ($medium->getFormAnswer() === $this) {
$medium->setFormAnswer(null);
}
}
return $this;
}
public function getDateEntered(): ?\DateTimeInterface
{
return $this->dateEntered;
}
public function setDateEntered(\DateTimeInterface $dateEntered): self
{
$this->dateEntered = $dateEntered;
return $this;
}
public function isView(): ?bool
{
return $this->view;
}
public function setView(?bool $view): self
{
$this->view = $view;
return $this;
}
/**
* @return Collection<int, FormAnswerFields>
*/
public function getFormAnswerFields(): Collection
{
return $this->formAnswerFields;
}
public function addFormAnswerField(FormAnswerFields $formAnswerField): self
{
if (!$this->formAnswerFields->contains($formAnswerField)) {
$this->formAnswerFields->add($formAnswerField);
$formAnswerField->setFormAnswer($this);
}
return $this;
}
public function removeFormAnswerField(FormAnswerFields $formAnswerField): self
{
if ($this->formAnswerFields->removeElement($formAnswerField)) {
// set the owning side to null (unless already changed)
if ($formAnswerField->getFormAnswer() === $this) {
$formAnswerField->setFormAnswer(null);
}
}
return $this;
}
}