<?php declare(strict_types=1);
namespace App\Entity;
use App\Validator as AppAssert;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Embeddable\FormPage\Config;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\HttpFoundation\File\File;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Embeddable\FormPage\ConfigInterface;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity]
#[Vich\Uploadable]
class FormPage extends Page implements FormPageInterface
{
#[ORM\OneToMany(targetEntity: Lead::class, mappedBy: 'formPage', fetch: 'EXTRA_LAZY')]
private $leads;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $leadEmailTemplateFilename;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $confirmationTemplateFilename;
#[Vich\UploadableField(mapping: 'page_confirmation_template', fileNameProperty: 'confirmationTemplateFilename')]
#[Assert\File(maxSize: '1024k', mimeTypes: ['text/html'], mimeTypesMessage: 'Please upload a valid .html')]
private $confirmationTemplateFile;
#[Vich\UploadableField(mapping: 'page_lead_email', fileNameProperty: 'leadEmailTemplateFilename')]
private $leadEmailTemplateFile;
#[ORM\Column(type: 'json', nullable: true)]
private $formConfig = [];
#[ORM\Embedded(class: '\App\Entity\Embeddable\FormPage\Config')]
private $config;
#[ORM\Column(type: 'json', nullable: true)]
private $data = [];
#[ORM\Column(type: 'json', nullable: true)]
private $queryMapping = [];
#[ORM\Column(type: 'text', nullable: true)]
#[AppAssert\Twig(message: 'twig.error')]
private $confirmBodyEndCode;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[AppAssert\Twig(message: 'twig.error')]
private $userEmailSubject;
#[ORM\Column(type: Types::ARRAY, nullable: true)]
private ?array $extraEmailRecipients = [];
public function __construct()
{
$this->leads = new ArrayCollection();
$this->config = new Config();
}
/**
* {@inheritDoc}
*/
public function getLeads(): Collection
{
return $this->leads;
}
public function addLead(LeadInterface $lead): self
{
if (!$this->leads->contains($lead)) {
$this->leads[] = $lead;
$lead->setFormPage($this);
}
return $this;
}
public function removeLead(LeadInterface $lead): self
{
if ($this->leads->contains($lead)) {
$this->leads->removeElement($lead);
// set the owning side to null (unless already changed)
if ($lead->getFormPage() === $this) {
$lead->setFormPage(null);
}
}
return $this;
}
public function getConfirmationTemplateFilename(): ?string
{
return $this->confirmationTemplateFilename;
}
public function setConfirmationTemplateFilename(?string $confirmationTemplateFilename): self
{
$this->confirmationTemplateFilename = $confirmationTemplateFilename;
return $this;
}
/**
* {@inheritDoc}
*/
public function setConfirmationTemplateFile(?File $confirmationTemplateFile = null): void
{
$this->confirmationTemplateFile = $confirmationTemplateFile;
if (null !== $confirmationTemplateFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTimeImmutable();
}
}
public function getConfirmationTemplateFile(): ?File
{
return $this->confirmationTemplateFile;
}
public function getLeadEmailTemplateFilename(): ?string
{
return $this->leadEmailTemplateFilename;
}
public function setLeadEmailTemplateFilename(?string $leadEmailTemplateFilename): self
{
$this->leadEmailTemplateFilename = $leadEmailTemplateFilename;
return $this;
}
public function getUserEmailSubject(): ?string
{
return $this->userEmailSubject;
}
public function setUserEmailSubject(?string $userEmailSubject): self
{
$this->userEmailSubject = $userEmailSubject;
return $this;
}
/**
* {@inheritDoc}
*/
public function setLeadEmailTemplateFile(?File $leadEmailTemplateFile = null): void
{
$this->leadEmailTemplateFile = $leadEmailTemplateFile;
if (null !== $leadEmailTemplateFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTimeImmutable();
}
}
public function getLeadEmailTemplateFile(): ?File
{
return $this->leadEmailTemplateFile;
}
public function getFormConfig(): ?array
{
return $this->formConfig;
}
public function setFormConfig(?array $formConfig): self
{
$this->formConfig = $formConfig;
return $this;
}
public function getConfig(): ?ConfigInterface
{
return $this->config;
}
public function setConfig(?ConfigInterface $config): self
{
$this->config = $config;
return $this;
}
public function getQueryMapping(): ?array
{
return $this->queryMapping;
}
public function setQueryMapping(?array $queryMapping): self
{
$this->queryMapping = $queryMapping;
return $this;
}
public function getData(): ?array
{
return $this->data;
}
public function setData(?array $data): self
{
$this->data = $data;
return $this;
}
public function getConfirmBodyEndCode(): ?string
{
return $this->confirmBodyEndCode;
}
public function setConfirmBodyEndCode(?string $confirmBodyEndCode): self
{
$this->confirmBodyEndCode = $confirmBodyEndCode;
return $this;
}
public function getExtraEmailRecipients(): ?array
{
return $this->extraEmailRecipients;
}
public function setExtraEmailRecipients(?array $extraEmailRecipients): self
{
$this->extraEmailRecipients = $extraEmailRecipients;
return $this;
}
}