|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
* @author [email protected] |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Jobs\Form; |
|
12
|
|
|
|
|
13
|
|
|
use Core\Entity\EntityInterface; |
|
14
|
|
|
use Core\Entity\EntityTrait; |
|
15
|
|
|
use Core\Entity\Hydrator\MappingEntityHydrator; |
|
16
|
|
|
use Core\Form\HydratorStrategyAwareTrait; |
|
17
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
18
|
|
|
use Jobs\Entity\Location; |
|
19
|
|
|
use Jobs\Form\Hydrator\Strategy\LocationStrategy; |
|
20
|
|
|
use Zend\Form\Exception; |
|
21
|
|
|
use Zend\Form\Fieldset; |
|
22
|
|
|
use Core\Entity\Hydrator\EntityHydrator; |
|
23
|
|
|
use Zend\Form\FieldsetInterface; |
|
24
|
|
|
use Core\Form\CustomizableFieldsetInterface; |
|
25
|
|
|
use Core\Form\CustomizableFieldsetTrait; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Defines the formular fields of the base formular of a job opening. |
|
29
|
|
|
*/ |
|
30
|
|
|
class BaseFieldset extends Fieldset implements CustomizableFieldsetInterface |
|
31
|
|
|
{ |
|
32
|
|
|
use CustomizableFieldsetTrait; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @return \Zend\Hydrator\HydratorInterface |
|
36
|
|
|
*/ |
|
37
|
|
|
public function getHydrator() |
|
38
|
|
|
{ |
|
39
|
|
|
if (!$this->hydrator) { |
|
40
|
|
|
$hydrator = new MappingEntityHydrator([ |
|
41
|
|
|
'locations' => 'geoLocation' |
|
42
|
|
|
]); |
|
43
|
|
|
|
|
44
|
|
|
$geoLocationIsMultiple = $this->get('geoLocation')->getAttribute('multiple', false); |
|
|
|
|
|
|
45
|
|
|
$geoLocationStrategy = $this->get('geoLocation')->getHydratorStrategy(); |
|
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
$locationsStrategy = new \Zend\Hydrator\Strategy\ClosureStrategy( |
|
48
|
|
|
/* extract */ |
|
49
|
|
|
function ($value) use ($geoLocationStrategy, $geoLocationIsMultiple) |
|
50
|
|
|
{ |
|
51
|
|
|
$value = $geoLocationIsMultiple ? $value : $value->first(); |
|
52
|
|
|
|
|
53
|
|
|
return $geoLocationStrategy->extract($value); |
|
54
|
|
|
}, |
|
55
|
|
|
|
|
56
|
|
|
/* hydrate */ |
|
57
|
|
|
function ($value) use ($geoLocationStrategy, $geoLocationIsMultiple) |
|
58
|
|
|
{ |
|
59
|
|
|
if ($geoLocationIsMultiple) { |
|
60
|
|
|
return $geoLocationStrategy->hydrate($value); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return new ArrayCollection([$geoLocationStrategy->hydrate($value)]); |
|
64
|
|
|
} |
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
|
|
$hydrator->addStrategy('locations', $locationsStrategy); |
|
68
|
|
|
|
|
69
|
|
|
/* |
|
|
|
|
|
|
70
|
|
|
$datetimeStrategy = new Hydrator\DatetimeStrategy(); |
|
71
|
|
|
$datetimeStrategy->setHydrateFormat(Hydrator\DatetimeStrategy::FORMAT_MYSQLDATE); |
|
72
|
|
|
$hydrator->addStrategy('datePublishStart', $datetimeStrategy); |
|
73
|
|
|
*/ |
|
74
|
|
|
|
|
75
|
|
|
$this->setHydrator($hydrator); |
|
76
|
|
|
} |
|
77
|
|
|
return $this->hydrator; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function init() |
|
81
|
|
|
{ |
|
82
|
|
|
$this->setAttribute('id', 'job-fieldset'); |
|
83
|
|
|
|
|
84
|
|
|
$this->setName('jobBase'); |
|
85
|
|
|
|
|
86
|
|
|
$this->add( |
|
87
|
|
|
[ |
|
88
|
|
|
'type' => 'Text', |
|
89
|
|
|
'name' => 'title', |
|
90
|
|
|
'options' => [ |
|
91
|
|
|
'label' => /*@translate*/ 'Job title', |
|
92
|
|
|
'description' => /*@translate*/ 'Please enter the job title' |
|
93
|
|
|
], |
|
94
|
|
|
] |
|
95
|
|
|
); |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
$this->add( |
|
99
|
|
|
[ |
|
100
|
|
|
'type' => 'LocationSelect', |
|
101
|
|
|
'name' => 'geoLocation', |
|
102
|
|
|
'options' => [ |
|
103
|
|
|
'label' => /*@translate*/ 'Location', |
|
104
|
|
|
'description' => /*@translate*/ 'Please enter the location of the job', |
|
105
|
|
|
'location_entity' => Location::class, |
|
106
|
|
|
'summary_value' => [$this, 'getLocationsSummaryValue'], |
|
107
|
|
|
], |
|
108
|
|
|
'attributes' => [ |
|
109
|
|
|
'data-width' => '100%', |
|
110
|
|
|
] |
|
111
|
|
|
] |
|
112
|
|
|
); |
|
113
|
|
|
|
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* |
|
118
|
|
|
* @codeCoverageIgnore |
|
119
|
|
|
* @return string |
|
120
|
|
|
*/ |
|
121
|
|
|
public function getLocationsSummaryValue() |
|
122
|
|
|
{ |
|
123
|
|
|
$element = $this->get('geoLocation'); |
|
124
|
|
|
$isMultiple = $element->getAttribute('multiple', false); |
|
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
$values = []; |
|
127
|
|
|
foreach ($this->object->getLocations() as $loc) { |
|
128
|
|
|
$values[] = trim( |
|
129
|
|
|
$loc->getPostalCode() . ' ' . $loc->getCity() . ', ' . $loc->getRegion(), |
|
130
|
|
|
' ,' |
|
131
|
|
|
); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
if (count($values)) { |
|
135
|
|
|
if ($isMultiple) { |
|
136
|
|
|
return '<ul><li>' . join('</li><li>', $values) . '</li></ul>'; |
|
137
|
|
|
} else { |
|
138
|
|
|
return $values[0]; |
|
139
|
|
|
} |
|
140
|
|
|
} else { |
|
141
|
|
|
return ''; |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.