<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Mapping\ClassMetadata;
/**
* @ORM\Entity(repositoryClass="App\Repository\FormFieldRepository")
*/
class FormField
{
const TEXT_FIELD = 1;
const TEXT_AREA = 2;
const DROP_DOWN = 3;
const RADIO_BUTTONS = 4;
const CHECK_BOXES = 5;
const IMAGE = 6;
const FILE = 7;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="bigint")
*/
private $id;
/**
* @ORM\Version @ORM\Column(type="integer")
*/
private $version;
/**
* @ORM\Column(type="integer")
*/
private $type;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\Column(type="text")
*/
private $description;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Form", inversedBy="formFields")
* @ORM\JoinColumn(name="form_id", referencedColumnName="id", onDelete="SET NULL")
*/
private $form;
/**
* @ORM\OneToMany(targetEntity="App\Entity\FormFieldOption", mappedBy="formField", orphanRemoval=true, cascade={"persist", "remove"}, fetch="EAGER")
*/
private $formFieldOptions;
/**
* @ORM\Column(type="boolean")
*/
private $required;
public function __construct ()
{
$this->type = 0;
$this->title = "";
$this->description = "";
$this->required = true;
$this->formFieldOptions = new ArrayCollection();
}
public function getId()
{
return $this->id;
}
public function getVersion() {
return $this->version;
}
public function getType(): ?int
{
return $this->type;
}
public function setType(int $type): self
{
$this->type = $type;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title = null): self
{
$this->title = $title ? $title : "";
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description = null): self
{
$this->description = $description ? $description : "";
return $this;
}
public function getForm(): ?Form
{
return $this->form;
}
public function setForm(?Form $form = null): self
{
$this->form = $form;
return $this;
}
/**
* @return Collection|FormFieldOption[]
*/
public function getFormFieldOptions(): Collection
{
return $this->formFieldOptions;
}
public function addFormFieldOption(FormFieldOption $formFieldOption): self
{
if (!$this->formFieldOptions->contains($formFieldOption)) {
$this->formFieldOptions[] = $formFieldOption;
$formFieldOption->setFormField($this);
}
return $this;
}
public function removeFormFieldOption(FormFieldOption $formFieldOption): self
{
if ($this->formFieldOptions->contains($formFieldOption)) {
$this->formFieldOptions->removeElement($formFieldOption);
// set the owning side to null (unless already changed)
if ($formFieldOption->getFormField() === $this) {
$formFieldOption->setFormField(null);
}
}
return $this;
}
public function getRequired(): ?bool
{
return $this->required == 1;
}
public function setRequired(bool $required): self
{
$this->required = $required ? 1 : 0;
return $this;
}
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addConstraint(new UniqueEntity([
'fields' => ['form', 'title'],
]));
}
public function __toString ()
{
return $this->title ? $this->title : '';
}
}