99 lines
2.1 KiB
PHP
99 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use App\Repository\LovenseConnectionRepository;
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
/**
|
|
* A platform user's paired Lovense toy(s), as reported by Lovense's pairing callback.
|
|
*/
|
|
#[ORM\Entity(repositoryClass: LovenseConnectionRepository::class)]
|
|
class LovenseConnection
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
private ?int $id = null;
|
|
|
|
/**
|
|
* The id you assigned this user when requesting their pairing QR code.
|
|
*/
|
|
#[ORM\Column(length: 64, unique: true)]
|
|
private string $uid;
|
|
|
|
/**
|
|
* Verification token Lovense includes on every callback for this uid.
|
|
*/
|
|
#[ORM\Column(length: 64)]
|
|
private string $utoken;
|
|
|
|
#[ORM\Column(type: Types::JSON)]
|
|
private array $toys = [];
|
|
|
|
#[ORM\Column(length: 20, nullable: true)]
|
|
private ?string $platform = null;
|
|
|
|
#[ORM\Column]
|
|
private \DateTimeImmutable $updatedAt;
|
|
|
|
public function __construct(string $uid, string $utoken)
|
|
{
|
|
$this->uid = $uid;
|
|
$this->utoken = $utoken;
|
|
$this->updatedAt = new \DateTimeImmutable();
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getUid(): string
|
|
{
|
|
return $this->uid;
|
|
}
|
|
|
|
public function getUtoken(): string
|
|
{
|
|
return $this->utoken;
|
|
}
|
|
|
|
public function getToys(): array
|
|
{
|
|
return $this->toys;
|
|
}
|
|
|
|
public function getPlatform(): ?string
|
|
{
|
|
return $this->platform;
|
|
}
|
|
|
|
public function getUpdatedAt(): \DateTimeImmutable
|
|
{
|
|
return $this->updatedAt;
|
|
}
|
|
|
|
public function updateFromCallback(string $utoken, array $toys, ?string $platform): static
|
|
{
|
|
$this->utoken = $utoken;
|
|
$this->toys = $toys;
|
|
$this->platform = $platform;
|
|
$this->updatedAt = new \DateTimeImmutable();
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function isOnline(): bool
|
|
{
|
|
foreach ($this->toys as $toy) {
|
|
if (1 === (int) ($toy['status'] ?? 0)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|