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

86 lines
2.2 KiB
PHP
Raw Normal View History

2016-07-20 10:35:46 +03:00
<?php
2019-10-05 18:26:10 +03:00
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;
use Shlinkio\Shlink\Core\Visit\Model\VisitLocationInterface;
use Shlinkio\Shlink\IpGeolocation\Model\Location;
2016-07-20 10:35:46 +03:00
class VisitLocation extends AbstractEntity implements VisitLocationInterface
2016-07-20 10:35:46 +03:00
{
2019-12-30 00:27:00 +03:00
private string $countryCode;
private string $countryName;
private string $regionName;
private string $cityName;
private float $latitude;
private float $longitude;
2019-12-30 00:27:00 +03:00
private string $timezone;
2020-03-23 22:37:45 +03:00
private bool $isEmpty;
2016-07-20 10:35:46 +03:00
public function __construct(Location $location)
2016-07-20 10:35:46 +03:00
{
$this->exchangeLocationInfo($location);
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(): float
2016-07-20 10:35:46 +03:00
{
return $this->latitude;
2016-07-20 10:35:46 +03:00
}
public function getLongitude(): float
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
}
2020-03-23 22:37:45 +03:00
public function isEmpty(): bool
{
return $this->isEmpty;
}
private function exchangeLocationInfo(Location $info): void
2016-07-20 10:35:46 +03:00
{
$this->countryCode = $info->countryCode();
$this->countryName = $info->countryName();
$this->regionName = $info->regionName();
$this->cityName = $info->city();
$this->latitude = $info->latitude();
$this->longitude = $info->longitude();
$this->timezone = $info->timeZone();
2020-03-23 22:37:45 +03:00
$this->isEmpty = (
$this->countryCode === '' &&
$this->countryName === '' &&
$this->regionName === '' &&
$this->cityName === '' &&
$this->latitude === 0.0 &&
$this->longitude === 0.0 &&
$this->timezone === ''
);
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,
2020-03-23 22:37:45 +03:00
'isEmpty' => $this->isEmpty,
2016-07-20 10:35:46 +03:00
];
}
}