<?php
namespace Diplix\KMGBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="user_device_tokens", indexes={@ORM\Index(name="be_deleted",columns={"be_deleted"}),@ORM\Index(name="user_id",columns={"user_id"})})
* @ORM\Entity()
*/
class DeviceToken extends BasicEntity
{
const FCM = 'fcm';
/**
* @ORM\Column(type="integer",name="id")
* @ORM\Id()
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Diplix\KMGBundle\Entity\User", inversedBy="deviceTokens")
* @ORM\JoinColumn(nullable=false, name="user_id")
*/
protected $user;
/**
* @ORM\Column(type="string")
*/
protected $platform;
/**
* @ORM\Column(type="string",name="token_type")
*/
protected $type = self::FCM;
/**
* @ORM\Column(type="string")
*/
protected $token;
/**
* @ORM\Column(type="datetime")
*/
protected $firstSeen;
/**
* @ORM\Column(type="datetime")
*/
protected $lastSeen;
public static function create(User $user,$token,$platform): DeviceToken
{
$deviceToken = new DeviceToken();
$deviceToken->setUser($user);
$now = new \DateTime();
$deviceToken->setFirstSeen($now);
$deviceToken->setLastSeen($now);
$deviceToken->setToken($token);
$deviceToken->setPlatform($platform);
return $deviceToken;
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @return User
*/
public function getUser()
{
return $this->user;
}
/**
* @param mixed $user
*/
public function setUser($user): void
{
$this->user = $user;
}
/**
* @return mixed
*/
public function getPlatform()
{
return $this->platform;
}
/**
* @param mixed $platform
*/
public function setPlatform($platform): void
{
$this->platform = $platform;
}
/**
* @return string
*/
public function getType(): string
{
return $this->type;
}
/**
* @param string $type
*/
public function setType(string $type): void
{
$this->type = $type;
}
/**
* @return mixed
*/
public function getToken()
{
return $this->token;
}
/**
* @param mixed $token
*/
public function setToken($token): void
{
$this->token = $token;
}
/**
* @return mixed
*/
public function getFirstSeen()
{
return $this->firstSeen;
}
/**
* @param mixed $firstSeen
*/
public function setFirstSeen($firstSeen): void
{
$this->firstSeen = $firstSeen;
}
/**
* @return mixed
*/
public function getLastSeen()
{
return $this->lastSeen;
}
/**
* @param mixed $lastSeen
*/
public function setLastSeen($lastSeen): void
{
$this->lastSeen = $lastSeen;
}
}