Completed
Push — develop ( d2080b...f8d06d )
by
unknown
23:14 queued 10:41
created

UserInfoFieldset::getDefaultEmptySummaryNotice()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
/**
24
 *
25
 *
26
 * @author Mathias Gelhausen <[email protected]>
27
 * @todo   write test
28
 */
29
class UserInfoFieldset extends Fieldset implements
30
    ViewPartialProviderInterface,
31
    EmptySummaryAwareInterface,
32
    InputFilterProviderInterface
33
{
34
35
    use EmptySummaryAwareTrait;
36
37
    private $defaultEmptySummaryNotice = /*@translate*/ 'Click here to enter contact informations.';
0 ignored issues
show
Unused Code introduced by
The property $defaultEmptySummaryNotice is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
38
    
39
    /**
40
     * View script for rendering
41
     *
42
     * @var string
43
     */
44
    protected $viewPartial = 'form/auth/contact';
45
46
    /**
47
     * @param String $partial
48
     *
49
     * @return $this
50
     */
51
    public function setViewPartial($partial)
52
    {
53
        $this->viewPartial = $partial;
54
55
        return $this;
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getViewPartial()
62
    {
63
        return $this->viewPartial;
64
    }
65
66
    /**
67
     * @return \Zend\Hydrator\HydratorInterface
68
     */
69
    public function getHydrator()
70
    {
71
        if (!$this->hydrator) {
72
            $hydrator = new EntityHydrator();
73
            $this->setHydrator($hydrator);
74
        }
75
76
        return $this->hydrator;
77
    }
78
79
    public function init()
80
    {
81
        $this->setName('info');
82
83
        $this->add(
84
            [
85
                'name'    => 'email',
86
                'options' => [
87
                    'label' => /* @translate */ 'Email'
88
                ],
89
                'attributes' => [
90
                    'required' => true, // marks the label as required.
91
                ]
92
            ]
93
        );
94
95
        $this->add(
96
            [
97
                'name'      => 'phone',
98
                'type'      => '\Core\Form\Element\Phone',
99
                'options'   => [
100
                    'label' => /* @translate */ 'Phone',
101
                ],
102
                'maxlength' => 20,
103
                'attributes' => [
104
                    'required' => true,
105
                ]
106
            ]
107
        );
108
109
        $this->add(
110
            [
111
                'name'    => 'postalCode',
112
                'options' => array(
113
                    'label' => /* @translate */ 'Postalcode'
114
                )
115
            ]
116
        );
117
118
        $this->add(
119
            [
120
                'name'    => 'city',
121
                'options' => [
122
                    'label' => /* @translate */ 'City'
123
                ]
124
            ]
125
        );
126
127
        $this->add(
128
            array(
129
                'name'       => 'gender',
130
                'type'       => 'Zend\Form\Element\Select',
131
                'options'    => [
132
                    'label'         => /*@translate */ 'Salutation',
133
                    'value_options' => [
134
                        ''       => '',
135
                        'male'   => /*@translate */ 'Mr.',
136
                        'female' => /*@translate */ 'Mrs.',
137
                    ]
138
                ],
139
                'attributes' => [
140
                    'data-placeholder' => /*@translate*/ 'please select',
141
                    'data-allowclear' => 'false',
142
                    'data-searchbox' => -1,  // hide the search box
143
                    'required' => true, // mark label as required
144
                ],
145
            )
146
        );
147
148
        $this->add(
149
            array(
150
                'name'       => 'firstName',
151
                'required'   => true,
152
                'options'    => [
153
                    'label'     => /*@translate*/ 'First name',
154
                    'maxlength' => 50,
155
                ],
156
                'attributes' => [
157
                    'required' => true,
158
                ]
159
            )
160
        );
161
162
        $this->add(
163
            array(
164
                'name'     => 'lastName',
165
                'options'  => array(
166
                    'label'     => /*@translate*/ 'Last name',
167
                    'maxlength' => 50,
168
                ),
169
                'attributes' => [
170
                    'required' => true,
171
                ]
172
            )
173
        );
174
175
        $this->add(
176
            [
177
                'name'    => 'street',
178
                'options' => [
179
                    'label' => /*@translate*/ 'street'
180
                ]
181
            ]
182
        );
183
184
        $this->add(
185
            [
186
                'name'    => 'houseNumber',
187
                'options' => [
188
                    'label' => /*@translate*/ 'house number'
189
                ]
190
            ]
191
        );
192
    }
193
194
    /**
195
     * (non-PHPdoc)
196
     *
197
     * @see \Zend\InputFilter\InputFilterProviderInterface::getInputFilterSpecification()
198
     */
199
    public function getInputFilterSpecification()
200
    {
201
        return array(
202
            'firstName' => array(
203
                'required'   => true,
204
                'filters'    => array(
205
                    array('name' => '\Zend\Filter\StringTrim'),
206
                ),
207
                'validators' => array(
208
                    new NotEmpty(),
209
                    new StringLength(array('max' => 50))
210
                ),
211
            ),
212
            'lastName'  => array(
213
                'required'   => true,
214
                'filters'    => array(
215
                    array('name' => 'Zend\Filter\StringTrim'),
216
                ),
217
                'validators' => array(
218
                    new NotEmpty(),
219
                    new StringLength(array('max' => 50))
220
                ),
221
            ),
222
            'email'     => array(
223
                'required'   => true,
224
                'filters'    => array(
225
                    array('name' => 'Zend\Filter\StringTrim'),
226
                ),
227
                'validators' => array(
228
                    new NotEmpty(),
229
                    new StringLength(array('max' => 100)),
230
                    new EmailAddress()
231
                )
232
            ),
233
            'image'     => array(
234
                'required'   => false,
235
                'filters'    => array(),
236
                'validators' => array(
237
                    new File\Exists(),
238
                    new File\Extension(array('extension' => array('jpg', 'png', 'jpeg', 'gif'))),
239
                ),
240
            ),
241
        );
242
    }
243
}
244