Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 7292 | Autoría | Ultima modificación | Ver Log |

<?php

declare(strict_types=1);

namespace LeadersLinked\Form;
use LeadersLinked\Mapper\IndustryMapper;
use LeadersLinked\Mapper\JobDescriptionMapper;
use LeadersLinked\Mapper\SkillMapper;
use LeadersLinked\Mapper\LanguageMapper;
use LeadersLinked\Mapper\CompanyMapper;
use Laminas\Form\Form;
use Laminas\Db\Adapter\AdapterInterface;
use LeadersLinked\Mapper\OrganizationalClimateMapper;
use LeadersLinked\Mapper\OrganizationalClimateFormMapper;
use LeadersLinked\Model\OrganizationalClimate;


class OrganizationalClimateSegmentedForm extends Form
{

    public function __construct($adapter, $company_id) 
    {
        parent::__construct();
        $this->setInputFilter(new OrganizationalClimateSegmentedFilter($adapter, $company_id));

        $this->add([
            'name' => 'segmented',
            'type' => \Laminas\Form\Element\Select::class,
            'attributes' => [
                'id'                    => 'segmented',
            ],'options' => [
                'disable_inarray_validator' => true,
                'empty_option' => 'LABEL_SEGMENTED',
                'value_options' => [
                   'description' => 'LABEL_JOB_DESCRIPTION',
                   'skill' => 'LABEL_SKILLS',
                   'industry' => 'LABEL_INDUSTRY',
                   'location' => 'LABEL_LOCATION',
                   'languages' => 'LABEL_LANGUAGES',
                ],
            ],
        ]);

        $this->add([
            'name' => 'job_description_id',
            'type' => \Laminas\Form\Element\Select::class,
             'attributes' => [
                'id'                    => 'job_description_id',
                'multiple'      => 'yes',
             ],
             'options' => [
                'disable_inarray_validator' => true,
                'value_options' => $this->getDescriptionSelectOptions($adapter, $company_id)
            ]
        ]);

        $this->add([
            'name' => 'skill_id',
            'type' => \Laminas\Form\Element\Select::class,
             'attributes' => [
                'id'                    => 'skill_id',
                'multiple'      => 'yes',
             ],
             'options' => [
                'disable_inarray_validator' => true,
                'value_options' => $this->getSkillSelectOptions($adapter)
            ]
        ]);

        $this->add([
            'name' => 'language_id',
            'type' => \Laminas\Form\Element\Select::class,
             'attributes' => [
                'id'                    => 'language_id',
                'multiple'      => 'yes',
             ],
             'options' => [
                'disable_inarray_validator' => true,
                'value_options' => $this->getLanguageSelectOptions($adapter)
            ]
        ]);

        $this->add([
            'name' => 'location',
            'type' => \Laminas\Form\Element\Text::class,
            'attributes' => [
                'maxlength'     => 250,
                'id'                    => 'location',
            ]
        ]);
        
        $this->add([
            'name' => 'address1',
            'type' => \Laminas\Form\Element\Hidden::class,
            'attributes' => [
                'id'    => 'address1',
            ]
        ]);
        
        $this->add([
            'name' => 'address2',
            'type' => \Laminas\Form\Element\Hidden::class,
            'attributes' => [
                'id'    => 'address2',
            ]
        ]);
        
        $this->add([
            'name' => 'country',
            'type' => \Laminas\Form\Element\Hidden::class,
            'attributes' => [
                'id'    => 'country',
            ]
        ]);
        
        $this->add([
            'name' => 'state',
            'type' => \Laminas\Form\Element\Hidden::class,
            'attributes' => [
                'id'    => 'state',
            ]
        ]);
        
        $this->add([
            'name' => 'city1',
            'type' => \Laminas\Form\Element\Hidden::class,
            'attributes' => [
                'id'    => 'city1',
            ]
        ]);
        
        $this->add([
            'name' => 'city2',
            'type' => \Laminas\Form\Element\Hidden::class,
            'attributes' => [
                'id'    => 'city2',
            ]
        ]);
        
        $this->add([
            'name' => 'postal_code',
            'type' => \Laminas\Form\Element\Hidden::class,
            'attributes' => [
                'id'    => 'postal_code',
            ]
        ]);
        
        $this->add([
            'name' => 'latitude',
            'type' => \Laminas\Form\Element\Hidden::class,
            'attributes' => [
                'id'    => 'latitude',
            ]
        ]);
        
        $this->add([
            'name' => 'longitude',
            'type' => \Laminas\Form\Element\Hidden::class,
            'attributes' => [
                'id'    => 'longitude',
            ]
        ]);

        $this->add([
            'name' => 'industry_id',
            'type' => \Laminas\Form\Element\Select::class,
             'attributes' => [
                'id'                    => 'industry_id',
                'multiple'      => 'yes',
             ],
             'options' => [
                'disable_inarray_validator' => true,
                'value_options' => $this->getIndustrySelectOptions($adapter)
            ]
        ]);

    }

    /**
     *
     * @param AdapterInterface $adapter
     */
    private function getFormSelectOptions($adapter, $company_id)
    {
        $options = [];
        
        $mapper = OrganizationalClimateFormMapper::getInstance($adapter);
        $records = $mapper->fetchAllByCompanyId($company_id);
        

        foreach($records as $record)
        {
            $options[$record->uuid] = $record->name;    
        }
        return $options;
    }

    private function getDescriptionSelectOptions($adapter, $company_id)
    {
        $options = [];
        
        $mapper = JobDescriptionMapper::getInstance($adapter);
        $records = $mapper->fetchAllActiveByCompanyId($company_id);
    
        

        foreach($records as $record)
        {
            $options[$record->uuid] = $record->name;    
        }
        
        
        return $options;
    }

    function getSkillSelectOptions($adapter)
    {
        $options = [];

        $mapper = SkillMapper::getInstance($adapter);
        $records = $mapper->fetchAllActive();

        foreach($records as $record)
        {
            $options[$record->uuid] = $record->name;
        }
        return $options;
    }

    function getIndustrySelectOptions($adapter)
    {
        $options = [];

        $mapper = IndustryMapper::getInstance($adapter);
        $records = $mapper->fetchAllActive();

        foreach($records as $record)
        {
            $options[$record->uuid] = $record->name;
        }
        return $options;
    }

    function getLanguageSelectOptions($adapter)
    {
        $options = [];

        $mapper = LanguageMapper::getInstance($adapter);
        $records = $mapper->fetchAll();

        foreach($records as $record)
        {
            $options[$record->id] = $record->name;
        }
        return $options;
    }
    
}