Skip to content

Commit

Permalink
[Core] Add Streetname and -number to AbstractLocation
Browse files Browse the repository at this point in the history
* Also add methods "fromArray" and "toArray".
  • Loading branch information
TiSiE committed Dec 21, 2017
1 parent a165491 commit b4f4238
Showing 1 changed file with 87 additions and 7 deletions.
94 changes: 87 additions & 7 deletions module/Core/src/Core/Entity/AbstractLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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; }
Expand All @@ -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
? [
Expand All @@ -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) {
Expand All @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit b4f4238

Please sign in to comment.