|
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 Jobs\Form; |
|
11
|
|
|
|
|
12
|
|
|
use Jobs\Entity\Salary as SalaryEntity; |
|
13
|
|
|
use Core\Form\ViewPartialProviderInterface; |
|
14
|
|
|
use Core\Entity\Hydrator\EntityHydrator; |
|
15
|
|
|
use Zend\Form\Fieldset; |
|
16
|
|
|
use Zend\InputFilter\InputFilterProviderInterface; |
|
17
|
|
|
use Zend\Validator\InArray as InArrayValidator; |
|
18
|
|
|
use Zend\Validator\GreaterThan as GreaterThan; |
|
19
|
|
|
use Zend\Validator\Regex as RegexValidator; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Defines the formular fields used in the formular for entering the job salary information |
|
23
|
|
|
* |
|
24
|
|
|
* @package Jobs\Form |
|
25
|
|
|
*/ |
|
26
|
|
|
class SalaryFieldset extends Fieldset implements ViewPartialProviderInterface, InputFilterProviderInterface |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* View partial name |
|
30
|
|
|
* |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $partial = 'jobs/form/salary-fieldset'; |
|
34
|
|
|
|
|
35
|
|
|
public function setViewPartial($partial) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->partial = $partial; |
|
38
|
|
|
|
|
39
|
|
|
return $this; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function getViewPartial() |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->partial; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function getHydrator() |
|
48
|
|
|
{ |
|
49
|
|
|
if (!$this->hydrator) { |
|
50
|
|
|
$hydrator = new EntityHydrator(); |
|
51
|
|
|
$this->setHydrator($hydrator); |
|
52
|
|
|
} |
|
53
|
|
|
return $this->hydrator; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function allowObjectBinding($object) |
|
57
|
|
|
{ |
|
58
|
|
|
return $object instanceof SalaryEntity || parent::allowObjectBinding($object); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function init() |
|
62
|
|
|
{ |
|
63
|
|
|
$this->setAttribute('id', 'jobsalary-fieldset'); |
|
64
|
|
|
$this->setName('salary'); |
|
65
|
|
|
|
|
66
|
|
|
$this->add( |
|
67
|
|
|
array( |
|
68
|
|
|
'type' => 'Text', |
|
69
|
|
|
'name' => 'value', |
|
70
|
|
|
'options' => array( |
|
71
|
|
|
'label' => /*@translate*/ 'Salary', |
|
72
|
|
|
'description' => /*@translate*/ 'Please enter the job salary amount', |
|
73
|
|
|
), |
|
74
|
|
|
) |
|
75
|
|
|
); |
|
76
|
|
|
|
|
77
|
|
|
$this->add( |
|
78
|
|
|
array( |
|
79
|
|
|
'type' => 'Select', |
|
80
|
|
|
'name' => 'currency', |
|
81
|
|
|
'options' => array( |
|
82
|
|
|
'label' => /*@translate*/ 'Currency', |
|
83
|
|
|
'description' => /*@translate*/ 'Please enter the job salary currency', |
|
84
|
|
|
'value_options' => array_map(function($val) { |
|
85
|
|
|
return $val['code']; |
|
86
|
|
|
}, SalaryEntity::getValidCurrencies()), |
|
87
|
|
|
) |
|
88
|
|
|
) |
|
89
|
|
|
); |
|
90
|
|
|
|
|
91
|
|
|
$this->add( |
|
92
|
|
|
array( |
|
93
|
|
|
'type' => 'Select', |
|
94
|
|
|
'name' => 'unit', |
|
95
|
|
|
'options' => array( |
|
96
|
|
|
'label' => /*@translate*/ 'Time interval unit', |
|
97
|
|
|
'description' => /*@translate*/ 'Please enter the job time interval unit', |
|
98
|
|
|
'value_options' => array( |
|
99
|
|
|
SalaryEntity::UNIT_HOUR => /*@translate*/ 'Hour', |
|
100
|
|
|
SalaryEntity::UNIT_DAY => /*@translate*/ 'Day', |
|
101
|
|
|
SalaryEntity::UNIT_WEEK => /*@translate*/ 'Week', |
|
102
|
|
|
SalaryEntity::UNIT_MONTH => /*@translate*/ 'Month', |
|
103
|
|
|
SalaryEntity::UNIT_YEAR => /*@translate*/ 'Year', |
|
104
|
|
|
|
|
105
|
|
|
), |
|
106
|
|
|
'attributes' => array( |
|
107
|
|
|
'value' => SalaryEntity::UNIT_MONTH, |
|
108
|
|
|
), |
|
109
|
|
|
), |
|
110
|
|
|
) |
|
111
|
|
|
); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function getInputFilterSpecification() |
|
115
|
|
|
{ |
|
116
|
|
|
return array( |
|
117
|
|
|
'value' => array( |
|
118
|
|
|
'required' => true, |
|
119
|
|
|
'filters' => array( |
|
120
|
|
|
array('name' => 'Zend\Filter\StringTrim'), |
|
121
|
|
|
), |
|
122
|
|
|
'validators' => array( |
|
123
|
|
|
new GreaterThan(array( |
|
124
|
|
|
'min' => 0, |
|
125
|
|
|
'inclusive' => true |
|
126
|
|
|
)), |
|
127
|
|
|
new RegexValidator('/^\$?[0-9]+(,[0-9]{3})*(.[0-9]{2})?$/'), |
|
128
|
|
|
), |
|
129
|
|
|
), |
|
130
|
|
|
'currency' => array( |
|
131
|
|
|
'required' => true, |
|
132
|
|
|
'filters' => array(), |
|
133
|
|
|
'validators' => array( |
|
134
|
|
|
new InArrayValidator(array( |
|
135
|
|
|
'haystack' => SalaryEntity::getValidCurrencyCodes(), |
|
136
|
|
|
'strict' => true |
|
137
|
|
|
)), |
|
138
|
|
|
), |
|
139
|
|
|
), |
|
140
|
|
|
'unit' => array( |
|
141
|
|
|
'required' => true, |
|
142
|
|
|
'filters' => array(), |
|
143
|
|
|
'validators' => array( |
|
144
|
|
|
new InArrayValidator(array( |
|
145
|
|
|
'haystack' => SalaryEntity::getValidUnits(), |
|
146
|
|
|
'strict' => true |
|
147
|
|
|
)), |
|
148
|
|
|
), |
|
149
|
|
|
), |
|
150
|
|
|
); |
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
|