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([
15452 efrain 104
            'name' => 'alternative_hostname',
105
            'type' => \Laminas\Form\Element\Text::class,
106
            'attributes' => [
107
                'maxlength' 	=> 250,
108
                'id' 			=> 'alternative_hostname',
109
            ]
110
        ]);
111
        $this->add([
15341 efrain 112
            'name' => 'admin_hostname',
113
            'type' => \Laminas\Form\Element\Text::class,
114
            'attributes' => [
115
                'maxlength' 	=> 250,
116
                'id' 			=> 'admin_hostname',
117
            ]
118
        ]);
15441 efrain 119
 
120
        $this->add([
121
            'name' => 'theme_id',
122
            'type' => \Laminas\Form\Element\Select::class,
123
            'attributes' => [
124
                'id' => 'theme_id',
125
            ],
126
            'options' => [
127
                'disable_inarray_validator' => true,
128
                'value_options' => $this->optionsTheme($adapter)
129
            ]
130
        ]);
131
 
15341 efrain 132
    }
133
 
134
    /**
135
     *
136
     * @param AdapterInterface $adapter
137
     * @param LoggerInterface $logger
138
     * @return array
139
     */
140
    private function optionsCompanySize($adapter)
141
    {
142
        $companySizeMapper = CompanySizeMapper::getInstance($adapter);
143
        $companySizes = $companySizeMapper->fetchAllActive();
144
 
145
        $options = [];
146
        foreach($companySizes as $companySize)
147
        {
148
            $options[$companySize->uuid] = $companySize->name . ' ( ' . $companySize->minimum_no_of_employee . ' - ' . $companySize->maximum_no_of_employee . ' )';
149
        }
150
 
151
        return $options;
152
    }
153
 
154
    /**
155
     *
156
     * @param AdapterInterface $adapter
157
     * @return array
158
     */
159
    private function optionsIndustry($adapter)
160
    {
161
        $industryMapper = IndustryMapper::getInstance($adapter);
162
        $industries  = $industryMapper->fetchAllActive();
163
 
164
        $options = [];
165
        foreach($industries as $industry)
166
        {
167
            $options[$industry->uuid] = $industry->name;
168
        }
169
 
170
        return $options;
171
    }
15441 efrain 172
 
173
    /**
174
     *
175
     * @param AdapterInterface $adapter
176
     */
177
    private function optionsTheme($adapter)
178
    {
179
        $options = [];
180
 
181
        $mapper = ThemeMapper::getInstance($adapter);
182
        $records = $mapper->fetchAll();
183
 
184
        foreach($records as $record)
185
        {
186
            $options[$record->uuid] = $record->name;
187
        }
188
        return $options;
189
    }
15341 efrain 190
 
191
}