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;
|
|
|
|
|
2017-10-12 11:13:20 +03:00
|
|
|
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
|
2019-02-17 14:59:55 +03:00
|
|
|
use Shlinkio\Shlink\Common\IpGeolocation\Model\Location;
|
2018-12-08 14:12:11 +03:00
|
|
|
use Shlinkio\Shlink\Core\Visit\Model\VisitLocationInterface;
|
2016-07-20 10:35:46 +03:00
|
|
|
|
2018-12-08 14:12:11 +03:00
|
|
|
class VisitLocation extends AbstractEntity implements VisitLocationInterface
|
2016-07-20 10:35:46 +03:00
|
|
|
{
|
2018-12-16 14:08:03 +03:00
|
|
|
/** @var string */
|
2018-09-15 11:03:42 +03:00
|
|
|
private $countryCode;
|
2018-12-16 14:08:03 +03:00
|
|
|
/** @var string */
|
2018-09-15 11:03:42 +03:00
|
|
|
private $countryName;
|
2018-12-16 14:08:03 +03:00
|
|
|
/** @var string */
|
2018-09-15 11:03:42 +03:00
|
|
|
private $regionName;
|
2018-12-16 14:08:03 +03:00
|
|
|
/** @var string */
|
2018-09-15 11:03:42 +03:00
|
|
|
private $cityName;
|
2018-12-16 14:08:03 +03:00
|
|
|
/** @var string */
|
2018-09-15 11:03:42 +03:00
|
|
|
private $latitude;
|
2018-12-16 14:08:03 +03:00
|
|
|
/** @var string */
|
2018-09-15 11:03:42 +03:00
|
|
|
private $longitude;
|
2018-12-16 14:08:03 +03:00
|
|
|
/** @var string */
|
2018-09-15 11:03:42 +03:00
|
|
|
private $timezone;
|
2016-07-20 10:35:46 +03:00
|
|
|
|
2019-02-17 14:59:55 +03:00
|
|
|
public function __construct(Location $location)
|
2016-07-20 10:35:46 +03:00
|
|
|
{
|
2019-02-17 14:59:55 +03:00
|
|
|
$this->exchangeLocationInfo($location);
|
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
|
|
|
}
|
|
|
|
|
2019-02-17 14:59:55 +03:00
|
|
|
private function exchangeLocationInfo(Location $info): void
|
2016-07-20 10:35:46 +03:00
|
|
|
{
|
2019-02-17 14:59:55 +03:00
|
|
|
$this->countryCode = $info->countryCode();
|
|
|
|
$this->countryName = $info->countryName();
|
|
|
|
$this->regionName = $info->regionName();
|
|
|
|
$this->cityName = $info->city();
|
|
|
|
$this->latitude = (string) $info->latitude();
|
|
|
|
$this->longitude = (string) $info->longitude();
|
|
|
|
$this->timezone = $info->timeZone();
|
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,
|
|
|
|
];
|
|
|
|
}
|
2019-02-27 00:31:07 +03:00
|
|
|
|
|
|
|
public function isEmpty(): bool
|
|
|
|
{
|
|
|
|
return
|
|
|
|
$this->countryCode === '' &&
|
|
|
|
$this->countryName === '' &&
|
|
|
|
$this->regionName === '' &&
|
|
|
|
$this->cityName === '' &&
|
|
|
|
((float) $this->latitude) === 0.0 &&
|
|
|
|
((float) $this->longitude) === 0.0 &&
|
|
|
|
$this->timezone === '';
|
|
|
|
}
|
2016-07-20 10:35:46 +03:00
|
|
|
}
|