Ir a la última revisión | 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 Laminas\Log\LoggerInterface;
use LeadersLinked\Model\PlanningTask;
use Laminas\Form\Element;
use LeadersLinked\Mapper\UserMapper;
use LeadersLinked\Mapper\CompanyUserMapper;
class PlanningTaskForm extends Form
{
public function __construct($adapter, $company_id){
parent::__construct();
$this->setInputFilter(new PlanningTaskFilter($adapter));
$this->add([
'name' => 'title',
'type' => \Laminas\Form\Element\Text::class,
'attributes' => [
'maxlength' => 254,
'id' => 'title',
]
]);
$this->add([
'name' => 'description',
'type' => \Laminas\Form\Element\Text::class,
'attributes' => [
'maxlength' => 254,
'id' => 'description',
]
]);
$this->add([
'name' => 'how',
'type' => \Laminas\Form\Element\Text::class,
'attributes' => [
'maxlength' => 254,
'id' => 'how',
]
]);
$this->add([
'name' => 'place',
'type' => \Laminas\Form\Element\Text::class,
'attributes' => [
'maxlength' => 254,
'id' => 'place',
]
]);
$this->add([
'name' => 'who',
'type' => \Laminas\Form\Element\Select::class,
'attributes' => [
'required'=> true,
'multiple' => 'yes',
'id' => 'who'
],
'options' => [
'disable_inarray_validator' => true,
'value_options' => $this->getSelectOptions($adapter,$company_id)
]
]);
$this->add([
'name' => 'time',
'type' => \Laminas\Form\Element\Number::class,
'attributes' => [
'min' => '0',
'step' => '1',
'id' => 'time',
]
]);
$this->add([
'name' => 'date',
'type' => Element\Date::class,
'attributes' => [
'maxlength' => 15,
'id' => 'date',
]
]);
$this->add([
'name' => 'detour',
'type' => \Laminas\Form\Element\Text::class,
'attributes' => [
'maxlength' => 254,
'id' => 'detour',
]
]);
$this->add([
'name' => 'evaluation',
'type' => \Laminas\Form\Element\Text::class,
'attributes' => [
'maxlength' => 254,
'id' => 'evaluation',
]
]);
$this->add([
'type' => Element\Range::class,
'name' => 'indicator',
'attributes' => [
'min'=> 1,
'max' => 100, // default maximum is 100
'id' => 'indicator',
],
]);
$this->add([
'name' => 'cost',
'type' => \Laminas\Form\Element\Number::class,
'attributes' => [
'min' => '0',
'step' => '1',
'id' => 'cost',
]
]);
$this->add([
'type' => Element\Select::class,
'name' => 'priority',
'options' => [
'empty_option' => 'LABEL_SELECT',
'value_options' =>[
'i' => 'LABEL_IMPORTANT',
'ni' => 'LABEL_NOT_IMPORTANT',
],
],
'attributes'=> [
'required'=> true,
'class' => 'Custom-select',
'id' => 'priority',
]
]);
$this->add([
'type' => Element\Select::class,
'name' => 'urgent',
'options' => [
'empty_option' => 'LABEL_SELECT',
'value_options' =>[
'u' => 'LABEL_URGENT',
'nu' => 'LABEL_NOT_URGENT'
],
],
'attributes'=> [
'required'=> true,
'class' => 'Custom-select',
'id' => 'urgent',
]
]);
$this->add([
'name' => 'status',
'type' => \Laminas\Form\Element\Checkbox::class,
'attributes' => [
'id' => 'status',
],
'options' => [
'use_hidden_element' => false,
'unchecked_value' => \LeadersLinked\Model\PlanningTask::STATUS_INACTIVE,
'checked_value'=> \LeadersLinked\Model\PlanningTask::STATUS_ACTIVE,
]
]);
}
private function getSelectOptions($adapter,$company_id)
{
$companyUserMapper = CompanyUserMapper::getInstance($adapter);
$userMapper = UserMapper::getInstance($adapter);
$datosCompanyUser = $companyUserMapper->fetchAllByCompanyId($company_id);
$users=[];
foreach($datosCompanyUser as $record){
$datosUser = $userMapper->fetchOne($record->user_id);
$users[$datosUser->uuid] = $datosUser->uuid;
}
return $users;
}
}