|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Cv\Form; |
|
4
|
|
|
|
|
5
|
|
|
use Zend\Form\Fieldset; |
|
6
|
|
|
use Cv\Entity\Employment as EmploymentEntity; |
|
7
|
|
|
use Core\Entity\Hydrator\EntityHydrator; |
|
8
|
|
|
use Zend\InputFilter\InputFilterProviderInterface; |
|
9
|
|
|
use Core\Form\ViewPartialProviderInterface; |
|
10
|
|
|
use Core\Form\ViewPartialProviderTrait; |
|
11
|
|
|
|
|
12
|
|
|
class EmploymentFieldset extends Fieldset implements InputFilterProviderInterface, ViewPartialProviderInterface |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
use ViewPartialProviderTrait; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* View script for rendering |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $defaultPartial = 'cv/form/employment'; |
|
23
|
|
|
|
|
24
|
|
|
public function init() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->setName('employment') |
|
27
|
|
|
->setHydrator(new EntityHydrator()) |
|
28
|
|
|
->setObject(new EmploymentEntity()); |
|
29
|
|
|
|
|
30
|
|
|
$this->add( |
|
31
|
|
|
array( |
|
32
|
|
|
'type' => 'Core/Datepicker', |
|
33
|
|
|
'name' => 'startDate', |
|
34
|
|
|
'options' => array( |
|
35
|
|
|
'label' => /*@translate */ 'Start date' |
|
36
|
|
|
) |
|
37
|
|
|
) |
|
38
|
|
|
); |
|
39
|
|
|
$this->add( |
|
40
|
|
|
array( |
|
41
|
|
|
'type' => 'Core/Datepicker', |
|
42
|
|
|
'name' => 'endDate', |
|
43
|
|
|
'options' => array( |
|
44
|
|
|
'label' => /*@translate */ 'End date' |
|
45
|
|
|
) |
|
46
|
|
|
) |
|
47
|
|
|
); |
|
48
|
|
|
$this->add( |
|
49
|
|
|
array( |
|
50
|
|
|
'type' => 'checkbox', |
|
51
|
|
|
'name' => 'currentIndicator', |
|
52
|
|
|
'options' => array( |
|
53
|
|
|
'label' => /*@translate */ 'ongoing' |
|
54
|
|
|
) |
|
55
|
|
|
) |
|
56
|
|
|
); |
|
57
|
|
|
$this->add( |
|
58
|
|
|
array( |
|
59
|
|
|
'name' => 'organizationName', |
|
60
|
|
|
'options' => array( |
|
61
|
|
|
'label' => /*@translate */ 'Company Name'), |
|
62
|
|
|
'attributes' => array( |
|
63
|
|
|
'title' => /*@translate */ 'please enter the name of the company' |
|
64
|
|
|
), |
|
65
|
|
|
) |
|
66
|
|
|
); |
|
67
|
|
|
$this->add( |
|
68
|
|
|
array( |
|
69
|
|
|
'name' => 'description', |
|
70
|
|
|
'type' => 'Zend\Form\Element\Textarea', |
|
71
|
|
|
'options' => array( |
|
72
|
|
|
'label' => /*@translate */ 'Description', |
|
73
|
|
|
), |
|
74
|
|
|
'attributes' => array( |
|
75
|
|
|
'title' => /*@translate */ 'please describe your position', |
|
76
|
|
|
), |
|
77
|
|
|
) |
|
78
|
|
|
); |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @see \Zend\InputFilter\InputFilterProviderInterface::getInputFilterSpecification() |
|
85
|
|
|
*/ |
|
86
|
|
|
public function getInputFilterSpecification() |
|
87
|
|
|
{ |
|
88
|
|
|
return [ |
|
89
|
|
|
'type' => 'Cv/Employment' |
|
90
|
|
|
]; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @see \Zend\Form\Form::setData() |
|
95
|
|
|
*/ |
|
96
|
|
View Code Duplication |
public function populateValues($data) |
|
|
|
|
|
|
97
|
|
|
{ |
|
98
|
|
|
if (isset($data['currentIndicator']) |
|
99
|
|
|
&& isset($data['endDate']) |
|
100
|
|
|
&& $data['currentIndicator'] |
|
101
|
|
|
) { |
|
102
|
|
|
// empty & hide endDate if currentIndicator is checked |
|
103
|
|
|
$data['endDate'] = ''; |
|
104
|
|
|
$this->get('endDate')->setOption('rowClass', 'hidden'); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
return parent::populateValues($data); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.