<?php
namespace App\Entity;
use App\Repository\DeviceRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=DeviceRepository::class)
*/
class Device
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="devices")
* @ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $userAgent;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $lastOnline;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $platform;
/**
* @ORM\OneToMany(targetEntity=AccessToken::class, mappedBy="device")
*/
private $accessTokens;
/**
* @ORM\Column(type="string", length=255, unique=true)
*/
private $deviceId;
public function __construct()
{
$this->accessTokens = new ArrayCollection();
$this->createdAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getUserAgent(): ?string
{
return $this->userAgent;
}
public function setUserAgent(?string $userAgent): self
{
$this->userAgent = $userAgent;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getLastOnline(): ?\DateTimeInterface
{
return $this->lastOnline;
}
public function setLastOnline(?\DateTimeInterface $lastOnline): self
{
$this->lastOnline = $lastOnline;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getPlatform(): ?string
{
return $this->platform;
}
public function setPlatform(?string $platform): self
{
$this->platform = $platform;
return $this;
}
/**
* @return Collection<int, AccessToken>
*/
public function getAccessTokens(): Collection
{
return $this->accessTokens;
}
public function addAccessToken(AccessToken $accessToken): self
{
if (!$this->accessTokens->contains($accessToken)) {
$this->accessTokens[] = $accessToken;
$accessToken->setDevice($this);
}
return $this;
}
public function removeAccessToken(AccessToken $accessToken): self
{
if ($this->accessTokens->removeElement($accessToken)) {
// set the owning side to null (unless already changed)
if ($accessToken->getDevice() === $this) {
$accessToken->setDevice(null);
}
}
return $this;
}
public function getDeviceId(): ?string
{
return $this->deviceId;
}
public function setDeviceId(string $deviceId): self
{
$this->deviceId = $deviceId;
return $this;
}
}