Proyectos de Subversion LeadersLinked - Backend

Rev

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

<?php

declare(strict_types=1);

namespace LeadersLinked\Form\Planning;

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

class PlanningTaskForm extends Form
{
    
    /**
     * 
     * @param AdapterInterface $adapter
     * @param int $company_id
     */
    public function __construct($adapter, $company_id)
    {
        parent::__construct();
        
        $this->setInputFilter(new PlanningTaskFilter());
        
        $this->add([
            'name' => 'title',
            'type' => \Laminas\Form\Element\Text::class,
            'attributes' => [
                'maxlength'     => 128,
                'id'                    => 'title',
            ]
        ]);
        
        $this->add([
            'name' => 'description',
            'type' => \Laminas\Form\Element\Textarea::class,
            'attributes' => [
                'id'    => 'description',
                'maxlength'     => 1024,
                'rows' => 5,
            ]
        ]);
        
        $this->add([
            'name' => 'place',
            'type' => \Laminas\Form\Element\Textarea::class,
            'attributes' => [
                'id'    => 'place',
                'maxlength'     => 254,
                'rows' => 5,
            ]
        ]);
        
        $this->add([
            'name' => 'how',
            'type' => \Laminas\Form\Element\Textarea::class,
            'attributes' => [
                'id'    => 'how',
                'maxlength'     => 1024,
                'rows' => 5,
            ]
        ]);
        
        $this->add([
            'name' => 'detour',
            'type' => \Laminas\Form\Element\Textarea::class,
            'attributes' => [
                'id'    => 'detour',
                'maxlength'     => 1024,
                'rows' => 5,
            ]
        ]);
        
        $this->add([
            'name' => 'evaluation',
            'type' => \Laminas\Form\Element\Textarea::class,
            'attributes' => [
                'id'    => 'evaluation',
                'maxlength'     => 1024,
                'rows' => 5,
            ]
        ]);
        
        
        $this->add([
            'name' => 'user_id',
            'type' => \Laminas\Form\Element\Select::class,
            'attributes' => [
                'required'=> true,
                'multiple'      => 'yes',
                'id' => 'user_id'
            ],
            'options' => [
                'disable_inarray_validator' => true,
                'value_options' => $this->getSelectOptions($adapter,$company_id)
            ]
        ]);
  
        $this->add([
            'name' => 'progress',
            'type' => \Laminas\Form\Element\Number::class,
            'attributes' => [
                'min' => 0,
                'max' => 100,
                'step' => 1,
                'id' => 'progress',
            ]
        ]);
        
        
        $this->add([
            'name' => 'status',
            'type' => \Laminas\Form\Element\Checkbox::class,
            'attributes' => [
                'id'                    => 'status',
            ],
            'options' => [
                'use_hidden_element' => false,
                'unchecked_value' => \LeadersLinked\Model\PlanningGoal::STATUS_INACTIVE,
                'checked_value'=> \LeadersLinked\Model\PlanningGoal::STATUS_ACTIVE,
            ]
        ]);
        
        $this->add([
            'name' => 'priority',
            'type' => \Laminas\Form\Element\Checkbox::class,
            'attributes' => [
                'id'                    => 'priority',
            ],
            'options' => [
                'use_hidden_element' => false,
                'unchecked_value' => \LeadersLinked\Model\PlanningTask::NO,
                'checked_value'=> \LeadersLinked\Model\PlanningTask::YES,
            ]
        ]);
        
        
        $this->add([
            'name' => 'urgent',
            'type' => \Laminas\Form\Element\Checkbox::class,
            'attributes' => [
                'id'                    => 'urgent',
            ],
            'options' => [
                'use_hidden_element' => false,
                'unchecked_value' => \LeadersLinked\Model\PlanningTask::NO,
                'checked_value'=> \LeadersLinked\Model\PlanningTask::YES,
            ]
        ]);
        
        
        $this->add([
            'name' => 'date_range',
            'type' => \Laminas\Form\Element\Text::class,
            'attributes' => [
                'id'    => 'date_range',
            ]
        ]);
        
        $this->add([
            'name' => 'start',
            'type' => \Laminas\Form\Element\Hidden::class,
            'attributes' => [
                'id'    => 'start',
            ],
        ]);
        
        $this->add([
            'name' => 'end',
            'type' => \Laminas\Form\Element\Hidden::class,
            'attributes' => [
                'id'    => 'end',
            ],
        ]);
        
        $this->add([
            'name' => 'cost',
            'type' => \Laminas\Form\Element\Number::class,
            'attributes' => [
                'id'    => 'cost',
                'step' => 0.01,
                'min' => 0,
                'max' => 999999999999.99
            ],
        ]);

        $this->add([
            'name' => 'hours',
            'type' => \Laminas\Form\Element\Number::class,
            'attributes' => [
                'id'    => 'hours',
                'step' => 0.01,
                'min' => 0,
                'max' => 9999
            ],
        ]);
        
    }
  
    private function getSelectOptions($adapter, $company_id) 
    {
        $items = [];
        $mapper = UserMapper::getInstance($adapter);
        $records = $mapper->fetchAllByCompanyId( $company_id );
      
        foreach($records as $record)
        {
            $items[ $record->uuid ] = trim($record->first_name . ' ' . $record->last_name) . ' (' . $record->email . ')';
        }

        return $items;
    }

}