<?php
namespace Sq\Entity\Schema\ORM;
use Doctrine\ORM\Mapping as ORM;
/**
* AndroidApp.
*/
#[ORM\Entity]
#[ORM\Table(name: 'android_app')]
#[ORM\UniqueConstraint(name: 'unique_android', columns: ['android_m_id', 'android_app_uuid'])]
class AndroidApp implements MobileAppInterface
{
/**
* @var int
*/
#[ORM\Column(name: 'android_id', type: 'integer', nullable: false, options: ['unsigned' => true])]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'IDENTITY')]
private $id;
/**
* @var Member|null
*/
#[ORM\ManyToOne(targetEntity: Member::class, inversedBy: 'androidApps')]
#[ORM\JoinColumn(name: 'android_m_id', referencedColumnName: 'm_id', nullable: true)]
private $member;
/**
*
* @var Organization|null
*
* @deprecated To be removed.
*/
#[ORM\Column(name: 'android_o_id', type: 'integer', nullable: true)]
private $deprecatedOrganization;
/**
*
* @var User|null
*/
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'androidApps')]
#[ORM\JoinColumn(name: 'android_u_id', referencedColumnName: 'u_id', nullable: true)]
private $user;
/**
* @var string|null
*/
#[ORM\Column(name: 'android_firebase_token', type: 'string', length: 255, nullable: true)]
private $firebaseToken;
/**
* @var string|null
*/
#[ORM\Column(name: 'android_app_uuid', type: 'string', length: 36, nullable: true)]
private $uuid;
/**
* @var int
*/
#[ORM\Column(name: 'android_app_version_code', type: 'integer', nullable: false, options: ['unsigned' => true])]
private $versionCode;
/**
* @var \DateTimeInterface|null
*/
#[ORM\Column(name: 'android_token_first_added', type: 'datetime', nullable: true, options: ['default' => '0000-00-00 00:00:00'])]
private $firstConnectedTime;
/**
* @var \DateTimeInterface|null
*/
#[ORM\Column(name: 'android_token_last_updated', type: 'datetime', nullable: true, options: ['default' => '0000-00-00 00:00:00'])]
private $lastConnectedTime;
/**
* @var string|null
*/
#[ORM\Column(name: 'android_device_type', type: 'string', length: 191, nullable: true)]
private $deviceType;
/**
* @var string|null
*/
#[ORM\Column(name: 'android_device_name', type: 'string', length: 191, nullable: true)]
private $deviceName;
public function __construct(
User $user,
string $firebaseToken,
string $uuid,
int $buildCode,
?string $deviceType = null,
?string $deviceName = null,
) {
$this->user = $user;
$this->firebaseToken = $firebaseToken;
$this->uuid = $uuid;
$this->versionCode = $buildCode;
$this->deviceType = $deviceType;
$this->deviceName = $deviceName;
$this->firstConnectedTime = new \DateTime();
$this->lastConnectedTime = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getMember(): ?Member
{
return $this->member;
}
public function getUser(): User
{
return $this->user;
}
public function getFirebaseToken(): ?string
{
return $this->firebaseToken;
}
public function updateFirebaseToken(?string $token): static
{
$this->firebaseToken = $token;
$this->lastConnectedTime = new \DateTime();
return $this;
}
public function getUuid(): string
{
return $this->uuid;
}
public function getBuildNumber(): int
{
return $this->versionCode;
}
public function updateBuildNumber(int $buildNumber): static
{
$this->versionCode = $buildNumber;
return $this;
}
public function getFirstConnectedTime(): \DateTimeInterface
{
return $this->firstConnectedTime;
}
public function getLastConnectedTime(): \DateTimeInterface
{
return $this->lastConnectedTime;
}
public function isVideoCarouselSupported(): bool
{
global $arr_config;
return $this->versionCode >= $arr_config['android_video_carousel_min_build'] && $this->isConnected();
}
/**
* Check if they have a valid connected app (with notifications still working), and the app is recent enough to support Generic Profiles.
*
* @return bool
*/
public function isGenericProfileSupported(): bool
{
return false; // TODO-GENERIC_PROFILES - once we have an Android app that supports Generic Profiles, update this function AND the build number in config
global $arr_config;
return $this->versionCode >= $arr_config['android_generic_profiles_min_build'] && $this->isConnected();
}
public function getDeviceType(): ?string
{
return $this->deviceType;
}
public function getDeviceName(): ?string
{
return $this->deviceName;
}
public function updateDeviceName(string $deviceName): static
{
$this->deviceName = $deviceName;
return $this;
}
public function isConnected(): bool
{
return $this->firebaseToken !== null;
}
}