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;
|
2018-12-08 14:12:11 +03:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Model\VisitLocationInterface;
|
2018-10-28 10:24:06 +03:00
|
|
|
use function array_key_exists;
|
2016-07-20 10:35:46 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class VisitLocation
|
|
|
|
* @author
|
|
|
|
* @link
|
|
|
|
*
|
|
|
|
* @ORM\Entity()
|
|
|
|
* @ORM\Table(name="visit_locations")
|
|
|
|
*/
|
2018-12-08 14:12:11 +03:00
|
|
|
class VisitLocation extends AbstractEntity implements VisitLocationInterface
|
2016-07-20 10:35:46 +03:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
2018-10-20 10:02:50 +03:00
|
|
|
* @ORM\Column(nullable=true, name="country_code")
|
2016-07-20 10:35:46 +03:00
|
|
|
*/
|
2018-09-15 11:03:42 +03:00
|
|
|
private $countryCode;
|
2016-07-20 10:35:46 +03:00
|
|
|
/**
|
|
|
|
* @var string
|
2018-10-20 10:02:50 +03:00
|
|
|
* @ORM\Column(nullable=true, name="country_name")
|
2016-07-20 10:35:46 +03:00
|
|
|
*/
|
2018-09-15 11:03:42 +03:00
|
|
|
private $countryName;
|
2016-07-20 10:35:46 +03:00
|
|
|
/**
|
|
|
|
* @var string
|
2018-10-20 10:02:50 +03:00
|
|
|
* @ORM\Column(nullable=true, name="region_name")
|
2016-07-20 10:35:46 +03:00
|
|
|
*/
|
2018-09-15 11:03:42 +03:00
|
|
|
private $regionName;
|
2016-07-20 10:35:46 +03:00
|
|
|
/**
|
|
|
|
* @var string
|
2018-10-20 10:02:50 +03:00
|
|
|
* @ORM\Column(nullable=true, name="city_name")
|
2016-07-20 10:35:46 +03:00
|
|
|
*/
|
2018-09-15 11:03:42 +03:00
|
|
|
private $cityName;
|
2016-07-20 10:35:46 +03:00
|
|
|
/**
|
|
|
|
* @var string
|
2018-10-20 10:02:50 +03:00
|
|
|
* @ORM\Column(nullable=true, name="latitude")
|
2016-07-20 10:35:46 +03:00
|
|
|
*/
|
2018-09-15 11:03:42 +03:00
|
|
|
private $latitude;
|
2016-07-20 10:35:46 +03:00
|
|
|
/**
|
|
|
|
* @var string
|
2018-10-20 10:02:50 +03:00
|
|
|
* @ORM\Column(nullable=true, name="longitude")
|
2016-07-20 10:35:46 +03:00
|
|
|
*/
|
2018-09-15 11:03:42 +03:00
|
|
|
private $longitude;
|
2016-07-20 10:35:46 +03:00
|
|
|
/**
|
|
|
|
* @var string
|
2018-10-20 10:02:50 +03:00
|
|
|
* @ORM\Column(nullable=true, name="timezone")
|
2016-07-20 10:35:46 +03:00
|
|
|
*/
|
2018-09-15 11:03:42 +03:00
|
|
|
private $timezone;
|
2016-07-20 10:35:46 +03:00
|
|
|
|
2018-10-28 17:13:45 +03:00
|
|
|
public function __construct(array $locationInfo)
|
2016-07-20 10:35:46 +03:00
|
|
|
{
|
2018-10-28 17:13:45 +03:00
|
|
|
$this->exchangeArray($locationInfo);
|
2016-07-20 10:35:46 +03:00
|
|
|
}
|
|
|
|
|
2018-09-15 11:03:42 +03:00
|
|
|
public function getCountryName(): string
|
2016-07-20 10:35:46 +03:00
|
|
|
{
|
2018-09-15 11:03:42 +03:00
|
|
|
return $this->countryName ?? '';
|
2016-07-20 10:35:46 +03:00
|
|
|
}
|
|
|
|
|
2018-09-15 11:03:42 +03:00
|
|
|
public function getLatitude(): string
|
2016-07-20 10:35:46 +03:00
|
|
|
{
|
2018-09-15 11:03:42 +03:00
|
|
|
return $this->latitude ?? '';
|
2016-07-20 10:35:46 +03:00
|
|
|
}
|
|
|
|
|
2018-09-15 11:03:42 +03:00
|
|
|
public function getLongitude(): string
|
2016-07-20 10:35:46 +03:00
|
|
|
{
|
2018-09-15 11:03:42 +03:00
|
|
|
return $this->longitude ?? '';
|
2016-07-20 10:35:46 +03:00
|
|
|
}
|
|
|
|
|
2018-10-28 17:13:45 +03:00
|
|
|
public function getCityName(): string
|
2016-07-20 10:35:46 +03:00
|
|
|
{
|
2018-10-28 17:13:45 +03:00
|
|
|
return $this->cityName ?? '';
|
2016-07-20 10:35:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Exchange internal values from provided array
|
|
|
|
*/
|
2018-10-28 17:13:45 +03:00
|
|
|
private function exchangeArray(array $array): void
|
2016-07-20 10:35:46 +03:00
|
|
|
{
|
2018-10-28 10:24:06 +03:00
|
|
|
if (array_key_exists('country_code', $array)) {
|
2018-10-28 17:13:45 +03:00
|
|
|
$this->countryCode = (string) $array['country_code'];
|
2016-07-20 10:35:46 +03:00
|
|
|
}
|
2018-10-28 10:24:06 +03:00
|
|
|
if (array_key_exists('country_name', $array)) {
|
2018-10-28 17:13:45 +03:00
|
|
|
$this->countryName = (string) $array['country_name'];
|
2016-07-20 10:35:46 +03:00
|
|
|
}
|
2018-10-28 10:24:06 +03:00
|
|
|
if (array_key_exists('region_name', $array)) {
|
2018-10-28 17:13:45 +03:00
|
|
|
$this->regionName = (string) $array['region_name'];
|
2016-07-20 10:35:46 +03:00
|
|
|
}
|
2018-10-28 10:24:06 +03:00
|
|
|
if (array_key_exists('city', $array)) {
|
2018-10-28 17:13:45 +03:00
|
|
|
$this->cityName = (string) $array['city'];
|
2016-07-20 10:35:46 +03:00
|
|
|
}
|
2018-10-28 10:24:06 +03:00
|
|
|
if (array_key_exists('latitude', $array)) {
|
2018-10-28 17:13:45 +03:00
|
|
|
$this->latitude = (string) $array['latitude'];
|
2016-07-20 10:35:46 +03:00
|
|
|
}
|
2018-10-28 10:24:06 +03:00
|
|
|
if (array_key_exists('longitude', $array)) {
|
2018-10-28 17:13:45 +03:00
|
|
|
$this->longitude = (string) $array['longitude'];
|
2016-07-20 10:35:46 +03:00
|
|
|
}
|
2018-10-28 10:24:06 +03:00
|
|
|
if (array_key_exists('time_zone', $array)) {
|
2018-10-28 17:13:45 +03:00
|
|
|
$this->timezone = (string) $array['time_zone'];
|
2016-07-20 10:35:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-28 17:13:45 +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,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|