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

namespace VisualM\FormBundle\Entity;

use DateTime;
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\Doctrine\FieldType\FormFieldType;
use VisualM\FormBundle\Model\FormFieldModel;

/**
 * FormField
 *
 * @ORM\Entity(repositoryClass="FormFieldRepository")
 * @ORM\Table(name="form_field", indexes= {
 *    @ORM\Index(name="form_fields_idx", columns={ "form_id", "volgorde" })
 * })
 * @UniqueEntity(fields = { "form", "referentie" }, message = "form_field.referentie.unique", errorPath = "referentie")
 * 
 * @author Elze Kool <info@visualmedia.nl>
 */
class FormField extends FormFieldModel
{
    /**
     * @var int
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var Form
     * @ORM\ManyToOne(targetEntity="Form", inversedBy="fields")
     * @ORM\JoinColumn(name="form_id", referencedColumnName="id", nullable = false)
     */
    private $form;

    /**
     * @var int
     * @ORM\Column(name="volgorde", type="integer", nullable = false)
     */
    private $volgorde;

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

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

    /**
     * @var bool
     * @ORM\Column(name="verplicht", type="boolean", nullable = false)
     * @Assert\NotBlank(message = "form_field.verplicht.not_blank")
     */
    private $verplicht;

    /**
     * @var int
     * @ORM\Column(name="rijen", type="integer", nullable = true)
     */
    private $rijen;

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

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

    /**
     * @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->type = FormFieldType::TEXT;
        $this->verplicht = false;
        $this->volgorde = 0;
        $this->rijen = 2;
    }

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

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

    /**
     * Get Form
     *
     * @return Form Form
     **/
    public function getForm()
    {
        return $this->form;
    }

    /**
     * Set Form
     *
     * @param Form $form Form
     **/
    public function setForm($form)
    {
        $this->form = $form;
    }

    /**
     * Get Volgorde
     *
     * @return int Volgorde
     **/
    public function getVolgorde()
    {
        return $this->volgorde;
    }

    /**
     * Set Volgorde
     *
     * @param int $volgorde Volgorde
     **/
    public function setVolgorde($volgorde)
    {
        $this->volgorde = $volgorde;
    }

    /**
     * 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 Type
     *
     * @return string Type
     **/
    public function getType()
    {
        return $this->type;
    }

    /**
     * Set Type
     *
     * @param string $type Type
     **/
    public function setType($type)
    {
        $this->type = $type;
    }

    /**
     * Get Verplicht
     *
     * @return bool Verplicht
     **/
    public function getVerplicht()
    {
        return $this->verplicht;
    }

    /**
     * Set Verplicht
     *
     * @param bool $verplicht Verplicht
     **/
    public function setVerplicht($verplicht)
    {
        $this->verplicht = $verplicht;
    }

    /**
     * Get Grootte
     *
     * @return string Grootte
     **/
    public function getGrootte()
    {
        return $this->grootte;
    }

    /**
     * Set Grootte
     *
     * @param string $grootte Grootte
     **/
    public function setGrootte($grootte)
    {
        $this->grootte = $grootte;
    }

    /**
     * Get Rijen
     *
     * @return int Rijen
     **/
    public function getRijen()
    {
        return $this->rijen;
    }

    /**
     * Set Rijen
     *
     * @param int $rijen Rijen
     **/
    public function setRijen($rijen)
    {
        $this->rijen = $rijen;
    }

    /**
     * Get Regex
     *
     * @return string Regex
     **/
    public function getRegex()
    {
        return $this->regex;
    }

    /**
     * Set Regex
     *
     * @param string $regex Regex
     **/
    public function setRegex($regex)
    {
        $this->regex = $regex;
    }

    /**
     * Get Waarden
     *
     * @return string Waarden
     **/
    public function getWaarden()
    {
        return $this->waarden;
    }

    /**
     * Set Waarden
     *
     * @param string $waarden Waarden
     **/
    public function setWaarden($waarden)
    {
        $this->waarden = $waarden;
    }

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

    /**
     * Set DateTime
     *
     * @param Toegevoegd $toegevoegd DateTime
     **/
    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;
    }

    
}

