Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
16817 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Form\Survey;
6
 
7
use Laminas\Form\Form;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use LeadersLinked\Mapper\IndustryMapper;
10
use LeadersLinked\Mapper\JobDescriptionMapper;
11
use LeadersLinked\Mapper\SkillMapper;
12
use LeadersLinked\Mapper\LanguageMapper;
13
use LeadersLinked\Mapper\SurveyFormMapper;
14
use LeadersLinked\Model\SurveyCampaign;
15
use LeadersLinked\Model\SurveyForm;
16
 
17
 
18
class SurveyCampaignForm extends Form
19
{
20
 
21
    public function __construct($adapter, $company_id, $type)
22
    {
23
        parent::__construct();
24
        $this->setInputFilter(new SurveyCampaignFilter($adapter, $company_id, $type));
25
 
26
        $this->add([
27
            'name' => 'name',
28
            'type' => \Laminas\Form\Element\Text::class,
29
             'attributes' => [
30
                'maxlength' 	=> 128,
31
                'id' 			=> 'name',
32
            ]
33
        ]);
34
 
35
        $this->add([
36
            'name' => 'form_id',
37
            'type' => \Laminas\Form\Element\Select::class,
38
             'attributes' => [
39
                'id' 			=> 'form_id',
40
             ],
41
             'options' => [
42
                'value_options' => $this->getFormSelectOptions($adapter, $company_id, $type)
43
            ]
44
        ]);
45
 
46
        $this->add([
47
            'name' => 'start_date',
48
            'type' => \Laminas\Form\Element\Date::class,
49
            'attributes' => [
50
                'id' 			=> 'start_date',
51
            ],
52
            'options' => [
53
                'format' => 'Y-m-d',
54
            ]
55
        ]);
56
 
57
        $this->add([
58
            'name' => 'end_date',
59
            'type' => \Laminas\Form\Element\Date::class,
60
            'attributes' => [
61
                'id' 			=> 'end_date',
62
 
63
            ],
64
            'options' => [
65
                'format' => 'Y-m-d',
66
            ]
67
        ]);
68
 
69
 
70
        $this->add([
71
            'name' => 'status',
72
            'type' => \Laminas\Form\Element\Select::class,
73
            'attributes' => [
74
                'id' 			=> 'status',
75
            ],
76
            'options' => [
77
                'empty_option' => 'LABEL_SELECT',
78
                'value_options' => [
79
                    SurveyCampaign::STATUS_ACTIVE => 'LABEL_ACTIVE',
80
                    SurveyCampaign::STATUS_INACTIVE => 'LABEL_INACTIVE',
81
                ],
82
            ],
83
        ]);
84
 
85
        $this->add([
86
            'name' => 'identity',
87
            'type' => \Laminas\Form\Element\Select::class,
88
            'attributes' => [
89
                'id' 			=> 'identity',
90
            ],
91
            'options' => [
92
                'empty_option' => 'LABEL_SELECT',
93
                'value_options' => [
94
                    SurveyCampaign::IDENTITY_YES => 'LABEL_YES',
95
                    SurveyCampaign::IDENTITY_NO => 'LABEL_NO',
96
                ],
97
            ],
98
        ]);
99
 
100
 
101
        /*** FILTERS ***/
102
 
103
        if($type == SurveyCampaign::TYPE_ORGANIZATIONAL_CLIMATE) {
104
            $this->add([
105
                'name' => 'job_description_id',
106
                'type' => \Laminas\Form\Element\Select::class,
107
                 'attributes' => [
108
                    'id' 			=> 'job_description_id',
109
                    'multiple'      => 'yes',
110
                 ],
111
                 'options' => [
112
                    'disable_inarray_validator' => true,
113
                    'value_options' => $this->getDescriptionSelectOptions($adapter, $company_id)
114
                ]
115
            ]);
116
        }
117
 
118
        $this->add([
119
            'name' => 'skill_id',
120
            'type' => \Laminas\Form\Element\Select::class,
121
             'attributes' => [
122
                'id' 			=> 'skill_id',
123
                'multiple'      => 'yes',
124
             ],
125
             'options' => [
126
                'disable_inarray_validator' => true,
127
                'value_options' => $this->getSkillSelectOptions($adapter)
128
            ]
129
        ]);
130
 
131
        $this->add([
132
            'name' => 'language',
133
            'type' => \Laminas\Form\Element\Select::class,
134
             'attributes' => [
135
                'id' 			=> 'language',
136
                'multiple'      => 'yes',
137
             ],
138
             'options' => [
139
                'disable_inarray_validator' => true,
140
                'value_options' => $this->getLanguageSelectOptions($adapter)
141
            ]
142
        ]);
143
 
144
        $this->add([
145
            'name' => 'industry_id',
146
            'type' => \Laminas\Form\Element\Select::class,
147
            'attributes' => [
148
                'id' 			=> 'industry_id',
149
                'multiple'      => 'yes',
150
            ],
151
            'options' => [
152
                'disable_inarray_validator' => true,
153
                'value_options' => $this->getIndustrySelectOptions($adapter)
154
            ]
155
        ]);
156
 
157
        $this->add([
158
            'name' => 'location_search',
159
            'type' => \Laminas\Form\Element\Text::class,
160
            'attributes' => [
161
                'maxlength' 	=> 250,
162
                'id' 			=> 'location_search',
163
            ]
164
        ]);
165
 
166
        $this->add([
167
            'name' => 'formatted_address',
168
            'type' => \Laminas\Form\Element\Hidden::class,
169
            'attributes' => [
170
                'id'    => 'formatted_address',
171
            ]
172
        ]);
173
 
174
        $this->add([
175
            'name' => 'address1',
176
            'type' => \Laminas\Form\Element\Hidden::class,
177
            'attributes' => [
178
                'id'    => 'address1',
179
            ]
180
        ]);
181
 
182
        $this->add([
183
            'name' => 'address2',
184
            'type' => \Laminas\Form\Element\Hidden::class,
185
            'attributes' => [
186
                'id'    => 'address2',
187
            ]
188
        ]);
189
 
190
        $this->add([
191
            'name' => 'country',
192
            'type' => \Laminas\Form\Element\Hidden::class,
193
            'attributes' => [
194
                'id'    => 'country',
195
            ]
196
        ]);
197
 
198
        $this->add([
199
            'name' => 'state',
200
            'type' => \Laminas\Form\Element\Hidden::class,
201
            'attributes' => [
202
                'id'    => 'state',
203
            ]
204
        ]);
205
 
206
        $this->add([
207
            'name' => 'city1',
208
            'type' => \Laminas\Form\Element\Hidden::class,
209
            'attributes' => [
210
                'id'    => 'city1',
211
            ]
212
        ]);
213
 
214
        $this->add([
215
            'name' => 'city2',
216
            'type' => \Laminas\Form\Element\Hidden::class,
217
            'attributes' => [
218
                'id'    => 'city2',
219
            ]
220
        ]);
221
 
222
        $this->add([
223
            'name' => 'postal_code',
224
            'type' => \Laminas\Form\Element\Hidden::class,
225
            'attributes' => [
226
                'id'    => 'postal_code',
227
            ]
228
        ]);
229
 
230
        $this->add([
231
            'name' => 'latitude',
232
            'type' => \Laminas\Form\Element\Hidden::class,
233
            'attributes' => [
234
                'id'    => 'latitude',
235
            ]
236
        ]);
237
 
238
        $this->add([
239
            'name' => 'longitude',
240
            'type' => \Laminas\Form\Element\Hidden::class,
241
            'attributes' => [
242
                'id'    => 'longitude',
243
            ]
244
        ]);
245
 
246
    }
247
 
248
    /**
249
     *
250
     * @param AdapterInterface $adapter
251
     */
252
    private function getFormSelectOptions($adapter, $company_id, $type)
253
    {
254
        $options = [];
255
 
256
        $mapper = SurveyFormMapper::getInstance($adapter);
257
 
258
        if($type == SurveyForm::TYPE_ORGANIZATIONAL_CLIMATE) {
259
            $records = $mapper->fetchAllActiveOrganizationalClimateByCompanyId($company_id);
260
        } else {
261
            $records = $mapper->fetchAllActiveNormalByCompanyId($company_id);
262
        }
263
 
264
        foreach($records as $record)
265
        {
266
            $options[$record->uuid] = $record->name;
267
        }
268
        return $options;
269
    }
270
 
271
    private function getDescriptionSelectOptions($adapter, $company_id)
272
    {
273
        $options = [];
274
 
275
        $mapper = JobDescriptionMapper::getInstance($adapter);
276
        $records = $mapper->fetchAllActiveByCompanyId($company_id);
277
 
278
 
279
 
280
        foreach($records as $record)
281
        {
282
            $options[$record->uuid] = $record->name;
283
        }
284
 
285
 
286
        return $options;
287
    }
288
 
289
    function getSkillSelectOptions($adapter)
290
    {
291
        $options = [];
292
 
293
        $mapper = SkillMapper::getInstance($adapter);
294
        $records = $mapper->fetchAllActive();
295
 
296
        foreach($records as $record)
297
        {
298
            $options[$record->uuid] = $record->name;
299
        }
300
        return $options;
301
    }
302
 
303
    function getIndustrySelectOptions($adapter)
304
    {
305
        $options = [];
306
 
307
        $mapper = IndustryMapper::getInstance($adapter);
308
        $records = $mapper->fetchAllActive();
309
 
310
        foreach($records as $record)
311
        {
312
            $options[$record->uuid] = $record->name;
313
        }
314
        return $options;
315
    }
316
 
317
    function getLanguageSelectOptions($adapter)
318
    {
319
        $options = [];
320
 
321
        $mapper = LanguageMapper::getInstance($adapter);
322
        $records = $mapper->fetchAll();
323
 
324
        foreach($records as $record)
325
        {
326
            $options[$record->id] = $record->name;
327
        }
328
        return $options;
329
    }
330
 
331
}