shlink/module/Core/src/Entity/VisitLocation.php

123 lines
3.1 KiB
PHP
Raw Normal View History

2016-07-20 10:35:46 +03:00
<?php
2017-10-12 11:13:20 +03:00
declare(strict_types=1);
2016-07-20 10:35:46 +03:00
namespace Shlinkio\Shlink\Core\Entity;
use Doctrine\ORM\Mapping as ORM;
2017-10-12 11:13:20 +03:00
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
use Shlinkio\Shlink\Core\Visit\Model\VisitLocationInterface;
use function array_key_exists;
2016-07-20 10:35:46 +03:00
/**
* Class VisitLocation
* @author
* @link
*
* @ORM\Entity()
* @ORM\Table(name="visit_locations")
*/
class VisitLocation extends AbstractEntity implements VisitLocationInterface
2016-07-20 10:35:46 +03:00
{
/**
* @var string
* @ORM\Column(nullable=true, name="country_code")
2016-07-20 10:35:46 +03:00
*/
private $countryCode;
2016-07-20 10:35:46 +03:00
/**
* @var string
* @ORM\Column(nullable=true, name="country_name")
2016-07-20 10:35:46 +03:00
*/
private $countryName;
2016-07-20 10:35:46 +03:00
/**
* @var string
* @ORM\Column(nullable=true, name="region_name")
2016-07-20 10:35:46 +03:00
*/
private $regionName;
2016-07-20 10:35:46 +03:00
/**
* @var string
* @ORM\Column(nullable=true, name="city_name")
2016-07-20 10:35:46 +03:00
*/
private $cityName;
2016-07-20 10:35:46 +03:00
/**
* @var string
* @ORM\Column(nullable=true, name="latitude")
2016-07-20 10:35:46 +03:00
*/
private $latitude;
2016-07-20 10:35:46 +03:00
/**
* @var string
* @ORM\Column(nullable=true, name="longitude")
2016-07-20 10:35:46 +03:00
*/
private $longitude;
2016-07-20 10:35:46 +03:00
/**
* @var string
* @ORM\Column(nullable=true, name="timezone")
2016-07-20 10:35:46 +03:00
*/
private $timezone;
2016-07-20 10:35:46 +03:00
public function __construct(array $locationInfo)
2016-07-20 10:35:46 +03:00
{
$this->exchangeArray($locationInfo);
2016-07-20 10:35:46 +03:00
}
public function getCountryName(): string
2016-07-20 10:35:46 +03:00
{
return $this->countryName ?? '';
2016-07-20 10:35:46 +03:00
}
public function getLatitude(): string
2016-07-20 10:35:46 +03:00
{
return $this->latitude ?? '';
2016-07-20 10:35:46 +03:00
}
public function getLongitude(): string
2016-07-20 10:35:46 +03:00
{
return $this->longitude ?? '';
2016-07-20 10:35:46 +03:00
}
public function getCityName(): string
2016-07-20 10:35:46 +03:00
{
return $this->cityName ?? '';
2016-07-20 10:35:46 +03:00
}
/**
* Exchange internal values from provided array
*/
private function exchangeArray(array $array): void
2016-07-20 10:35:46 +03:00
{
if (array_key_exists('country_code', $array)) {
$this->countryCode = (string) $array['country_code'];
2016-07-20 10:35:46 +03:00
}
if (array_key_exists('country_name', $array)) {
$this->countryName = (string) $array['country_name'];
2016-07-20 10:35:46 +03:00
}
if (array_key_exists('region_name', $array)) {
$this->regionName = (string) $array['region_name'];
2016-07-20 10:35:46 +03:00
}
if (array_key_exists('city', $array)) {
$this->cityName = (string) $array['city'];
2016-07-20 10:35:46 +03:00
}
if (array_key_exists('latitude', $array)) {
$this->latitude = (string) $array['latitude'];
2016-07-20 10:35:46 +03:00
}
if (array_key_exists('longitude', $array)) {
$this->longitude = (string) $array['longitude'];
2016-07-20 10:35:46 +03:00
}
if (array_key_exists('time_zone', $array)) {
$this->timezone = (string) $array['time_zone'];
2016-07-20 10:35:46 +03:00
}
}
public function jsonSerialize(): array
2016-07-20 10:35:46 +03:00
{
return [
'countryCode' => $this->countryCode,
'countryName' => $this->countryName,
'regionName' => $this->regionName,
'cityName' => $this->cityName,
'latitude' => $this->latitude,
'longitude' => $this->longitude,
'timezone' => $this->timezone,
];
}
}