<commit_before><?php
/**
 * Litus is a project by a group of students from the KU Leuven. The goal is to create
 * various applications to support the IT needs of student unions.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 *
 * @license http://litus.cc/LICENSE
 */

namespace BrBundle\Form\Admin\Company;

use BrBundle\Entity\Company;

/**
 * Add a company.
 *
 * @author <NAME> <<EMAIL>>
 */
class Add extends \CommonBundle\Component\Form\Admin\Form
{
    protected $hydrator = 'BrBundle\Hydrator\Company';

    /**
     * @var Company|null
     */
    protected $company;

    public function init()
    {
        parent::init();

        $this->add(
            array(
                'type'     => 'text',
                'name'     => 'name',
                'label'    => 'Company Name',
                'required' => true,
                'options'  => array(
                    'input' => array(
                        'filters' => array(
                            array('name' => 'StringTrim'),
                        ),
                        'validators' => array(
                            array(
                                'name'    => 'CompanyName',
                                'options' => array(
                                    'company' => $this->company,
                                ),
                            ),
                        ),
                    ),
                ),
            )
        );

        $this->add(
            array(
                'type'       => 'select',
                'name'       => 'sector',
                'label'      => 'Sector',
                'required'   => true,
                'attributes' => array(
                    'options' => Company::POSSIBLE_SECTORS,
                ),
            )
        );

        $this->add(
            array(
                'type'     => 'text',
                'name'     => 'vat_number',
                'label'    => 'VAT Number',
                'required' => true,
                'options'  => array(
                    'input' => array(
                        'filters' => array(
                            array('name' => 'StringTrim'),
                        ),
                    ),
                ),
            )
        );

        $this->add(
            array(
                'type'     => 'text',
                'name'     => 'matching_software_email',
                'label'    => 'Email for Matching Software',
                'options'  => array(
                    'input' => array(
                        'filters' => array(
                            array('name' => 'StringTrim'),
                        ),
                        'validators' => array(
                            array(
                                'name' => 'EmailAddress',
                            ),
                        ),
                    ),
                ),
            )
        );

        $this->add(
            array(
                'type'       => 'text',
                'name'       => 'phone_number',
                'label'      => 'Phone Number',
                'required'   => false,
                'attributes' => array(
                    'placeholder' => '+CCAAANNNNNN',
                ),
                'options'    => array(
                    'input' => array(
                        'filters' => array(
                            array('name' => 'StringTrim'),
                        ),
                        'validators' => array(
                            array('name' => 'PhoneNumber'),
                        ),
                    ),
                ),
            )
        );

        $this->add(
            array(
                'type'     => 'text',
                'name'     => 'website',
                'label'    => 'Website',
                'required' => true,
                'options'  => array(
                    'input' => array(
                        'filters' => array(
                            array('name' => 'StringTrim'),
                        ),
                        'validators' => array(
                            array('name' => 'Uri'),
                        ),
                    ),
                ),
            )
        );

        $this->add(
            array(
                'type'       => 'select',
                'name'       => 'cvbook',
                'label'      => 'CV Book',
                'required'   => false,
                'attributes' => array(
                    'multiple'  => true,
                    'options'   => $this->getCvBookYears(),
                    'data-help' => 'The selected years will be visible in the corporate app of this company. The archived ones are downloadable in pdf format.',
                ),
            )
        );

        $this->add(
            array(
                'type'     => 'common_address_add',
                'name'     => 'address',
                'label'    => 'Address',
                'required' => true,
            )
        );

        array(
            'type'  => 'checkbox',
            'name'  => 'attendsJobfair',
            'label' => 'company is at Jobfair this year',
        );

        $this->add(
            array(
                'type'       => 'fieldset',
                'name'       => 'invoice',
                'label'      => 'Invoice Data',
                'attributes' => array(
                    'id' => 'invoice_form',
                ),
                'elements'   => array(
                    array(
                        'type'     => 'text',
                        'name'     => 'invoice_name',
                        'label'    => 'Company Invoice Name',
                        'required' => false,
                        'options'  => array(
                            'input' => array(
                                'filters' => array(
                                    array('name' => 'StringTrim'),
                                ),
                                'validators' => array(
                                    array(
                                        'name'    => 'CompanyName',
                                        'options' => array(
                                            'company' => $this->company,
                                        ),
                                    ),
                                ),
                            ),
                        ),
                    ),

                    array(
                        'type'     => 'text',
                        'name'     => 'invoice_vat_number',
                        'label'    => 'VAT Number',
                        'required' => false,
                        'options'  => array(
                            'input' => array(
                                'filters' => array(
                                    array('name' => 'StringTrim'),
                                ),
                            ),
                        ),
                    ),

                    array(
                        'type'     => 'common_address_add',
                        'name'     => 'invoice_address',
                        'label'    => 'Invoice Address',
                        'required' => true,
                    ),
                ),
            )
        );

        $this->add(
            array(
                'type'       => 'fieldset',
                'name'       => 'page',
                'label'      => 'Page',
                'attributes' => array(
                    'id' => 'page_form',
                ),
                'elements'   => array(
                    array(
                        'type'       => 'select',
                        'name'       => 'years',
                        'label'      => 'Page Visible During',
                        'attributes' => array(
                            'multiple' => true,
                            'options'  => $this->getYears(),
                        ),
                    ),
                    array(
                        'type'       => 'textarea',
                        'name'       => 'description',
                        'label'      => 'Description',
                        'attributes' => array(
                            'id' => 'description',
                        ),
                        'options'    => array(
                            'input' => array(
                                'filters' => array(
                                    array('name' => 'StringTrim'),
                                ),
                            ),
                        ),
                    ),
                    array(
                        'type'  => 'checkbox',
                        'name'  => 'atEvent',
                        'label' => 'company is at internshipfair',
                    ),
                ),
            )
        );

        $this->addSubmit('Add', 'company_add');

        if ($this->company !== null) {
            $this->bind($this->company);
        }
    }

    /**
     * @return array
     */
    private function getYears()
    {
        $years = $this->getEntityManager()
            ->getRepository('CommonBundle\Entity\General\AcademicYear')
            ->findAll();

        $options = array();
        foreach ($years as $year) {
            $options[$year->getId()] = $year->getCode();
        }

        return $options;
    }

    /**
     * @return array
     */
    private function getArchiveYears()
    {
        $years = unserialize(
            $this->getEntityManager()
                ->getRepository('CommonBundle\Entity\General\Config')
                ->getConfigValue('br.cv_archive_years')
        );

        $options = array();
        foreach ($years as $code => $year) {
            $options['archive-' . $code] = $year['full_year'] . ' (Archive)';
        }

        return $options;
    }

    /**
     * @return array
     */
    private function getCvBookYears()
    {
        $cvYears = $this->getArchiveYears();
        $years = $this->getYears();
        foreach ($years as $key => $year) {
            $shortCode = substr($year, 2, 2) . substr($year, 7, 2);
            if (isset($cvYears['archive-' . $shortCode])) {
                continue;
            }
            $cvYears['year-' . $key] = $year;
        }
        asort($cvYears);

        return $cvYears;
    }

    /**
     * @param  Company $company
     * @return self
     */
    public function setCompany(Company $company)
    {
        $this->company = $company;

        return $this;
    }
}
<commit_msg>Update Add.php<commit_after><?php
/**
 * Litus is a project by a group of students from the KU Leuven. The goal is to create
 * various applications to support the IT needs of student unions.
 *
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 *
 * @license http://litus.cc/LICENSE
 */

namespace BrBundle\Form\Admin\Company;

use BrBundle\Entity\Company;

/**
 * Add a company.
 *
 * @author <NAME> <<EMAIL>>
 */
class Add extends \CommonBundle\Component\Form\Admin\Form
{
    protected $hydrator = 'BrBundle\Hydrator\Company';

    /**
     * @var Company|null
     */
    protected $company;

    public function init()
    {
        parent::init();

        $this->add(
            array(
                'type'     => 'text',
                'name'     => 'name',
                'label'    => 'Company Name',
                'required' => true,
                'options'  => array(
                    'input' => array(
                        'filters' => array(
                            array('name' => 'StringTrim'),
                        ),
                        'validators' => array(
                            array(
                                'name'    => 'CompanyName',
                                'options' => array(
                                    'company' => $this->company,
                                ),
                            ),
                        ),
                    ),
                ),
            )
        );

        $this->add(
            array(
                'type'       => 'select',
                'name'       => 'sector',
                'label'      => 'Sector',
                'required'   => true,
                'attributes' => array(
                    'options' => Company::POSSIBLE_SECTORS,
                ),
            )
        );

        $this->add(
            array(
                'type'     => 'text',
                'name'     => 'vat_number',
                'label'    => 'VAT Number',
                'required' => true,
                'options'  => array(
                    'input' => array(
                        'filters' => array(
                            array('name' => 'StringTrim'),
                        ),
                    ),
                ),
            )
        );

        $this->add(
            array(
                'type'     => 'text',
                'name'     => 'matching_software_email',
                'label'    => 'Email for Matching Software',
                'options'  => array(
                    'input' => array(
                        'filters' => array(
                            array('name' => 'StringTrim'),
                        ),
                        'validators' => array(
                            array(
                                'name' => 'EmailAddress',
                            ),
                        ),
                    ),
                ),
            )
        );

        $this->add(
            array(
                'type'       => 'text',
                'name'       => 'phone_number',
                'label'      => 'Phone Number',
                'required'   => false,
                'attributes' => array(
                    'placeholder' => '+CCAAANNNNNN',
                ),
                'options'    => array(
                    'input' => array(
                        'filters' => array(
                            array('name' => 'StringTrim'),
                        ),
                        'validators' => array(
                            array('name' => 'PhoneNumber'),
                        ),
                    ),
                ),
            )
        );

        $this->add(
            array(
                'type'     => 'text',
                'name'     => 'website',
                'label'    => 'Website',
                'required' => true,
                'options'  => array(
                    'input' => array(
                        'filters' => array(
                            array('name' => 'StringTrim'),
                        ),
                        'validators' => array(
                            array('name' => 'Uri'),
                        ),
                    ),
                ),
            )
        );

        $this->add(
            array(
                'type'       => 'select',
                'name'       => 'cvbook',
                'label'      => 'CV Book',
                'required'   => false,
                'attributes' => array(
                    'multiple'  => true,
                    'options'   => $this->getCvBookYears(),
                    'data-help' => 'The selected years will be visible in the corporate app of this company. The archived ones are downloadable in pdf format.',
                ),
            )
        );

        $this->add(
            array(
                'type'     => 'common_address_add',
                'name'     => 'address',
                'label'    => 'Address',
                'required' => true,
            )
        );
        
        $this->add(
            array(
                'type'  => 'checkbox',
                'name'  => 'attends_jobfair',
                'label' => 'company is at Jobfair this year',
            )
        );

        $this->add(
            array(
                'type'       => 'fieldset',
                'name'       => 'invoice',
                'label'      => 'Invoice Data',
                'attributes' => array(
                    'id' => 'invoice_form',
                ),
                'elements'   => array(
                    array(
                        'type'     => 'text',
                        'name'     => 'invoice_name',
                        'label'    => 'Company Invoice Name',
                        'required' => false,
                        'options'  => array(
                            'input' => array(
                                'filters' => array(
                                    array('name' => 'StringTrim'),
                                ),
                                'validators' => array(
                                    array(
                                        'name'    => 'CompanyName',
                                        'options' => array(
                                            'company' => $this->company,
                                        ),
                                    ),
                                ),
                            ),
                        ),
                    ),

                    array(
                        'type'     => 'text',
                        'name'     => 'invoice_vat_number',
                        'label'    => 'VAT Number',
                        'required' => false,
                        'options'  => array(
                            'input' => array(
                                'filters' => array(
                                    array('name' => 'StringTrim'),
                                ),
                            ),
                        ),
                    ),

                    array(
                        'type'     => 'common_address_add',
                        'name'     => 'invoice_address',
                        'label'    => 'Invoice Address',
                        'required' => true,
                    ),
                ),
            )
        );

        $this->add(
            array(
                'type'       => 'fieldset',
                'name'       => 'page',
                'label'      => 'Page',
                'attributes' => array(
                    'id' => 'page_form',
                ),
                'elements'   => array(
                    array(
                        'type'       => 'select',
                        'name'       => 'years',
                        'label'      => 'Page Visible During',
                        'attributes' => array(
                            'multiple' => true,
                            'options'  => $this->getYears(),
                        ),
                    ),
                    array(
                        'type'       => 'textarea',
                        'name'       => 'description',
                        'label'      => 'Description',
                        'attributes' => array(
                            'id' => 'description',
                        ),
                        'options'    => array(
                            'input' => array(
                                'filters' => array(
                                    array('name' => 'StringTrim'),
                                ),
                            ),
                        ),
                    ),
                    array(
                        'type'  => 'checkbox',
                        'name'  => 'atEvent',
                        'label' => 'company is at internshipfair',
                    ),
                ),
            )
        );

        $this->addSubmit('Add', 'company_add');

        if ($this->company !== null) {
            $this->bind($this->company);
        }
    }

    /**
     * @return array
     */
    private function getYears()
    {
        $years = $this->getEntityManager()
            ->getRepository('CommonBundle\Entity\General\AcademicYear')
            ->findAll();

        $options = array();
        foreach ($years as $year) {
            $options[$year->getId()] = $year->getCode();
        }

        return $options;
    }

    /**
     * @return array
     */
    private function getArchiveYears()
    {
        $years = unserialize(
            $this->getEntityManager()
                ->getRepository('CommonBundle\Entity\General\Config')
                ->getConfigValue('br.cv_archive_years')
        );

        $options = array();
        foreach ($years as $code => $year) {
            $options['archive-' . $code] = $year['full_year'] . ' (Archive)';
        }

        return $options;
    }

    /**
     * @return array
     */
    private function getCvBookYears()
    {
        $cvYears = $this->getArchiveYears();
        $years = $this->getYears();
        foreach ($years as $key => $year) {
            $shortCode = substr($year, 2, 2) . substr($year, 7, 2);
            if (isset($cvYears['archive-' . $shortCode])) {
                continue;
            }
            $cvYears['year-' . $key] = $year;
        }
        asort($cvYears);

        return $cvYears;
    }

    /**
     * @param  Company $company
     * @return self
     */
    public function setCompany(Company $company)
    {
        $this->company = $company;

        return $this;
    }
}

{'fraction_non_alphanumeric': 0.13112063463116622, 'fraction_numerical': 0.00036473055530227043, 'mean_word_length': 0.7726684984645223, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 390, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3095035', 'n_tokens_mistral': 5447, 'n_tokens_neox': 4996, 'n_words': 1012}