<?php
namespace App\Entity;
use App\Repository\UserDeviceRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: UserDeviceRepository::class)]
#[ORM\UniqueConstraint(name: 'uniq_user_token', columns: ['token'])]
class UserDevice
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'devices')]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
private ?User $user = null;
#[ORM\Column(length: 512)]
private ?string $token = null;
/**
* web | android | ios | desktop
*/
#[ORM\Column(length: 20)]
private string $platform = 'web';
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $lastSeenAt = null;
#[ORM\Column]
private \DateTimeImmutable $createdAt;
public function __construct()
{
$this->createdAt = new \DateTimeImmutable();
$this->lastSeenAt = new \DateTimeImmutable();
}
public function getId(): ?int { return $this->id; }
public function getUser(): ?User { return $this->user; }
public function setUser(?User $user): static { $this->user = $user; return $this; }
public function getToken(): ?string { return $this->token; }
public function setToken(string $token): static { $this->token = $token; return $this; }
public function getPlatform(): string { return $this->platform; }
public function setPlatform(string $platform): static { $this->platform = $platform; return $this; }
public function getLastSeenAt(): ?\DateTimeImmutable { return $this->lastSeenAt; }
public function setLastSeenAt(\DateTimeImmutable $dt): static { $this->lastSeenAt = $dt; return $this; }
public function getCreatedAt(): \DateTimeImmutable { return $this->createdAt; }
public function touch(): void
{
$this->lastSeenAt = new \DateTimeImmutable();
}
}