Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Form\UserProfile;
6
 
7
use Laminas\Form\Form;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use LeadersLinked\Mapper\DegreeMapper;
10
 
11
class EducationForm extends Form
12
{
13
    /**
14
     *
15
     * @param AdapterInterface $adapter
16
     */
17
    public function __construct($adapter)
18
    {
19
        parent::__construct();
20
 
21
        $this->setInputFilter(new EducationFilter($adapter));
22
 
23
        $this->add([
24
            'name' => 'degree_id',
25
            'type' => \Laminas\Form\Element\Select::class,
26
            'options' => [
27
                'value_options' => $this->optionsDegree($adapter)
28
            ],
29
            'attributes' => [
30
                'id' => 'degree_id',
31
            ]
32
        ]);
33
 
34
        $this->add([
35
            'name' => 'university',
36
            'type' => \Laminas\Form\Element\Text::class,
37
            'attributes' => [
38
                'maxlength' 	=> 128,
39
                'id' 			=> 'university',
40
            ]
41
        ]);
42
 
43
        $this->add([
44
            'name' => 'field_of_study',
45
            'type' => \Laminas\Form\Element\Text::class,
46
            'attributes' => [
47
                'maxlength' 	=> 128,
48
                'id' 			=> 'field_of_study',
49
            ]
50
        ]);
51
 
52
        $this->add([
53
            'name' => 'from_year',
54
            'type' => \Laminas\Form\Element\Select::class,
55
            'attributes' => [
56
                'id'=> 'from_year',
57
            ],
58
            'options' => [
59
                'value_options' => $this->optionsYears()
60
            ],
61
        ]);
62
 
63
        $this->add([
64
            'name' => 'to_year',
65
            'type' => \Laminas\Form\Element\Select::class,
66
            'attributes' => [
67
                'id' => 'to_year',
68
            ],
69
            'options' => [
70
                'value_options' => $this->optionsYears()
71
            ],
72
        ]);
73
 
74
        $this->add([
75
            'name' => 'grade_or_percentage',
76
            'type' => \Laminas\Form\Element\Text::class,
77
            'attributes' => [
78
                'maxlength' 	=> 3,
79
                'id' 			=> 'grade_or_percentage',
80
            ]
81
        ]);
82
 
83
        $this->add([
84
            'name' => 'description',
85
            'type' => \Laminas\Form\Element\Textarea::class,
86
            'attributes' => [
87
                'id' 			=> 'description',
88
            ]
89
        ]);
90
 
91
 
92
        $this->add([
93
            'name' => 'education_location_search',
94
            'type' => \Laminas\Form\Element\Text::class,
95
            'attributes' => [
96
                'maxlength' 	=> 250,
97
                'id' 			=> 'education_location_search',
98
            ]
99
        ]);
100
 
101
 
102
        $this->add([
103
            'name' => 'formatted_address',
104
            'type' => \Laminas\Form\Element\Hidden::class,
105
            'attributes' => [
106
                'id'    => 'formatted_address',
107
            ]
108
        ]);
109
 
110
        $this->add([
111
            'name' => 'address1',
112
            'type' => \Laminas\Form\Element\Hidden::class,
113
            'attributes' => [
114
                'id'    => 'address1',
115
            ]
116
        ]);
117
 
118
        $this->add([
119
            'name' => 'address2',
120
            'type' => \Laminas\Form\Element\Hidden::class,
121
            'attributes' => [
122
                'id'    => 'address2',
123
            ]
124
        ]);
125
 
126
        $this->add([
127
            'name' => 'country',
128
            'type' => \Laminas\Form\Element\Hidden::class,
129
            'attributes' => [
130
                'id'    => 'country',
131
            ]
132
        ]);
133
 
134
        $this->add([
135
            'name' => 'state',
136
            'type' => \Laminas\Form\Element\Hidden::class,
137
            'attributes' => [
138
                'id'    => 'state',
139
            ]
140
        ]);
141
 
142
        $this->add([
143
            'name' => 'city1',
144
            'type' => \Laminas\Form\Element\Hidden::class,
145
            'attributes' => [
146
                'id'    => 'city1',
147
            ]
148
        ]);
149
 
150
        $this->add([
151
            'name' => 'city2',
152
            'type' => \Laminas\Form\Element\Hidden::class,
153
            'attributes' => [
154
                'id'    => 'city2',
155
            ]
156
        ]);
157
 
158
        $this->add([
159
            'name' => 'postal_code',
160
            'type' => \Laminas\Form\Element\Hidden::class,
161
            'attributes' => [
162
                'id'    => 'postal_code',
163
            ]
164
        ]);
165
 
166
        $this->add([
167
            'name' => 'latitude',
168
            'type' => \Laminas\Form\Element\Hidden::class,
169
            'attributes' => [
170
                'id'    => 'latitude',
171
            ]
172
        ]);
173
 
174
        $this->add([
175
            'name' => 'longitude',
176
            'type' => \Laminas\Form\Element\Hidden::class,
177
            'attributes' => [
178
                'id'    => 'longitude',
179
            ]
180
        ]);
181
 
182
 
183
 
184
 
185
 
186
    }
187
 
188
    /**
189
     *
190
     * @param AdapterInterface $adapter
191
     * @return array
192
     */
193
    private function optionsDegree($adapter)
194
    {
195
        $mapper = DegreeMapper::getInstance($adapter);
196
        $records = $mapper->fetchAllActives();
197
 
198
        $items = [];
199
        foreach($records as $record)
200
        {
201
            $items[$record->uuid] = $record->name;
202
        }
203
 
204
        return $items;
205
    }
206
 
207
    /**
208
     *
209
     * @return array
210
     */
211
    private function optionsYears()
212
    {
213
        $y = date('Y');
214
        $options = [];
215
        for($i = 0 ; $i < 100; $i++)
216
        {
217
            $options[$y - $i] = $y - $i;
218
        }
219
 
220
        return $options;
221
    }
222
 
223
}