Files
vindn.de/frontend/src/Entity/MediaObject.php
T

125 lines
2.8 KiB
PHP

<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[ORM\Table(name: 'media_objects')]
class MediaObject
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $url = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $alt = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $rel = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $name = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $type = null;
#[ORM\Column(name: 'ref_id', type: 'string', length: 255, nullable: true)]
private ?string $refId = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $source = null;
#[ORM\Column(type: 'integer', nullable: true)]
private ?int $prio = null;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $description = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $license = null;
#[ORM\Column(name: 'ai_optimized', type: 'boolean', nullable: true)]
private ?bool $aiOptimized = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $ext = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $hash = null;
public function getId(): ?int
{
return $this->id;
}
public function getUrl(): ?string
{
return $this->url;
}
public function getAlt(): ?string
{
return $this->alt;
}
public function getName(): ?string
{
return $this->name;
}
public function getType(): ?string
{
return $this->type;
}
public function getSource(): ?string
{
return $this->source;
}
public function getDescription(): ?string
{
return $this->description;
}
public function getLicense(): ?string
{
return $this->license;
}
public function getExt(): ?string
{
return $this->ext;
}
public function getHash(): ?string
{
return $this->hash;
}
public function isImage(): bool
{
return str_starts_with($this->type ?? '', 'image/');
}
/**
* Matches the path EventRepository.saveMediaFile writes to in the Go
* importer: ./public/storage/<mediatype>/<hash><ext>.
*/
public function getStoragePath(): ?string
{
if (!$this->hash) {
return null;
}
$mediaType = strtolower((string) (strstr($this->type ?? '', '/', true) ?: 'other'));
return sprintf('/storage/%s/%s%s', $mediaType, $this->hash, $this->ext);
}
}