src/Entity/Form.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Contracts\FormInterface;
  4. use App\Entity\Traits\FormTrait;
  5. use App\Entity\Traits\ActivableTrait;
  6. use App\Entity\Traits\EntityIdTrait;
  7. use App\Entity\Traits\TimestampableTrait;
  8. use App\Repository\FormRepository;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Symfony\Component\Uid\Uuid;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use App\Validator as CustomAssert;
  15. /**
  16.  * @ORM\Entity(repositoryClass=FormRepository::class)
  17.  * @ORM\HasLifecycleCallbacks()
  18.  * @CustomAssert\FormClass()
  19.  */
  20. class Form implements FormInterface
  21. {
  22.     use EntityIdTrait;
  23.     use ActivableTrait;
  24.     use TimestampableTrait;
  25.     use FormTrait;
  26.     // Types
  27.     public const TYPE_CREATE 'create';
  28.     public const TYPE_FULL_CREATE 'full_create';
  29.     public const TYPE_EDIT 'edit';
  30.     public const TYPE_DELETE 'delete';
  31.     public const TYPES = [
  32.         self::TYPE_CREATE => 'Creación',
  33.         self::TYPE_FULL_CREATE => 'Creación con precarga de un registro',
  34.         self::TYPE_EDIT => 'Edición',
  35.         self::TYPE_DELETE => 'Borrado'
  36.     ];
  37.     // Deactivable scales
  38.     public const NOT_ALLOW_SCALES FormActionsSet::RECURRING_DATE_SCALES;
  39.     /**
  40.      * @var string
  41.      * @ORM\Column(type="string", length=255)
  42.      */
  43.     private $type;
  44.     /**
  45.      * @ORM\ManyToOne(targetEntity=Campaign::class, inversedBy="forms")
  46.      * @ORM\JoinColumn(nullable=false)
  47.      * @Assert\NotBlank
  48.      */
  49.     private $campaign;
  50.     /**
  51.      * @ORM\Column(type="text")
  52.      */
  53.     private $confirmationMessage;
  54.     /**
  55.      * @var int
  56.      * @ORM\Column(type="integer", nullable=true)
  57.      */
  58.     private $notAllowStep;
  59.     /**
  60.      * @var string
  61.      * @ORM\Column(type="string", length=255, nullable=true)
  62.      */
  63.     private $notAllowScale;
  64.     /**
  65.      * @var int
  66.      * @ORM\Column(type="integer", nullable=true)
  67.      */
  68.     private $notAllowDuringStep;
  69.     /**
  70.      * @var string
  71.      * @ORM\Column(type="string", length=255, nullable=true)
  72.      */
  73.     private $notAllowDuringScale;
  74.     /**
  75.      * @var bool
  76.      * @ORM\Column(type="boolean")
  77.      */
  78.     private $oneUpdateByPeriod false;
  79.     /**
  80.      * @ORM\OneToMany(targetEntity=FormActionsSet::class, mappedBy="form", orphanRemoval=true, cascade={"remove"})
  81.      */
  82.     private $formActionsSets;
  83.     /**
  84.      * @var MasterForm
  85.      * @ORM\ManyToOne(targetEntity=MasterForm::class, inversedBy="forms")
  86.      * @ORM\JoinColumn(nullable=true)
  87.      */
  88.     private $masterForm;
  89.     /**
  90.      * @var FormFieldAdding[]
  91.      * @ORM\OneToMany(targetEntity=FormFieldAdding::class, mappedBy="form", cascade={"persist", "remove"})
  92.      * @ORM\JoinColumn()
  93.      */
  94.     private $formFieldAddings;
  95.     public function __construct()
  96.     {
  97.         $this->uuid Uuid::v6();
  98.         $this->formActionsSets = new ArrayCollection();
  99.         $this->formFieldAddings = new ArrayCollection();
  100.     }
  101.     /**
  102.      * @return string|null
  103.      */
  104.     public function getDefinitionFile(): ?string
  105.     {
  106.         if ($this->masterForm) {
  107.             return $this->getMasterForm()->getDefinitionFile();
  108.         }
  109.         return $this->definitionFile;
  110.     }
  111.     /**
  112.      * @param string|null $definitionFile
  113.      * @return $this
  114.      */
  115.     public function setDefinitionFile(?string $definitionFile): self
  116.     {
  117.         $this->definitionFile $definitionFile;
  118.         return $this;
  119.     }
  120.     /**
  121.      * @return string|null
  122.      */
  123.     public function getType(): ?string
  124.     {
  125.         return $this->type;
  126.     }
  127.     /**
  128.      * @param string $type
  129.      * @return $this
  130.      */
  131.     public function setType(string $type): self
  132.     {
  133.         $this->type $type;
  134.         return $this;
  135.     }
  136.     /**
  137.      * @return Campaign|null
  138.      */
  139.     public function getCampaign(): ?Campaign
  140.     {
  141.         return $this->campaign;
  142.     }
  143.     /**
  144.      * @param Campaign|null $campaign
  145.      * @return $this
  146.      */
  147.     public function setCampaign(?Campaign $campaign): self
  148.     {
  149.         $this->campaign $campaign;
  150.         return $this;
  151.     }
  152.     /**
  153.      * @return string|null
  154.      */
  155.     public function getConfirmationMessage(): ?string
  156.     {
  157.         return $this->confirmationMessage;
  158.     }
  159.     /**
  160.      * @param string $confirmationMessage
  161.      * @return $this
  162.      */
  163.     public function setConfirmationMessage(string $confirmationMessage): self
  164.     {
  165.         $this->confirmationMessage $confirmationMessage;
  166.         return $this;
  167.     }
  168.     /**
  169.      * @return int|null
  170.      */
  171.     public function getNotAllowStep(): ?int
  172.     {
  173.         return $this->notAllowStep;
  174.     }
  175.     /**
  176.      * @param int|null $notAllowStep
  177.      * @return $this
  178.      */
  179.     public function setNotAllowStep(?int $notAllowStep): self
  180.     {
  181.         $this->notAllowStep $notAllowStep;
  182.         return $this;
  183.     }
  184.     /**
  185.      * @return string|null
  186.      */
  187.     public function getNotAllowScale(): ?string
  188.     {
  189.         return $this->notAllowScale;
  190.     }
  191.     /**
  192.      * @param string|null $notAllowScale
  193.      * @return $this
  194.      */
  195.     public function setNotAllowScale(?string $notAllowScale): self
  196.     {
  197.         $this->notAllowScale $notAllowScale;
  198.         return $this;
  199.     }
  200.     /**
  201.      * @return int|null
  202.      */
  203.     public function getNotAllowDuringStep(): ?int
  204.     {
  205.         return $this->notAllowDuringStep;
  206.     }
  207.     /**
  208.      * @param int|null $notAllowDuringStep
  209.      * @return $this
  210.      */
  211.     public function setNotAllowDuringStep(?int $notAllowDuringStep): self
  212.     {
  213.         $this->notAllowDuringStep $notAllowDuringStep;
  214.         return $this;
  215.     }
  216.     /**
  217.      * @return string|null
  218.      */
  219.     public function getNotAllowDuringScale(): ?string
  220.     {
  221.         return $this->notAllowDuringScale;
  222.     }
  223.     /**
  224.      * @param string|null $notAllowDuringScale
  225.      * @return $this
  226.      */
  227.     public function setNotAllowDuringScale(?string $notAllowDuringScale): self
  228.     {
  229.         $this->notAllowDuringScale $notAllowDuringScale;
  230.         return $this;
  231.     }
  232.     /**
  233.      * @param bool $oneUpdateByPeriod
  234.      * @return $this
  235.      */
  236.     public function setOneUpdateByPeriod(bool $oneUpdateByPeriod false): self
  237.     {
  238.         $this->oneUpdateByPeriod $oneUpdateByPeriod;
  239.         return $this;
  240.     }
  241.     /**
  242.      * @return bool|null
  243.      */
  244.     public function isOneUpdateByPeriod(): ?bool
  245.     {
  246.         return $this->oneUpdateByPeriod;
  247.     }
  248.     /**
  249.      * @param string|null $type
  250.      * @return Collection<int, FormActionsSet>
  251.      */
  252.     public function getFormActionsSets(string $type null): Collection
  253.     {
  254.         if (!$type) {
  255.             return $this->formActionsSets;
  256.         }
  257.         return $this->formActionsSets->filter(function (FormActionsSet $formActionsSet) use ($type) {
  258.             return $formActionsSet->getEvent() == $type;
  259.         });
  260.     }
  261.     /**
  262.      * @param FormActionsSet $formActionsSet
  263.      * @return $this
  264.      */
  265.     public function addFormActionsSet(FormActionsSet $formActionsSet): self
  266.     {
  267.         if (!$this->formActionsSets->contains($formActionsSet)) {
  268.             $this->formActionsSets[] = $formActionsSet;
  269.             $formActionsSet->setForm($this);
  270.         }
  271.         return $this;
  272.     }
  273.     /**
  274.      * @param FormActionsSet $formActionsSet
  275.      * @return $this
  276.      */
  277.     public function removeFormActionsSet(FormActionsSet $formActionsSet): self
  278.     {
  279.         if ($this->formActionsSets->removeElement($formActionsSet)) {
  280.             // set the owning side to null (unless already changed)
  281.             if ($formActionsSet->getForm() === $this) {
  282.                 $formActionsSet->setForm(null);
  283.             }
  284.         }
  285.         return $this;
  286.     }
  287.     /**
  288.      * @return MasterForm|null
  289.      */
  290.     public function getMasterForm(): ?MasterForm
  291.     {
  292.         return $this->masterForm;
  293.     }
  294.     /**
  295.      * @param MasterForm|null $masterForm
  296.      * @return $this
  297.      */
  298.     public function setMasterForm(?MasterForm $masterForm): self
  299.     {
  300.         $this->masterForm $masterForm;
  301.         return $this;
  302.     }
  303.     /**
  304.      * @return Collection<int, FormFieldAdding>
  305.      */
  306.     public function getFormFieldAddings(): ?Collection
  307.     {
  308.         return $this->formFieldAddings;
  309.     }
  310.     /**
  311.      * @param FormFieldAdding $formFieldAdding
  312.      * @return $this
  313.      */
  314.     public function addFormFieldAdding(FormFieldAdding $formFieldAdding): self
  315.     {
  316.         if (!$this->formActionsSets->contains($formFieldAdding)) {
  317.             $this->formFieldAddings[] = $formFieldAdding;
  318.             $formFieldAdding->setForm($this);
  319.         }
  320.         return $this;
  321.     }
  322.     /**
  323.      * @param FormFieldAdding $formFieldAdding
  324.      * @return $this
  325.      */
  326.     public function removeFormFieldAdding(FormFieldAdding $formFieldAdding): self
  327.     {
  328.         if ($this->formFieldAddings->removeElement($formFieldAdding)) {
  329.             // set the owning side to null (unless already changed)
  330.             if ($formFieldAdding->getForm() === $this) {
  331.                 $formFieldAdding->setForm(null);
  332.             }
  333.         }
  334.         return $this;
  335.     }
  336.     /**
  337.      * @param FormFieldAdding[] $formFieldAddings
  338.      * @return $this
  339.      */
  340.     public function setFormFieldAddings(array $formFieldAddings): self
  341.     {
  342.         $this->formFieldAddings $formFieldAddings;
  343.         return $this;
  344.     }
  345.     /**
  346.      * @return bool
  347.      */
  348.     public function isTemporarilyAllow(): bool
  349.     {
  350.         return $this->notAllowStep && $this->notAllowScale;
  351.     }
  352.     /**
  353.      * @return string
  354.      */
  355.     public function __toString()
  356.     {
  357.         return $this->getCampaign()->getCompany() . ' - ' $this->getCampaign() . ' - ' '[#' $this->getId() . '] ' $this->getName();
  358.     }
  359. }