src/Entity/FormField.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Symfony\Component\Validator\Mapping\ClassMetadata;
  9. /**
  10.  * @ORM\Entity(repositoryClass="App\Repository\FormFieldRepository")
  11.  */
  12. class FormField
  13. {
  14.     
  15.     const TEXT_FIELD 1;
  16.     const TEXT_AREA 2;
  17.     const DROP_DOWN 3;
  18.     const RADIO_BUTTONS 4;
  19.     const CHECK_BOXES 5;
  20.     const IMAGE 6;
  21.     const FILE 7;
  22.     
  23.     /**
  24.      * @ORM\Id()
  25.      * @ORM\GeneratedValue()
  26.      * @ORM\Column(type="bigint")
  27.      */
  28.     private $id;
  29.     
  30.     /**
  31.      * @ORM\Version @ORM\Column(type="integer")
  32.      */
  33.     private $version;
  34.     
  35.     /**
  36.      * @ORM\Column(type="integer")
  37.      */
  38.     private $type;
  39.     
  40.     /**
  41.      * @ORM\Column(type="string", length=255)
  42.      */
  43.     private $title;
  44.     /**
  45.      * @ORM\Column(type="text")
  46.      */
  47.     private $description;
  48.     
  49.     /**
  50.      * @ORM\ManyToOne(targetEntity="App\Entity\Form", inversedBy="formFields")
  51.      * @ORM\JoinColumn(name="form_id", referencedColumnName="id", onDelete="SET NULL")
  52.      */
  53.     private $form;
  54.     
  55.     /**
  56.      * @ORM\OneToMany(targetEntity="App\Entity\FormFieldOption", mappedBy="formField", orphanRemoval=true, cascade={"persist", "remove"}, fetch="EAGER")
  57.      */
  58.     private $formFieldOptions;
  59.     
  60.     /**
  61.      * @ORM\Column(type="boolean")
  62.      */
  63.     private $required;
  64.     
  65.     public function __construct ()
  66.     {
  67.         $this->type 0;
  68.         $this->title "";
  69.         $this->description "";
  70.         $this->required true;
  71.         $this->formFieldOptions = new ArrayCollection();
  72.     }
  73.     public function getId()
  74.     {
  75.         return $this->id;
  76.     }
  77.     
  78.     public function getVersion() {
  79.         return $this->version;
  80.     }
  81.     
  82.     public function getType(): ?int
  83.     {
  84.         return $this->type;
  85.     }
  86.     
  87.     public function setType(int $type): self
  88.     {
  89.         $this->type $type;
  90.         
  91.         return $this;
  92.     }
  93.     
  94.     public function getTitle(): ?string
  95.     {
  96.         return $this->title;
  97.     }
  98.     public function setTitle(string $title null): self
  99.     {
  100.         $this->title $title $title "";
  101.         return $this;
  102.     }
  103.     public function getDescription(): ?string
  104.     {
  105.         return $this->description;
  106.     }
  107.     public function setDescription(string $description null): self
  108.     {
  109.         $this->description $description $description "";
  110.         return $this;
  111.     }
  112.     
  113.     public function getForm(): ?Form
  114.     {
  115.         return $this->form;
  116.     }
  117.     
  118.     public function setForm(?Form $form null): self
  119.     {
  120.         $this->form $form;
  121.         
  122.         return $this;
  123.     }
  124.     
  125.     /**
  126.      * @return Collection|FormFieldOption[]
  127.      */
  128.     public function getFormFieldOptions(): Collection
  129.     {
  130.         return $this->formFieldOptions;
  131.     }
  132.     public function addFormFieldOption(FormFieldOption $formFieldOption): self
  133.     {
  134.         if (!$this->formFieldOptions->contains($formFieldOption)) {
  135.             $this->formFieldOptions[] = $formFieldOption;
  136.             $formFieldOption->setFormField($this);
  137.         }
  138.         return $this;
  139.     }
  140.     public function removeFormFieldOption(FormFieldOption $formFieldOption): self
  141.     {
  142.         if ($this->formFieldOptions->contains($formFieldOption)) {
  143.             $this->formFieldOptions->removeElement($formFieldOption);
  144.             // set the owning side to null (unless already changed)
  145.             if ($formFieldOption->getFormField() === $this) {
  146.                 $formFieldOption->setFormField(null);
  147.             }
  148.         }
  149.         
  150.         return $this;
  151.     }
  152.     
  153.     public function getRequired(): ?bool
  154.     {
  155.         return $this->required == 1;
  156.     }
  157.     
  158.     public function setRequired(bool $required): self
  159.     {
  160.         $this->required $required 0;
  161.         return $this;
  162.     }
  163.     public static function loadValidatorMetadata(ClassMetadata $metadata)
  164.     {
  165.         $metadata->addConstraint(new UniqueEntity([
  166.             'fields' => ['form''title'],
  167.         ]));
  168.     }
  169.     
  170.     public function __toString ()
  171.     {
  172.         return $this->title $this->title '';
  173.     }
  174.     
  175. }