Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
15341 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Form;
6
 
7
use Laminas\Form\Form;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use Laminas\Log\LoggerInterface;
10
use LeadersLinked\Mapper\CompanySizeMapper;
11
use LeadersLinked\Mapper\IndustryMapper;
15441 efrain 12
use LeadersLinked\Mapper\ThemeMapper;
15341 efrain 13
 
14
class NetworkCreateForm extends Form
15
{
16
    /**
17
     *
18
     * @param AdapterInterface $adapter
19
     */
20
    public function __construct($adapter)
21
    {
22
 
23
        parent::__construct();
24
        $this->setInputFilter(new NetworkCreateFilter($adapter));
25
 
26
        $this->add([
27
            'name' => 'first_name',
28
            'type' => \Laminas\Form\Element\Text::class,
29
            'attributes' => [
30
                'maxlength' 	=> 64,
31
                'id' 			=> 'first_name',
32
            ]
33
        ]);
34
        $this->add([
35
            'name' => 'last_name',
36
            'type' => \Laminas\Form\Element\Text::class,
37
            'attributes' => [
38
                'maxlength' 	=> 64,
39
                'id' 			=> 'last_name',
40
            ]
41
        ]);
42
        $this->add([
43
            'name' => 'email',
44
            'type' => \Laminas\Form\Element\Text::class,
45
            'attributes' => [
46
                'maxlength' 	=> 64,
47
                'id' 			=> 'email',
48
            ]
49
        ]);
50
        $this->add([
51
            'name' => 'password',
52
            'type' => \Laminas\Form\Element\Text::class,
53
            'attributes' => [
54
                'maxlength' 	=> 16,
55
                'id' 			=> 'password',
56
            ]
57
        ]);
58
        $this->add([
59
            'name' => 'confirmation',
60
            'type' => \Laminas\Form\Element\Text::class,
61
            'attributes' => [
62
                'maxlength' 	=> 16,
63
                'id' 			=> 'confirmation',
64
            ]
65
        ]);
66
 
67
        $this->add([
68
            'name' => 'company',
69
            'type' => \Laminas\Form\Element\Text::class,
70
             'attributes' => [
71
                'maxlength' 	=> 128,
72
                'id' 			=> 'company',
73
            ]
74
         ]);
75
        $this->add([
76
             'name' => 'industry_id',
77
             'type' => \Laminas\Form\Element\Select::class,
78
             'options' => [
79
                 'value_options' => $this->optionsIndustry($adapter),
80
             ],
81
             'attributes' => [
82
                 'id' => 'industry_id',
83
             ]
84
         ]);
85
        $this->add([
86
            'name' => 'company_size_id',
87
            'type' => \Laminas\Form\Element\Select::class,
88
            'options' => [
89
                'value_options' => $this->optionsCompanySize($adapter),
90
            ],
91
            'attributes' => [
92
                'id' => 'company_size_id',
93
            ]
94
        ]);
95
        $this->add([
96
            'name' => 'main_hostname',
97
            'type' => \Laminas\Form\Element\Text::class,
98
            'attributes' => [
99
                'maxlength' 	=> 250,
100
                'id' 			=> 'admin_hostname',
101
            ]
102
        ]);
103
        $this->add([
104
            'name' => 'admin_hostname',
105
            'type' => \Laminas\Form\Element\Text::class,
106
            'attributes' => [
107
                'maxlength' 	=> 250,
108
                'id' 			=> 'admin_hostname',
109
            ]
110
        ]);
15441 efrain 111
 
112
        $this->add([
113
            'name' => 'theme_id',
114
            'type' => \Laminas\Form\Element\Select::class,
115
            'attributes' => [
116
                'id' => 'theme_id',
117
            ],
118
            'options' => [
119
                'disable_inarray_validator' => true,
120
                'value_options' => $this->optionsTheme($adapter)
121
            ]
122
        ]);
123
 
15341 efrain 124
    }
125
 
126
    /**
127
     *
128
     * @param AdapterInterface $adapter
129
     * @param LoggerInterface $logger
130
     * @return array
131
     */
132
    private function optionsCompanySize($adapter)
133
    {
134
        $companySizeMapper = CompanySizeMapper::getInstance($adapter);
135
        $companySizes = $companySizeMapper->fetchAllActive();
136
 
137
        $options = [];
138
        foreach($companySizes as $companySize)
139
        {
140
            $options[$companySize->uuid] = $companySize->name . ' ( ' . $companySize->minimum_no_of_employee . ' - ' . $companySize->maximum_no_of_employee . ' )';
141
        }
142
 
143
        return $options;
144
    }
145
 
146
    /**
147
     *
148
     * @param AdapterInterface $adapter
149
     * @return array
150
     */
151
    private function optionsIndustry($adapter)
152
    {
153
        $industryMapper = IndustryMapper::getInstance($adapter);
154
        $industries  = $industryMapper->fetchAllActive();
155
 
156
        $options = [];
157
        foreach($industries as $industry)
158
        {
159
            $options[$industry->uuid] = $industry->name;
160
        }
161
 
162
        return $options;
163
    }
15441 efrain 164
 
165
    /**
166
     *
167
     * @param AdapterInterface $adapter
168
     */
169
    private function optionsTheme($adapter)
170
    {
171
        $options = [];
172
 
173
        $mapper = ThemeMapper::getInstance($adapter);
174
        $records = $mapper->fetchAll();
175
 
176
        foreach($records as $record)
177
        {
178
            $options[$record->uuid] = $record->name;
179
        }
180
        return $options;
181
    }
15341 efrain 182
 
183
}