Rev 16948 | 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\Network;
use Laminas\Form\Form;
use Laminas\Db\Adapter\AdapterInterface;
use Laminas\Log\LoggerInterface;
use LeadersLinked\Mapper\CompanySizeMapper;
use LeadersLinked\Mapper\IndustryMapper;
use LeadersLinked\Mapper\ThemeMapper;
use LeadersLinked\Model\Network;
class NetworkCreateForm extends Form
{
/**
*
* @param AdapterInterface $adapter
*/
public function __construct($adapter)
{
parent::__construct();
$this->setInputFilter(new NetworkCreateFilter($adapter));
$this->add([
'name' => 'first_name',
'type' => \Laminas\Form\Element\Text::class,
'attributes' => [
'maxlength' => 64,
'id' => 'first_name',
]
]);
$this->add([
'name' => 'last_name',
'type' => \Laminas\Form\Element\Text::class,
'attributes' => [
'maxlength' => 64,
'id' => 'last_name',
]
]);
$this->add([
'name' => 'email',
'type' => \Laminas\Form\Element\Text::class,
'attributes' => [
'maxlength' => 64,
'id' => 'email',
]
]);
$this->add([
'name' => 'password',
'type' => \Laminas\Form\Element\Text::class,
'attributes' => [
'maxlength' => 16,
'id' => 'password',
]
]);
$this->add([
'name' => 'confirmation',
'type' => \Laminas\Form\Element\Text::class,
'attributes' => [
'maxlength' => 16,
'id' => 'confirmation',
]
]);
$this->add([
'name' => 'company',
'type' => \Laminas\Form\Element\Text::class,
'attributes' => [
'maxlength' => 128,
'id' => 'company',
]
]);
$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',
]
]);
$this->add([
'name' => 'main_hostname',
'type' => \Laminas\Form\Element\Text::class,
'attributes' => [
'maxlength' => 250,
'id' => 'admin_hostname',
]
]);
$this->add([
'name' => 'alternative_hostname',
'type' => \Laminas\Form\Element\Text::class,
'attributes' => [
'maxlength' => 250,
'id' => 'alternative_hostname',
]
]);
$this->add([
'name' => 'admin_hostname',
'type' => \Laminas\Form\Element\Text::class,
'attributes' => [
'maxlength' => 250,
'id' => 'admin_hostname',
]
]);
$this->add([
'name' => 'theme_id',
'type' => \Laminas\Form\Element\Select::class,
'attributes' => [
'id' => 'theme_id',
],
'options' => [
'value_options' => $this->optionsTheme($adapter)
]
]);
$this->add([
'name' => 'moodle_url',
'type' => \Laminas\Form\Element\Text::class,
'attributes' => [
'maxlength' => 250,
'id' => 'moodle_url',
]
]);
$this->add([
'name' => 'relationship_user_mode',
'type' => \Laminas\Form\Element\Select::class,
'attributes' => [
'id' => 'relationship_user_mode',
],
'options' => [
'value_options' => [
Network::RELATIONSHIP_USER_MODE_USER_2_USER => 'LABEL_RELATIONSHIP_USER_MODE_USER_2_USER',
Network::RELATIONSHIP_USER_MODE_ALL_2_ALL => 'LABEL_RELATIONSHIP_USER_MODE_ALL_2_ALL',
]
]
]);
}
/**
*
* @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;
}
/**
*
* @param AdapterInterface $adapter
*/
private function optionsTheme($adapter)
{
$options = [];
$mapper = ThemeMapper::getInstance($adapter);
$records = $mapper->fetchAll();
foreach($records as $record)
{
$options[$record->uuid] = $record->name;
}
return $options;
}
}