<?php
/**
 * Created by PhpStorm.
 * User: vlade
 * Date: 7/2/15
 * Time: 6:58 PM
 */

namespace VGM\UserBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Doctrine\ORM\EntityRepository;

class RegistrationFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('email', 'email', array('label' => false,
                'translation_domain' => 'FOSUserBundle',
                'attr' => array('placeholder' => 'form.email')))
            ->add('username', null, array('label' => false,
                'translation_domain' => 'FOSUserBundle',
                'attr' => array('placeholder' => 'form.username')))
            ->add('plainPassword', 'repeated', array(
                'type' => 'password',
                'options' => array('translation_domain' => 'FOSUserBundle'),
                'first_options' => array('label' => false,
                    'attr' => array('placeholder' => 'form.password')),
                'second_options' => array('label' => false,
                    'attr' => array('placeholder' => 'form.password_confirmation')),
                'invalid_message' => 'fos_user.password.mismatch'))
            ->add('groups', 'entity', array(
                'class' => 'VGMUserBundle:Group',
                'property' => 'name',
                'expanded' => true,
                'multiple' => true,
                'required' => true,
                'empty_value' => '--Select Group--'
            ))
            ->add('worker', 'entity', array(
                'class' => 'VGMWOBundle:Worker',
                'query_builder' => function(EntityRepository $er) {
                        return $er->createQueryBuilder('w')
                            ->orderBy('w.name', 'ASC')->orderBy('w.lastname', 'ASC');
                    },
                'expanded' => false,
                'multiple' => false,
                'required' => true,
                'empty_value' => 'Select Worker'
            ));
    }

    public function getParent()
    {
        return 'fos_user_registration';
    }

    public function getName()
    {
        return 'vgm_user_registration';
    }
}