<?php
namespace App\Entity;
use App\Repository\InstanceRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=InstanceRepository::class)
* @ORM\Table(name="instance")
*/
class Instance
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $name;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $slug;
/**
* @ORM\Column(type="string", length=50)
*/
private $type;
/**
* @ORM\Column(type="string", length=255)
*/
private $baseUrl;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $parentName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $token;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $projectId;
/**
* @ORM\Column(type="string", length=20, options={"default" = "normal"})
*/
private $viewMode = 'normal';
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $displayTitle;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $displayDescription;
/**
* @ORM\Column(type="string", length=1024, nullable=true)
*/
private $googleMapUrl;
/**
* @ORM\Column(type="string", length=1024, nullable=true)
*/
private $videoUrl;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $logoPath;
/**
* @ORM\Column(type="json")
*/
private $imageSizes = [];
/**
* @ORM\Column(type="datetime_immutable")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $updatedAt;
public function __construct()
{
$now = new \DateTimeImmutable();
$this->createdAt = $now;
$this->updatedAt = $now;
$this->imageSizes = [4000, 1920, 1366, 915];
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getBaseUrl(): ?string
{
return $this->baseUrl;
}
public function setBaseUrl(string $baseUrl): self
{
$this->baseUrl = $baseUrl;
return $this;
}
public function getParentName(): ?string
{
return $this->parentName;
}
public function setParentName(?string $parentName): self
{
$this->parentName = $parentName;
return $this;
}
public function getToken(): ?string
{
return $this->token;
}
public function setToken(?string $token): self
{
$this->token = $token;
return $this;
}
public function getProjectId(): ?string
{
return $this->projectId;
}
public function setProjectId(?string $projectId): self
{
$this->projectId = $projectId;
return $this;
}
public function getViewMode(): string
{
return $this->viewMode ?: 'normal';
}
public function setViewMode(string $viewMode): self
{
if ($viewMode !== 'floor' && $viewMode !== 'normal') {
$viewMode = 'normal';
}
$this->viewMode = $viewMode;
return $this;
}
public function getDisplayTitle(): ?string
{
return $this->displayTitle;
}
public function setDisplayTitle(?string $displayTitle): self
{
$this->displayTitle = $displayTitle;
return $this;
}
public function getDisplayDescription(): ?string
{
return $this->displayDescription;
}
public function setDisplayDescription(?string $displayDescription): self
{
$this->displayDescription = $displayDescription;
return $this;
}
public function getGoogleMapUrl(): ?string
{
return $this->googleMapUrl;
}
public function setGoogleMapUrl(?string $googleMapUrl): self
{
$this->googleMapUrl = $googleMapUrl;
return $this;
}
public function getVideoUrl(): ?string
{
return $this->videoUrl;
}
public function setVideoUrl(?string $videoUrl): self
{
$this->videoUrl = $videoUrl;
return $this;
}
public function getVideoEmbedUrl(): ?string
{
$url = trim((string) $this->videoUrl);
if ($url === '') {
return null;
}
$parts = parse_url($url);
if (!\is_array($parts)) {
return $url;
}
$host = strtolower((string) ($parts['host'] ?? ''));
$path = (string) ($parts['path'] ?? '');
$query = (string) ($parts['query'] ?? '');
$isYoutube = str_contains($host, 'youtube.com') || str_contains($host, 'youtu.be');
if (!$isYoutube) {
return $url;
}
$videoId = null;
if (str_contains($host, 'youtu.be')) {
$videoId = ltrim($path, '/');
}
if (!$videoId && str_contains($path, '/watch')) {
parse_str($query, $qs);
if (\is_array($qs) && isset($qs['v'])) {
$videoId = (string) $qs['v'];
}
}
if (!$videoId && preg_match('~^/embed/([^/?#]+)~', $path, $m)) {
$videoId = (string) $m[1];
}
if (!$videoId && preg_match('~^/shorts/([^/?#]+)~', $path, $m)) {
$videoId = (string) $m[1];
}
$videoId = $videoId ? preg_replace('~[^a-zA-Z0-9_-]~', '', $videoId) : null;
if (!$videoId) {
return $url;
}
return 'https://www.youtube-nocookie.com/embed/' . $videoId;
}
public function getLogoPath(): ?string
{
return $this->logoPath;
}
public function setLogoPath(?string $logoPath): self
{
$this->logoPath = $logoPath;
return $this;
}
public function getImageSizes(): array
{
// Sizes are fixed and not configurable from the UI
return [4000, 1920, 1366, 915];
}
public function setImageSizes(array $imageSizes): self
{
// Ignore custom input and always keep the fixed set
$this->imageSizes = [4000, 1920, 1366, 915];
return $this;
}
public function getCreatedAt(): \DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): \DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
}