<?php
declare(strict_types=1);
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
class Media {
/**
* @var integer
*/
private $id;
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $copyright;
/**
* @var string
*/
private $providerName;
/**
* @var string
*/
private $providerReference;
/**
* @var array<string, mixed>
*/
private $providerMetadata;
/**
* @var string
*/
private $contentType;
/**
* @var string
*/
private $context;
/**
* @var \DateTime
*/
private $updatedAt;
/**
* @var \DateTime
*/
private $createdAt;
/**
* @var integer
*/
private $ownerID;
/**
* @var integer
*/
private $documentType;
/**
* @var mixed
*/
private $binaryContent;
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $galleryHasMedias;
/**
* Constructor
*/
public function __construct() {
$this->galleryHasMedias = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId() {
return $this->id;
}
/**
* Set ownerID
*
* @param integer $ownerID
*
* @return Media
*/
public function setOwnerID($ownerID) {
$this->ownerID = $ownerID;
return $this;
}
/**
* Get ownerID
*
* @return integer
*/
public function getOwnerID() {
return $this->ownerID;
}
/**
* Set documentType
*
* @param integer $documentType
*
* @return Media
*/
public function setDocumentType($documentType) {
$this->documentType = $documentType;
return $this;
}
/**
* Get documentType
*
* @return integer
*/
public function getDocumentType() {
return $this->documentType;
}
public function getName() {
return $this->name;
}
public function setName($name) {
$this->name = $name;
return $this;
}
public function getCopyright() {
return $this->copyright;
}
public function setCopyright($copyright) {
$this->copyright = $copyright;
}
public function getProviderName() {
return $this->providerName;
}
public function setProviderName($providerName) {
$this->providerName = $providerName;
return $this;
}
public function getProviderReference() {
return $this->providerReference;
}
public function setProviderReference($providerReference) {
$this->providerReference = $providerReference;
return $this;
}
public function getProviderMetadata() {
return $this->providerMetadata;
}
public function setProviderMetadata($providerMetadata) {
$this->providerMetadata = $providerMetadata;
return $this;
}
public function getContentType() {
return $this->contentType;
}
public function setContentType($contentType) {
$this->contentType = $contentType;
return $this;
}
public function getContext() {
return $this->context;
}
public function setContext($context) {
$this->context = $context;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface {
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt) {
$this->updatedAt = $updatedAt;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface {
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt) {
$this->createdAt = $createdAt;
return $this;
}
/**
* Add galleryHasMedia
*
* @param \App\Entity\GalleryHasMedia $galleryHasMedia
*
* @return Media
*/
public function addGalleryHasMedia(\App\Entity\GalleryHasMedia $galleryHasMedia) {
$this->galleryHasMedias[] = $galleryHasMedia;
return $this;
}
/**
* Remove galleryHasMedia
*
* @param \App\Entity\GalleryHasMedia $galleryHasMedia
*/
public function removeGalleryHasMedia(\App\Entity\GalleryHasMedia $galleryHasMedia) {
$this->galleryHasMedias->removeElement($galleryHasMedia);
}
/**
* Get galleryHasMedias
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getGalleryItems(): Collection {
return $this->galleryHasMedias;
}
public function setBinaryContent($binaryContent): void {
$this->previousProviderReference = $this->providerReference;
$this->providerReference = null;
$this->binaryContent = $binaryContent;
}
public function resetBinaryContent(): void {
$this->binaryContent = null;
}
public function getBinaryContent() {
return $this->binaryContent;
}
public function prePersist() {
$this->createdAt = new \DateTime();
$this->updatedAt = new \DateTime();
}
public function preUpdate() {
$this->updatedAt = new \DateTime();
}
public function isProviderYoutube() {
if (empty($this->providerName)) {
return false;
}
if (empty($this->providerReference)) {
return false;
}
if (strcasecmp($this->providerName, "media.provider.youtube") != 0) {
return false;
}
return true;
}
public function getYoutubeUrl() {
// for example https://youtube.com/shorts
if (strlen($this->providerReference) >= 20) {
return $this->providerReference;
}
return "https://www.youtube.com/watch?v=" . $this->providerReference;
}
public function isTypeVideo() {
if (empty($this->contentType)) {
return false;
}
if (strcasecmp($this->contentType, "video/x-flv") != 0) {
return false;
}
return true;
}
public function isPDF() {
if (empty($this->name)) {
return false;
}
$nameLower = strtolower($this->name);
if (strpos($nameLower, '.pdf') == false) {
return false;
}
return true;
}
public function __toString(): string {
return $this->getName() ?? 'n/a';
}
}