|
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 Core\Entity; |
|
11
|
|
|
|
|
12
|
|
|
use GeoJson\GeoJson; |
|
13
|
|
|
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; |
|
14
|
|
|
use Zend\Json\Json; |
|
15
|
|
|
|
|
16
|
|
|
abstract class AbstractLocation extends AbstractEntity implements LocationInterface |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* city name of a job location |
|
20
|
|
|
* |
|
21
|
|
|
* @ODM\Field(type="string") |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $city; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* region of a job location. E.g "Hessen" is a region in germany |
|
27
|
|
|
* |
|
28
|
|
|
* @ODM\Field(type="string") |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $region; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* postalcode of a job location. |
|
34
|
|
|
* |
|
35
|
|
|
* @var String |
|
36
|
|
|
* @ODM\Field(type="string") |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $postalcode; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* coordinates of a job location. |
|
42
|
|
|
* |
|
43
|
|
|
* @var GeoJson |
|
44
|
|
|
* @ODM\EmbedOne(discriminatorField="_entity") |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $coordinates; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Country of a job location |
|
50
|
|
|
* @var String |
|
51
|
|
|
* |
|
52
|
|
|
* @ODM\Field(type="string") |
|
53
|
|
|
*/ |
|
54
|
|
|
protected $country; |
|
55
|
|
|
|
|
56
|
|
|
public function __construct() |
|
57
|
|
|
{ |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function __toString() |
|
61
|
|
|
{ |
|
62
|
|
|
$coords = $this->getCoordinates(); |
|
63
|
|
|
$postalCode = $this->getPostalCode(); |
|
64
|
|
|
$city = $this->getCity(); |
|
65
|
|
|
$country = $this->getCountry(); |
|
66
|
|
|
$region = $this->getRegion(); |
|
67
|
|
|
|
|
68
|
|
|
$str = ''; |
|
69
|
|
|
if ($postalCode) { $str .= $postalCode . ' '; } |
|
70
|
|
|
if ($city) { $str .= $city; } |
|
71
|
|
|
if ($region) { $str .= ', ' . $region; } |
|
72
|
|
|
if ($country) { $str .= ', ' . $country; } |
|
73
|
|
|
if ($coords) { |
|
74
|
|
|
$coords = $coords->getCoordinates(); |
|
75
|
|
|
$str .= ' ( ' . join(', ', $coords) . ' )'; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $str; |
|
79
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function toString() |
|
83
|
|
|
{ |
|
84
|
|
|
$coords = $this->getCoordinates(); |
|
85
|
|
|
$attributes = [ |
|
86
|
|
|
'city' => $this->getCity(), |
|
87
|
|
|
'region' => $this->getRegion(), |
|
88
|
|
|
'postalCode' => $this->getPostalCode(), |
|
89
|
|
|
'country' => $this->getCountry(), |
|
90
|
|
|
'coordinates' => $coords |
|
91
|
|
|
? [ |
|
92
|
|
|
'type' => $coords->getType(), |
|
93
|
|
|
'coordinates' => $coords->getCoordinates(), |
|
94
|
|
|
] |
|
95
|
|
|
: null |
|
96
|
|
|
|
|
97
|
|
|
]; |
|
98
|
|
|
|
|
99
|
|
|
return Json::encode($attributes); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function fromString($serialized) |
|
103
|
|
|
{ |
|
104
|
|
|
$attributes = Json::decode($serialized, Json::TYPE_ARRAY); |
|
105
|
|
|
|
|
106
|
|
|
foreach ($attributes as $key => $value) { |
|
107
|
|
|
if (!$value) { continue; } |
|
108
|
|
|
|
|
109
|
|
|
if ('coordinates' == $key) { |
|
110
|
|
|
$class = '\\Geo\\Entity\\Geometry\\' . $value['type']; |
|
111
|
|
|
$value = new $class($value['coordinates']); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
$setter = "set$key"; |
|
115
|
|
|
if (is_callable([$this, $setter])) { |
|
116
|
|
|
$this->$setter($value); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
return $this; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @codeCoverageIgnore |
|
125
|
|
|
*/ |
|
126
|
|
|
public function preUpdate() |
|
127
|
|
|
{ |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function getCoordinates() |
|
131
|
|
|
{ |
|
132
|
|
|
return $this->coordinates; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @param GeoJson $coordinates |
|
137
|
|
|
* |
|
138
|
|
|
* @return $this |
|
139
|
|
|
*/ |
|
140
|
|
|
public function setCoordinates(GeoJson $coordinates) |
|
141
|
|
|
{ |
|
142
|
|
|
$this->coordinates = $coordinates; |
|
143
|
|
|
return $this; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @return String |
|
148
|
|
|
*/ |
|
149
|
|
|
public function getPostalCode() |
|
150
|
|
|
{ |
|
151
|
|
|
return $this->postalcode; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @param $postalcode |
|
156
|
|
|
* |
|
157
|
|
|
* @return $this |
|
158
|
|
|
*/ |
|
159
|
|
|
public function setPostalCode($postalcode) |
|
160
|
|
|
{ |
|
161
|
|
|
$this->postalcode = $postalcode; |
|
162
|
|
|
return $this; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* @return mixed |
|
167
|
|
|
*/ |
|
168
|
|
|
public function getCity() |
|
169
|
|
|
{ |
|
170
|
|
|
return $this->city; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* @param $country |
|
175
|
|
|
* |
|
176
|
|
|
* @return $this |
|
177
|
|
|
*/ |
|
178
|
|
|
public function setCity($country) |
|
179
|
|
|
{ |
|
180
|
|
|
$this->city = $country; |
|
181
|
|
|
return $this; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @return String |
|
186
|
|
|
*/ |
|
187
|
|
|
public function getCountry() |
|
188
|
|
|
{ |
|
189
|
|
|
return $this->country; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* @param $country |
|
194
|
|
|
* |
|
195
|
|
|
* @return $this |
|
196
|
|
|
*/ |
|
197
|
|
|
public function setCountry($country) |
|
198
|
|
|
{ |
|
199
|
|
|
$this->country = $country; |
|
200
|
|
|
return $this; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* @return mixed |
|
205
|
|
|
*/ |
|
206
|
|
|
public function getRegion() |
|
207
|
|
|
{ |
|
208
|
|
|
return $this->region; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* @param $region |
|
213
|
|
|
* |
|
214
|
|
|
* @return $this |
|
215
|
|
|
*/ |
|
216
|
|
|
public function setRegion($region) |
|
217
|
|
|
{ |
|
218
|
|
|
$this->region = $region; |
|
219
|
|
|
return $this; |
|
220
|
|
|
} |
|
221
|
|
|
} |
|
222
|
|
|
|