<commit_before><?php

namespace Lists\ContactBundle\Form;

use Lists\ContactBundle\Entity\ModelContactLevelRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Lists\ContactBundle\Entity\ModelContactRepository;

/**
 * Class ModelContactOrganizationFormType
 */
class ModelContactOrganizationFormType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('modelName', 'hidden', array(
                'data' => ModelContactRepository::MODEL_ORGANIZATION
            ))
            ->add('modelId', 'text')
            ->add('firstName')
            ->add('lastName')
            ->add('middleName')
            ->add('phone1')
            ->add('phone2')
            ->add('position')
            ->add('birthday', 'birthday', array(
                'widget' => 'single_text',
                'format' => 'dd.M.yyyy'
            ))
            ->add('email')
            ->add('type', null, array(
                'required' => true
            ))
            ->add('level', null, array(
                'required' => true,
                'query_builder' => function (ModelContactLevelRepository $repository) {
                        return $repository->createQueryBuilder('mcl')
                            ->orderBy('mcl.digit', 'ASC');
                }
            ));

        $builder
            ->add('add', 'submit')
            ->add('cancel', 'button');
    }

    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Lists\ContactBundle\Entity\ModelContact',
            'translation_domain' => 'ListsContactBundle'
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'modelContactOrganizationForm';
    }
}
<commit_msg>task 557 - form add user (role sales)<commit_after><?php

namespace Lists\ContactBundle\Form;

use Lists\ContactBundle\Entity\ModelContactLevelRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Lists\ContactBundle\Entity\ModelContactRepository;

/**
 * Class ModelContactOrganizationFormType
 */
class ModelContactOrganizationFormType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('modelName', 'hidden', array(
                'data' => ModelContactRepository::MODEL_ORGANIZATION
            ))
            ->add('modelId', 'text')
            ->add('firstName')
            ->add('lastName')
            ->add('middleName')
            ->add('phone1')
            ->add('phone2')
            ->add('position')
            ->add('birthday', 'birthday', array(
                'widget' => 'single_text',
                'format' => 'dd.M.yyyy'
            ))
            ->add('email')
            ->add('type', null, array(
                'required' => true
            ))
            ->add('level', null, array(
                'required' => true,
                'query_builder' => function (ModelContactLevelRepository $repository) {
                        return $repository->createQueryBuilder('mcl')
                            ->orderBy('mcl.digit', 'ASC');
                }
            ));

        $builder
            ->add('add', 'submit')
            ->add('cancel', 'button');
        $builder->addEventListener(
            FormEvents::POST_SUBMIT,
            function (FormEvent $event) use ($container) {
                $data = $event->getData();

                $form = $event->getForm();

                if ($data) {
                    if (!$data->getPhone1() && !$data->getPhone2() && !$data->getEmail()) {
                        $translator = $container->get('translator');

                        $msg = $translator->trans("Enter Phone or Phone mob or email", array(), 'ListsContactBundle');

                        $form->get('phone1')->addError(new FormError($msg));
                    }
                    if (!$data->getLevel()) {
                        $translator = $container->get('translator');

                        $msg = $translator->trans("Enter level", array(), 'ListsContactBundle');

                        $form->get('level')->addError(new FormError($msg));
                    }
                }
            }
        );
    }

    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Lists\ContactBundle\Entity\ModelContact',
            'translation_domain' => 'ListsContactBundle'
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'modelContactOrganizationForm';
    }
}

{'fraction_non_alphanumeric': 0.13761822042076818, 'fraction_numerical': 0.0019301293186643506, 'mean_word_length': 1.8239782016348773, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4939882', 'n_tokens_mistral': 1364, 'n_tokens_neox': 1306, 'n_words': 228}