<?php
/**
 * Form
 * 
 * @author Elze Kool <info@visualmedia.nl>
 */

namespace VisualM\FormBundle\Entity;

use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
use VisualM\FormBundle\Model\FormModel;

/**
 * Form
 *
 * @ORM\Entity(repositoryClass="FormRepository")
 * @ORM\Table(name="form")
 * @UniqueEntity(fields = "referentie", message = "form.referentie.unique", errorPath = "referentie")
 * 
 * @author Elze Kool <info@visualmedia.nl>
 */
class Form extends FormModel
{
    /**
     * @var int
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var ArrayCollection
     * @ORM\OneToMany(targetEntity="FormField", mappedBy="form", orphanRemoval = true, fetch="EXTRA_LAZY", cascade = { "remove" })
     * @ORM\OrderBy({"volgorde" = "ASC"})
     * @Assert\Valid()
     */
    private $fields;

    /**
     * @var ArrayCollection
     * @ORM\OneToMany(targetEntity="FormEntry", mappedBy="form", orphanRemoval = true, fetch="EXTRA_LAZY", cascade = { "remove" })
     */
    private $entries;

    /**
     * @var string
     * @ORM\Column(name="titel", type="string", nullable=false)
     * @Assert\NotBlank(message = "form.titel.not_blank")
     */
    private $titel;

    /**
     * @var string
     * @ORM\Column(name="referentie", type="string", nullable=false, unique=true)
     * @Assert\NotBlank(message = "form.referentie.not_blank")
     * @Assert\Regex(pattern = "/^[a-z0-9_\-]+$/", message = "form.referentie.regex")
     */
    private $referentie;

    /**
     * @var string
     * @ORM\Column(name="email_onderwerp", type="string", nullable=false)
     * @Assert\NotBlank(message = "form.email_onderwerp.not_blank")
     */
    private $emailOnderwerp;

    /**
     * @var string
     * @ORM\Column(name="ontvanger_email", type="string", nullable=false)
     * @Assert\NotBlank(message = "form.ontvanger_email.not_blank")
     */
    private $ontvangerEmail;

    /**
     * @var string
     * @ORM\Column(name="ontvanger_naam", type="string", nullable=false)
     * @Assert\NotBlank(message = "form.ontvanger_naam.not_blank")
     */
    private $ontvangerNaam;

    /**
     * @var string
     * @ORM\Column(name="bcc_email", type="string", nullable=true)
     */
    private $bccEmail;

    /**
     * @var string
     * @ORM\Column(name="afzender_email", type="string", nullable=false)
     * @Assert\NotBlank(message = "form.afzender_email.not_blank")
     */
    private $afzenderEmail;

    /**
     * @var string
     * @ORM\Column(name="afzender_naam", type="string", nullable=false)
     * @Assert\NotBlank(message = "form.afzender_naam.not_blank")
     */
    private $afzenderNaam;

    /**
     * @var bool
     * @ORM\Column(name="kopie_naar_afzender", type="boolean", nullable=false)
     */
    private $kopieNaarAfzender;

    /**
     * @var string
     * @ORM\Column(name="redirect_path", type="string", nullable=false)
     * @Assert\NotBlank(message = "form.redirect_path.not_blank")
     */
    private $redirectPath;

    /**
     * @var string
     * @ORM\Column(name="form_html", type="text", nullable=false)
     * @Assert\NotBlank(message = "form.form_html.not_blank")
     */
    private $formHtml;

    /**
     * @var string
     * @ORM\Column(name="email_html", type="text", nullable=false)
     * @Assert\NotBlank(message = "form.email_html.not_blank")
     */
    private $emailHtml;

    /**
     * @var string
     * @ORM\Column(name="kopie_email_onderwerp", type="string", nullable=true)
     */
    private $kopieEmailOnderwerp;

    /**
     * @var string
     * @ORM\Column(name="kopie_email_html", type="text", nullable=true)
     */
    private $kopieEmailHtml;


    /**
     * @var DateTime
     * @Gedmo\Timestampable(on="create")
     * @ORM\Column(name="toegevoegd", type="datetime")
     */
    protected $toegevoegd;

    /**
     * @var DateTime
     * @Gedmo\Timestampable(on="update")
     * @ORM\Column(name="gewijzigd", type="datetime")
     */
    protected $gewijzigd;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->kopieNaarAfzender = true;
        $this->fields = new ArrayCollection();
        $this->entries = new ArrayCollection();
    }

    /**
     * Get string representation
     * @return string String representation
     */
    public function __toString()
    {
        return $this->titel;
    }

    /**
     * Clone
     */
    public function __clone()
    {
        if ($this->getId() === null) {
            return;
        }
        
        $this->entries = new ArrayCollection();
        $this->referentie = null;

        $fields = new ArrayCollection();
        foreach ($this->fields as $field) {
            $fieldClone = clone $field;
            $fieldClone->setForm(null);
            $fields->add($fieldClone);
        }

        $this->fields = $fields;        
    }

        /**
     * Get Id
     *
     * @return int Id
     **/
    public function getId()
    {
        return $this->id;
    }

    /**
     * Get Fields
     *
     * @return ArrayCollection Fields
     **/
    public function getFields()
    {
        return $this->fields;
    }

    /**
     * Set Fields
     *
     * @param ArrayCollection $fields Fields
     **/
    public function setFields($fields)
    {
        $this->fields = $fields;
    }

    /**
     * Get Entries
     *
     * @return ArrayCollection Entries
     **/
    public function getEntries()
    {
        return $this->entries;
    }

    /**
     * Get Titel
     *
     * @return string Titel
     **/
    public function getTitel()
    {
        return $this->titel;
    }

    /**
     * Set Titel
     *
     * @param string $titel Titel
     **/
    public function setTitel($titel)
    {
        $this->titel = $titel;
    }

    /**
     * Get Referentie
     *
     * @return string Referentie
     **/
    public function getReferentie()
    {
        return $this->referentie;
    }

    /**
     * Set Referentie
     *
     * @param string $referentie Referentie
     **/
    public function setReferentie($referentie)
    {
        $this->referentie = $referentie;
    }

    /**
     * Get E-mail Ontwerp
     *
     * @return string E-mail Ontwerp
     **/
    public function getEmailOnderwerp()
    {
        return $this->emailOnderwerp;
    }

    /**
     * Set E-mail Ontwerp
     *
     * @param string $emailOnderwerp E-mail Ontwerp
     **/
    public function setEmailOnderwerp($emailOnderwerp)
    {
        $this->emailOnderwerp = $emailOnderwerp;
    }

    /**
     * Get Ontvanger E-mailadres
     *
     * @return string Ontvanger E-mailadres
     **/
    public function getOntvangerEmail()
    {
        return $this->ontvangerEmail;
    }

    /**
     * Set Ontvanger E-mailadres
     *
     * @param string $ontvangerEmail Ontvanger E-mailadres
     **/
    public function setOntvangerEmail($ontvangerEmail)
    {
        $this->ontvangerEmail = $ontvangerEmail;
    }

    /**
     * Get Bcc E-mail
     *
     * @return string Bcc E-mail
     **/
    public function getBccEmail()
    {
        return $this->bccEmail;
    }

    /**
     * Set Bcc E-mail
     *
     * @param string $bccEmail Bcc E-mail
     **/
    public function setBccEmail($bccEmail)
    {
        $this->bccEmail = $bccEmail;
    }

    /**
     * Get Ontvanger Naam
     *
     * @return string Ontvanger Naam
     **/
    public function getOntvangerNaam()
    {
        return $this->ontvangerNaam;
    }

    /**
     * Set Ontvanger Naam
     *
     * @param string $ontvangerNaam Ontvanger Naam
     **/
    public function setOntvangerNaam($ontvangerNaam)
    {
        $this->ontvangerNaam = $ontvangerNaam;
    }

    /**
     * Get Afzender E-mailadres
     *
     * @return string Afzender E-mailadres
     **/
    public function getAfzenderEmail()
    {
        return $this->afzenderEmail;
    }

    /**
     * Set Afzender E-mailadres
     *
     * @param string $afzenderEmail Afzender E-mailadres
     **/
    public function setAfzenderEmail($afzenderEmail)
    {
        $this->afzenderEmail = $afzenderEmail;
    }

    /**
     * Get Afzender Naam
     *
     * @return string Afzender Naam
     **/
    public function getAfzenderNaam()
    {
        return $this->afzenderNaam;
    }

    /**
     * Set Afzender Naam
     *
     * @param string $afzenderNaam Afzender Naam
     **/
    public function setAfzenderNaam($afzenderNaam)
    {
        $this->afzenderNaam = $afzenderNaam;
    }

    /**
     * Get Kopie sturen naar afzender
     *
     * @return bool Kopie sturen naar afzender
     **/
    public function getKopieNaarAfzender()
    {
        return $this->kopieNaarAfzender;
    }

    /**
     * Set Kopie sturen naar afzender
     *
     * @param bool $kopieNaarAfzender Kopie sturen naar afzender
     **/
    public function setKopieNaarAfzender($kopieNaarAfzender)
    {
        $this->kopieNaarAfzender = $kopieNaarAfzender;
    }

    /**
     * Get RedirectPath
     *
     * @return string RedirectPath
     **/
    public function getRedirectPath()
    {
        return $this->redirectPath;
    }

    /**
     * Set RedirectPath
     *
     * @param string $redirectPath RedirectPath
     **/
    public function setRedirectPath($redirectPath)
    {
        $this->redirectPath = $redirectPath;
    }

    /**
     * Get Form HTML
     *
     * @return string Form HTML
     **/
    public function getFormHtml()
    {
        return $this->formHtml;
    }

    /**
     * Set Form HTML
     *
     * @param string $formHtml Form HTML
     **/
    public function setFormHtml($formHtml)
    {
        $this->formHtml = $formHtml;
    }

    /**
     * Get E-mail HTML
     *
     * @return string E-mail HTML
     **/
    public function getEmailHtml()
    {
        return $this->emailHtml;
    }

    /**
     * Set E-mail HTML
     *
     * @param string $emailHtml E-mail HTML
     **/
    public function setEmailHtml($emailHtml)
    {
        $this->emailHtml = $emailHtml;
    }

    /**
     * Get Kopie E-mail Onderwerp
     *
     * @return string Kopie E-mail Onderwerp
     **/
    public function getKopieEmailOnderwerp()
    {
        return $this->kopieEmailOnderwerp;
    }

    /**
     * Set Kopie E-mail Onderwerp
     *
     * @param string $kopieEmailOnderwerp Kopie E-mail Onderwerp
     **/
    public function setKopieEmailOnderwerp($kopieEmailOnderwerp)
    {
        $this->kopieEmailOnderwerp = $kopieEmailOnderwerp;
    }

    /**
     * Get Kopie E-mail HTML
     *
     * @return string Kopie E-mail HTML
     **/
    public function getKopieEmailHtml()
    {
        return $this->kopieEmailHtml;
    }

    /**
     * Set Kopie E-mail HTML
     *
     * @param string $kopieEmailHtml Kopie E-mail HTML
     **/
    public function setKopieEmailHtml($kopieEmailHtml)
    {
        $this->kopieEmailHtml = $kopieEmailHtml;
    }

    /**
     * Get Toegevoegd
     *
     * @return DateTime Toegevoegd
     **/
    public function getToegevoegd()
    {
        return $this->toegevoegd;
    }

    /**
     * Set Toegevoegd
     *
     * @param DateTime $toegevoegd Toegevoegd
     **/
    public function setToegevoegd($toegevoegd)
    {
        $this->toegevoegd = $toegevoegd;
    }

    /**
     * Get Gewijzigd
     *
     * @return DateTime Gewijzigd
     **/
    public function getGewijzigd()
    {
        return $this->gewijzigd;
    }

    /**
     * Set Gewijzigd
     *
     * @param DateTime $gewijzigd Gewijzigd
     **/
    public function setGewijzigd($gewijzigd)
    {
        $this->gewijzigd = $gewijzigd;
    }
    
}