Rev 15086 | 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\SurveyMapper;
use LeadersLinked\Mapper\SurveyFormMapper;
use LeadersLinked\Model\Survey;
class SurveyForm extends Form
{
public function __construct($adapter, $company_id)
{
parent::__construct();
$this->setInputFilter(new SurveyFilter($adapter, $company_id));
$this->add([
'name' => 'name',
'type' => \Laminas\Form\Element\Text::class,
'attributes' => [
'maxlength' => 128,
'id' => 'name',
]
]);
/*
$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' => 'form_id',
'type' => \Laminas\Form\Element\Select::class,
'attributes' => [
'id' => 'form_id',
],
'options' => [
'value_options' => $this->getFormSelectOptions($adapter, $company_id)
]
]);
$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' => 'since_date',
'type' => \Laminas\Form\Element\Date::class,
'attributes' => [
'id' => 'since_date',
],
]);
$this->add([
'name' => 'last_date',
'type' => \Laminas\Form\Element\Date::class,
'attributes' => [
'id' => 'last_date',
],
]);
$this->add([
'name' => 'location_search',
'type' => \Laminas\Form\Element\Text::class,
'attributes' => [
'maxlength' => 250,
'id' => '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',
]
]);
$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)
]
]);
$this->add([
'name' => 'target',
'type' => \Laminas\Form\Element\Select::class,
'attributes' => [
'id' => 'target',
],'options' => [
'empty_option' => 'LABEL_SELECT',
'value_options' => [
Survey::TARGET_NON_REGISTERED => 'LABEL_SURVEY_TARGET_PUBLIC',
Survey::TARGET_REGISTER => 'LABEL_SURVEY_TARGET_USERS',
Survey::TARGET_SEGMENTED => 'LABEL_SURVEY_TARGET_USERS_SEGMENTED',
],
],
]);
$this->add([
'name' => 'status',
'type' => \Laminas\Form\Element\Select::class,
'attributes' => [
'id' => 'status',
],
'options' => [
'empty_option' => 'LABEL_SELECT',
'value_options' => [
Survey::STATUS_ACTIVE => 'LABEL_ACTIVE',
Survey::STATUS_INACTIVE => 'LABEL_INACTIVE',
],
],
]);
$this->add([
'name' => 'identity',
'type' => \Laminas\Form\Element\Select::class,
'attributes' => [
'id' => 'identity',
],
'options' => [
'empty_option' => 'LABEL_SELECT',
'value_options' => [
Survey::IDENTITY_YES => 'LABEL_YES',
Survey::IDENTITY_NO => 'LABEL_NO',
],
],
]);
}
/**
*
* @param AdapterInterface $adapter
*/
private function getFormSelectOptions($adapter, $company_id)
{
$options = [];
$mapper = SurveyFormMapper::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;
}
}