Completed
Push — develop ( bfc0af...88d3fd )
by
unknown
08:28
created

UserInfoFieldset::setViewPartial()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
7
 * @license       MIT
8
 */
9
10
namespace Auth\Form;
11
12
use Core\Entity\Hydrator\EntityHydrator;
13
use Core\Form\EmptySummaryAwareInterface;
14
use Core\Form\EmptySummaryAwareTrait;
15
use Zend\Form\Fieldset;
16
use Core\Form\ViewPartialProviderInterface;
17
use Zend\InputFilter\InputFilterProviderInterface;
18
use Zend\Validator\StringLength;
19
use Zend\Validator\NotEmpty;
20
use Zend\Validator\EmailAddress;
21
use Zend\Validator\File;
22
23
class UserInfoFieldset extends Fieldset implements
24
    ViewPartialProviderInterface,
25
    EmptySummaryAwareInterface,
26
    InputFilterProviderInterface
27
{
28
29
    use EmptySummaryAwareTrait;
30
    
31
    /**
32
     * View script for rendering
33
     *
34
     * @var string
35
     */
36
    protected $viewPartial = 'form/auth/contact';
37
38
    /**
39
     * @param String $partial
40
     *
41
     * @return $this
42
     */
43
    public function setViewPartial($partial)
44
    {
45
        $this->viewPartial = $partial;
46
47
        return $this;
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getViewPartial()
54
    {
55
        return $this->viewPartial;
56
    }
57
58
    /**
59
     * @return \Zend\Hydrator\HydratorInterface
60
     */
61
    public function getHydrator()
62
    {
63
        if (!$this->hydrator) {
64
            $hydrator = new EntityHydrator();
65
            $this->setHydrator($hydrator);
66
        }
67
68
        return $this->hydrator;
69
    }
70
71
    public function init()
72
    {
73
        $this->setName('info');
74
75
        $this->add(
76
            [
77
                'name'    => 'email',
78
                'options' => [
79
                    'label' => /* @translate */ 'Email'
80
                ],
81
                'attributes' => [
82
                    'required' => true, // marks the label as required.
83
                ]
84
            ]
85
        );
86
87
        $this->add(
88
            [
89
                'name'      => 'phone',
90
                'type'      => '\Core\Form\Element\Phone',
91
                'options'   => [
92
                    'label' => /* @translate */ 'Phone',
93
                ],
94
                'maxlength' => 20,
95
                'attributes' => [
96
                    'required' => true,
97
                ]
98
            ]
99
        );
100
101
        $this->add(
102
            [
103
                'name'    => 'postalCode',
104
                'options' => array(
105
                    'label' => /* @translate */ 'Postalcode'
106
                )
107
            ]
108
        );
109
110
        $this->add(
111
            [
112
                'name'    => 'city',
113
                'options' => [
114
                    'label' => /* @translate */ 'City'
115
                ]
116
            ]
117
        );
118
119
        $this->add(
120
            array(
121
                'name'       => 'gender',
122
                'type'       => 'Zend\Form\Element\Select',
123
                'options'    => [
124
                    'label'         => /*@translate */ 'Salutation',
125
                    'value_options' => [
126
                        ''       => '',
127
                        'male'   => /*@translate */ 'Mr.',
128
                        'female' => /*@translate */ 'Mrs.',
129
                    ]
130
                ],
131
                'attributes' => [
132
                    'data-placeholder' => /*@translate*/ 'please select',
133
                    'data-allowclear' => 'false',
134
                    'data-searchbox' => -1,  // hide the search box
135
                    'required' => true, // mark label as required
136
                ],
137
            )
138
        );
139
140
        $this->add(
141
            array(
142
                'name'       => 'firstName',
143
                'required'   => true,
144
                'options'    => [
145
                    'label'     => /*@translate*/ 'First name',
146
                    'maxlength' => 50,
147
                ],
148
                'attributes' => [
149
                    'required' => true,
150
                ]
151
            )
152
        );
153
154
        $this->add(
155
            array(
156
                'name'     => 'lastName',
157
                'options'  => array(
158
                    'label'     => /*@translate*/ 'Last name',
159
                    'maxlength' => 50,
160
                ),
161
                'attributes' => [
162
                    'required' => true,
163
                ]
164
            )
165
        );
166
167
        $this->add(
168
            [
169
                'name'    => 'street',
170
                'options' => [
171
                    'label' => /*@translate*/ 'street'
172
                ]
173
            ]
174
        );
175
176
        $this->add(
177
            [
178
                'name'    => 'houseNumber',
179
                'options' => [
180
                    'label' => /*@translate*/ 'house number'
181
                ]
182
            ]
183
        );
184
    }
185
186
    /**
187
     * (non-PHPdoc)
188
     *
189
     * @see \Zend\InputFilter\InputFilterProviderInterface::getInputFilterSpecification()
190
     */
191
    public function getInputFilterSpecification()
192
    {
193
        return array(
194
            'firstName' => array(
195
                'required'   => true,
196
                'filters'    => array(
197
                    array('name' => '\Zend\Filter\StringTrim'),
198
                ),
199
                'validators' => array(
200
                    new NotEmpty(),
201
                    new StringLength(array('max' => 50))
202
                ),
203
            ),
204
            'lastName'  => array(
205
                'required'   => true,
206
                'filters'    => array(
207
                    array('name' => 'Zend\Filter\StringTrim'),
208
                ),
209
                'validators' => array(
210
                    new NotEmpty(),
211
                    new StringLength(array('max' => 50))
212
                ),
213
            ),
214
            'email'     => array(
215
                'required'   => true,
216
                'filters'    => array(
217
                    array('name' => 'Zend\Filter\StringTrim'),
218
                ),
219
                'validators' => array(
220
                    new NotEmpty(),
221
                    new StringLength(array('max' => 100)),
222
                    new EmailAddress()
223
                )
224
            ),
225
            'image'     => array(
226
                'required'   => false,
227
                'filters'    => array(),
228
                'validators' => array(
229
                    new File\Exists(),
230
                    new File\Extension(array('extension' => array('jpg', 'png', 'jpeg', 'gif'))),
231
                ),
232
            ),
233
        );
234
    }
235
236
    /**
237
     * @return string
238
     */
239
    protected function getDefaultEmptySummaryNotice()
240
    {
241
        return /*@translate*/ 'Click here to enter contact informations.';
242
    }
243
}
244