diff --git a/module/Core/src/Core/Entity/AbstractLocation.php b/module/Core/src/Core/Entity/AbstractLocation.php index a7bf32c2b..06fcce8ac 100644 --- a/module/Core/src/Core/Entity/AbstractLocation.php +++ b/module/Core/src/Core/Entity/AbstractLocation.php @@ -15,6 +15,22 @@ abstract class AbstractLocation extends AbstractEntity implements LocationInterface { + /** + * Street name + * + * @var string + * @ODM\Field(type="string") + */ + protected $streetname; + + /** + * Street number + * + * @var string + * @ODM\Field(type="string") + */ + protected $streetnumber; + /** * city name of a job location * @@ -53,19 +69,28 @@ abstract class AbstractLocation extends AbstractEntity implements LocationInterf */ protected $country; - public function __construct() + public function __construct($attributes = null) { + if (is_string($attributes)) { + $this->fromString($attributes); + } else if (is_array($attributes)) { + $this->fromArray($attributes); + } } public function __toString() { $coords = $this->getCoordinates(); + $street = $this->getStreetname(); + $number = $this->getStreetnumber(); $postalCode = $this->getPostalCode(); $city = $this->getCity(); $country = $this->getCountry(); $region = $this->getRegion(); $str = ''; + if ($street) { $str .= $street; if (!$number) { $str .= ', '; } } + if ($number) { $str .= ' ' . $number . ', '; } if ($postalCode) { $str .= $postalCode . ' '; } if ($city) { $str .= $city; } if ($region) { $str .= ', ' . $region; } @@ -79,13 +104,15 @@ public function __toString() } - public function toString() + public function toArray() { $coords = $this->getCoordinates(); $attributes = [ + 'streetname' => $this->getStreetname(), + 'streetnumber' => $this->getStreetnumber(), 'city' => $this->getCity(), 'region' => $this->getRegion(), - 'postalCode' => $this->getPostalCode(), + 'postalcode' => $this->getPostalCode(), 'country' => $this->getCountry(), 'coordinates' => $coords ? [ @@ -95,15 +122,19 @@ public function toString() : null ]; + return $attributes; + } + + public function toString() + { + $attributes = $this->toArray(); return Json::encode($attributes); } - public function fromString($serialized) + public function fromArray(array $data) { - $attributes = Json::decode($serialized, Json::TYPE_ARRAY); - - foreach ($attributes as $key => $value) { + foreach ($data as $key => $value) { if (!$value) { continue; } if ('coordinates' == $key) { @@ -120,6 +151,13 @@ public function fromString($serialized) return $this; } + public function fromString($serialized) + { + $attributes = Json::decode($serialized, Json::TYPE_ARRAY); + + return $this->fromArray($attributes); + } + /** * @codeCoverageIgnore */ @@ -162,6 +200,48 @@ public function setPostalCode($postalcode) return $this; } + /** + * @return string + */ + public function getStreetname() + { + return $this->streetname; + } + + /** + * @param string $streetname + * + * @return self + */ + public function setStreetname($streetname) + { + $this->streetname = $streetname; + + return $this; + } + + /** + * @return string + */ + public function getStreetnumber() + { + return $this->streetnumber; + } + + /** + * @param string $streetnumber + * + * @return self + */ + public function setStreetnumber($streetnumber) + { + $this->streetnumber = $streetnumber; + + return $this; + } + + + /** * @return mixed */