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

183 lines
3.8 KiB
PHP
Raw Normal View History

2016-04-17 11:46:35 +03:00
<?php
2017-10-12 11:13:20 +03:00
declare(strict_types=1);
2016-07-19 19:01:39 +03:00
namespace Shlinkio\Shlink\Core\Entity;
2016-04-17 11:46:35 +03:00
use Doctrine\ORM\Mapping as ORM;
2016-07-19 19:01:39 +03:00
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
2016-04-17 11:46:35 +03:00
/**
* Class Visit
* @author
* @link
*
* @ORM\Entity(repositoryClass="Shlinkio\Shlink\Core\Repository\VisitRepository")
2016-04-17 11:46:35 +03:00
* @ORM\Table(name="visits")
*/
class Visit extends AbstractEntity implements \JsonSerializable
2016-04-17 11:46:35 +03:00
{
/**
* @var string
* @ORM\Column(type="string", length=256, nullable=true)
2016-04-17 11:46:35 +03:00
*/
protected $referer;
/**
* @var \DateTime
* @ORM\Column(type="datetime", nullable=false)
*/
protected $date;
/**
* @var string
* @ORM\Column(type="string", length=256, name="remote_addr", nullable=true)
2016-04-17 11:46:35 +03:00
*/
protected $remoteAddr;
2016-04-17 11:46:35 +03:00
/**
* @var string
* @ORM\Column(type="string", length=256, name="user_agent", nullable=true)
2016-04-17 11:46:35 +03:00
*/
protected $userAgent;
2016-04-17 11:46:35 +03:00
/**
* @var ShortUrl
* @ORM\ManyToOne(targetEntity=ShortUrl::class)
* @ORM\JoinColumn(name="short_url_id", referencedColumnName="id")
*/
protected $shortUrl;
2016-07-20 10:35:46 +03:00
/**
* @var VisitLocation
* @ORM\ManyToOne(targetEntity=VisitLocation::class, cascade={"persist"})
2016-07-20 10:35:46 +03:00
* @ORM\JoinColumn(name="visit_location_id", referencedColumnName="id", nullable=true)
*/
protected $visitLocation;
2016-04-17 11:46:35 +03:00
public function __construct()
{
$this->date = new \DateTime();
}
2016-04-17 11:46:35 +03:00
/**
* @return string
*/
public function getReferer()
{
return $this->referer;
}
/**
* @param string $referer
* @return $this
*/
public function setReferer($referer)
{
$this->referer = $referer;
return $this;
}
/**
* @return \DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* @param \DateTime $date
* @return $this
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
/**
* @return ShortUrl
2016-04-17 11:46:35 +03:00
*/
public function getShortUrl()
2016-04-17 11:46:35 +03:00
{
return $this->shortUrl;
2016-04-17 11:46:35 +03:00
}
/**
* @param ShortUrl $shortUrl
2016-04-17 11:46:35 +03:00
* @return $this
*/
public function setShortUrl($shortUrl)
2016-04-17 11:46:35 +03:00
{
$this->shortUrl = $shortUrl;
2016-04-17 11:46:35 +03:00
return $this;
}
/**
* @return string
*/
public function getRemoteAddr()
2016-04-17 11:46:35 +03:00
{
return $this->remoteAddr;
2016-04-17 11:46:35 +03:00
}
/**
* @param string $remoteAddr
2016-04-17 11:46:35 +03:00
* @return $this
*/
public function setRemoteAddr($remoteAddr)
2016-04-17 11:46:35 +03:00
{
$this->remoteAddr = $remoteAddr;
2016-04-17 11:46:35 +03:00
return $this;
}
/**
* @return string
*/
public function getUserAgent()
2016-04-17 11:46:35 +03:00
{
return $this->userAgent;
2016-04-17 11:46:35 +03:00
}
/**
* @param string $userAgent
2016-04-17 11:46:35 +03:00
* @return $this
*/
public function setUserAgent($userAgent)
2016-04-17 11:46:35 +03:00
{
$this->userAgent = $userAgent;
2016-04-17 11:46:35 +03:00
return $this;
}
2016-07-20 10:35:46 +03:00
/**
* @return VisitLocation
*/
public function getVisitLocation()
{
return $this->visitLocation;
}
/**
* @param VisitLocation $visitLocation
* @return $this
*/
public function setVisitLocation($visitLocation)
{
$this->visitLocation = $visitLocation;
return $this;
}
/**
* Specify data which should be serialized to JSON
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
public function jsonSerialize()
{
return [
'referer' => $this->referer,
2017-04-16 11:27:27 +03:00
'date' => isset($this->date) ? $this->date->format(\DateTime::ATOM) : null,
'remoteAddr' => $this->remoteAddr,
'userAgent' => $this->userAgent,
2016-07-20 10:35:46 +03:00
'visitLocation' => $this->visitLocation,
];
}
2016-04-17 11:46:35 +03:00
}