Proyectos de Subversion LeadersLinked - Services

Rev

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

<?php
declare(strict_types = 1);
namespace LeadersLinked\Form\UserProfile;

use Laminas\Form\Form;
use Laminas\Db\Adapter\AdapterInterface;
use LeadersLinked\Mapper\DegreeMapper;

class EducationForm extends Form
{

    /**
     *
     * @param AdapterInterface $adapter
     */
    public function __construct($adapter)
    {
        parent::__construct();

        $this->setInputFilter(new EducationFilter($adapter));

        $this->add([
            'name' => 'degree_id',
            'type' => \Laminas\Form\Element\Select::class,
            'options' => [
                'value_options' => $this->optionsDegree($adapter)
            ],
            'attributes' => [
                'id' => 'degree_id'
            ]
        ]);

        $this->add([
            'name' => 'university',
            'type' => \Laminas\Form\Element\Text::class,
            'attributes' => [
                'maxlength' => 128,
                'id' => 'university'
            ]
        ]);

        $this->add([
            'name' => 'field_of_study',
            'type' => \Laminas\Form\Element\Text::class,
            'attributes' => [
                'maxlength' => 128,
                'id' => 'field_of_study'
            ]
        ]);

        $this->add([
            'name' => 'from_year',
            'type' => \Laminas\Form\Element\Select::class,
            'attributes' => [
                'id' => 'from_year'
            ],
            'options' => [
                'value_options' => $this->optionsYears()
            ]
        ]);

        $this->add([
            'name' => 'to_year',
            'type' => \Laminas\Form\Element\Select::class,
            'attributes' => [
                'id' => 'to_year'
            ],
            'options' => [
                'value_options' => $this->optionsYears()
            ]
        ]);

        $this->add([
            'name' => 'grade_or_percentage',
            'type' => \Laminas\Form\Element\Text::class,
            'attributes' => [
                'maxlength' => 3,
                'id' => 'grade_or_percentage'
            ]
        ]);

        $this->add([
            'name' => 'description',
            'type' => \Laminas\Form\Element\Textarea::class,
            'attributes' => [
                'id' => 'description'
            ]
        ]);

        $this->add([
            'name' => 'education_location_search',
            'type' => \Laminas\Form\Element\Text::class,
            'attributes' => [
                'maxlength' => 250,
                'id' => 'education_location_search'
            ]
        ]);

        $this->add([
            'name' => 'formatted_address',
            'type' => \Laminas\Form\Element\Hidden::class,
            'attributes' => [
                'id' => 'formatted_address'
            ]
        ]);

        $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'
            ]
        ]);
    }

    /**
     *
     * @param AdapterInterface $adapter
     * @return array
     */
    private function optionsDegree($adapter)
    {
        $mapper = DegreeMapper::getInstance($adapter);
        $records = $mapper->fetchAllActive();

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

        return $items;
    }

    /**
     *
     * @return array
     */
    private function optionsYears()
    {
        $y = date('Y');
        $options = [];
        for ($i = 0; $i < 100; $i ++) {
            $options[$y - $i] = $y - $i;
        }

        return $options;
    }
}