Proyectos de Subversion LeadersLinked - Services

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

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