Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 15831 | Ir a la última revisión | | Ultima modificación | Ver Log |

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