src/Entity/Media.php line 10

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\Common\Collections\Collection;
  6. class Media {
  7.     /**
  8.      * @var int
  9.      */
  10.     private $id;
  11.     /**
  12.      * @var string
  13.      */
  14.     private $name;
  15.     /**
  16.      * @var string|null
  17.      */
  18.     private $altText;
  19.     
  20.     /**
  21.      * @var string
  22.      */
  23.     private $copyright;
  24.     /**
  25.      * @var string
  26.      */
  27.     private $providerName;
  28.     /**
  29.      * @var string
  30.      */
  31.     private $providerReference;
  32.     /**
  33.      * @var array<string, mixed>
  34.      */
  35.     private $providerMetadata;
  36.     /**
  37.      * @var string
  38.      */
  39.     private $contentType;
  40.     /**
  41.      * @var string
  42.      */
  43.     private $context;
  44.     /**
  45.      * @var \DateTime
  46.      */
  47.     private $updatedAt;
  48.     /**
  49.      * @var \DateTime
  50.      */
  51.     private $createdAt;
  52.     /**
  53.      * @var int
  54.      */
  55.     private $ownerID;
  56.     /**
  57.      * @var int
  58.      */
  59.     private $documentType;
  60.     /**
  61.      * @var mixed
  62.      */
  63.     private $binaryContent;
  64.     /**
  65.      * @var \Doctrine\Common\Collections\Collection
  66.      */
  67.     private $galleryHasMedias;
  68.     /**
  69.      * Constructor
  70.      */
  71.     public function __construct() {
  72.         $this->galleryHasMedias = new \Doctrine\Common\Collections\ArrayCollection();
  73.     }
  74.     /**
  75.      * Get id
  76.      *
  77.      * @return integer
  78.      */
  79.     public function getId() {
  80.         return $this->id;
  81.     }
  82.     /**
  83.      * Set ownerID
  84.      *
  85.      * @param integer $ownerID
  86.      *
  87.      * @return Media
  88.      */
  89.     public function setOwnerID($ownerID) {
  90.         $this->ownerID $ownerID;
  91.         return $this;
  92.     }
  93.     /**
  94.      * Get ownerID
  95.      *
  96.      * @return integer
  97.      */
  98.     public function getOwnerID() {
  99.         return $this->ownerID;
  100.     }
  101.     /**
  102.      * Set documentType
  103.      *
  104.      * @param integer $documentType
  105.      *
  106.      * @return Media
  107.      */
  108.     public function setDocumentType($documentType) {
  109.         $this->documentType $documentType;
  110.         return $this;
  111.     }
  112.     /**
  113.      * Get documentType
  114.      *
  115.      * @return integer
  116.      */
  117.     public function getDocumentType() {
  118.         return $this->documentType;
  119.     }
  120.     public function getName() {
  121.         return $this->name;
  122.     }
  123.     public function setName($name) {
  124.         $this->name $name;
  125.         return $this;
  126.     }
  127.     public function getAltText(): ?string {
  128.         return $this->altText;
  129.     }
  130.     public function setAltText(?string $altText): void {
  131.         $this->altText $altText;
  132.     }
  133.         
  134.     public function getCopyright() {
  135.         return $this->copyright;
  136.     }
  137.     public function setCopyright($copyright) {
  138.         $this->copyright $copyright;
  139.     }
  140.     public function getProviderName() {
  141.         return $this->providerName;
  142.     }
  143.     public function setProviderName($providerName) {
  144.         $this->providerName $providerName;
  145.         return $this;
  146.     }
  147.     public function getProviderReference() {
  148.         return $this->providerReference;
  149.     }
  150.     public function setProviderReference($providerReference) {
  151.         $this->providerReference $providerReference;
  152.         return $this;
  153.     }
  154.     public function getProviderMetadata() {
  155.         return $this->providerMetadata;
  156.     }
  157.     public function setProviderMetadata($providerMetadata) {
  158.         $this->providerMetadata $providerMetadata;
  159.         return $this;
  160.     }
  161.     public function getContentType() {
  162.         return $this->contentType;
  163.     }
  164.     public function setContentType($contentType) {
  165.         $this->contentType $contentType;
  166.         return $this;
  167.     }
  168.     public function getContext() {
  169.         return $this->context;
  170.     }
  171.     public function setContext($context) {
  172.         $this->context $context;
  173.         return $this;
  174.     }
  175.     public function getUpdatedAt(): ?\DateTimeInterface {
  176.         return $this->updatedAt;
  177.     }
  178.     public function setUpdatedAt(\DateTimeInterface $updatedAt) {
  179.         $this->updatedAt $updatedAt;
  180.         return $this;
  181.     }
  182.     public function getCreatedAt(): ?\DateTimeInterface {
  183.         return $this->createdAt;
  184.     }
  185.     public function setCreatedAt(\DateTimeInterface $createdAt) {
  186.         $this->createdAt $createdAt;
  187.         return $this;
  188.     }
  189.     /**
  190.      * Add galleryHasMedia
  191.      *
  192.      * @param \App\Entity\GalleryHasMedia $galleryHasMedia
  193.      *
  194.      * @return Media
  195.      */
  196.     public function addGalleryHasMedia(\App\Entity\GalleryHasMedia $galleryHasMedia) {
  197.         $this->galleryHasMedias[] = $galleryHasMedia;
  198.         return $this;
  199.     }
  200.     /**
  201.      * Remove galleryHasMedia
  202.      *
  203.      * @param \App\Entity\GalleryHasMedia $galleryHasMedia
  204.      */
  205.     public function removeGalleryHasMedia(\App\Entity\GalleryHasMedia $galleryHasMedia) {
  206.         $this->galleryHasMedias->removeElement($galleryHasMedia);
  207.     }
  208.     /**
  209.      * Get galleryHasMedias
  210.      *
  211.      * @return \Doctrine\Common\Collections\Collection
  212.      */
  213.     public function getGalleryItems(): Collection {
  214.         return $this->galleryHasMedias;
  215.     }
  216.     public function setBinaryContent($binaryContent): void {
  217.         $this->previousProviderReference $this->providerReference;
  218.         $this->providerReference null;
  219.         $this->binaryContent $binaryContent;
  220.     }
  221.     public function resetBinaryContent(): void {
  222.         $this->binaryContent null;
  223.     }
  224.     public function getBinaryContent() {
  225.         return $this->binaryContent;
  226.     }
  227.     public function prePersist() {
  228.         $this->createdAt = new \DateTime();
  229.         $this->updatedAt = new \DateTime();
  230.     }
  231.     public function preUpdate() {
  232.         $this->updatedAt = new \DateTime();
  233.     }
  234.     public function isProviderYoutube() {
  235.         if (empty($this->providerName)) {
  236.             return false;
  237.         }
  238.         if (empty($this->providerReference)) {
  239.             return false;
  240.         }
  241.         if (strcasecmp($this->providerName"media.provider.youtube") != 0) {
  242.             return false;
  243.         }
  244.         return true;
  245.     }
  246.     public function getYoutubeUrl() {
  247.         // for example https://youtube.com/shorts
  248.         if (strlen($this->providerReference) >= 20) {
  249.             return $this->providerReference;
  250.         }
  251.         return "https://www.youtube.com/watch?v=" $this->providerReference;
  252.     }
  253.     public function isTypeVideo() {
  254.         if (empty($this->contentType)) {
  255.             return false;
  256.         }
  257.         if (strcasecmp($this->contentType"video/x-flv") != 0) {
  258.             return false;
  259.         }
  260.         return true;
  261.     }
  262.     public function isPDF() {
  263.         if (empty($this->contentType)) {
  264.             return false;
  265.         }
  266.         $lowerContentType strtolower($this->contentType);
  267.         $resultInt strcmp($lowerContentType"application/pdf");
  268.         if ($resultInt === 0) {
  269.             return true;
  270.         }
  271.         return false;
  272.     }
  273.     public function __toString(): string {
  274.         return $this->getName() ?? 'n/a';
  275.     }
  276. }