Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

<?php

declare(strict_types=1);

namespace LeadersLinked\Form\MyCompanies;

use Laminas\Form\Form;
use Laminas\Db\Adapter\AdapterInterface;
use Laminas\Log\LoggerInterface;
use LeadersLinked\Mapper\CompanySizeMapper;
use LeadersLinked\Mapper\IndustryMapper;

class CreateForm extends Form
{
    /**
     * 
     * @param AdapterInterface $adapter
     */
    public function __construct($adapter) 
    {
        parent::__construct();
        $this->setInputFilter(new CreateFilter($adapter));
        
        $this->add([
            'name' => 'name',
            'type' => \Laminas\Form\Element\Text::class,
             'attributes' => [
                'maxlength'     => 128,
                'id'                    => 'name',
            ]
         ]);
        $this->add([
             'name' => 'industry_id',
             'type' => \Laminas\Form\Element\Select::class,
             'options' => [
                 'value_options' => $this->optionsIndustry($adapter),
             ],
             'attributes' => [
                 'id' => 'industry_id',
             ]
         ]);
        $this->add([
            'name' => 'company_size_id',
            'type' => \Laminas\Form\Element\Select::class,
            'options' => [
                'value_options' => $this->optionsCompanySize($adapter),
            ],
            'attributes' => [
                'id' => 'company_size_id',
            ]
        ]);
    }
    
    /**
     *
     * @param AdapterInterface $adapter
     * @param LoggerInterface $logger
     * @return array
     */
    private function optionsCompanySize($adapter)
    {
        $companySizeMapper = CompanySizeMapper::getInstance($adapter);
        $companySizes = $companySizeMapper->fetchAllActive();
        
        $options = [];
        foreach($companySizes as $companySize)
        {
            $options[$companySize->uuid] = $companySize->name . ' ( ' . $companySize->minimum_no_of_employee . ' - ' . $companySize->maximum_no_of_employee . ' )';
        }
        
        return $options;
    }
    
    /**
     *
     * @param AdapterInterface $adapter
     * @return array
     */
    private function optionsIndustry($adapter)
    {
        $industryMapper = IndustryMapper::getInstance($adapter);
        $industries  = $industryMapper->fetchAllActive();
        
        $options = [];
        foreach($industries as $industry)
        {
            $options[$industry->uuid] = $industry->name;
        }
        
        return $options;
    }
   
}