<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Controller\CreateMediaObjectAction;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass="App\Repository\MediaRepository")
* @Vich\Uploadable
*/
class Media
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
public $id;
/**
* @var File|null
*
* @Assert\NotNull(groups={"media_object_create"})
* @Vich\UploadableField(mapping="media_object", fileNameProperty="path")
*/
public $mediaFile;
/**
* @var string|null
*
* @ORM\Column(type="string", length=2048, nullable=true)
*/
public $path;
/**
* @ApiProperty(iri="http://schema.org/contentUrl")
*/
public $url;
/**
* @ORM\Column(type="string", length=50, options={"comment":"IMAGE ou VIDEO"})
*/
private $mediaType;
/**
* @ORM\Column(type="string", length=255)
*/
public $title;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $titleTranslations;
/**
* @ORM\Column(type="string", length=2048, nullable=true)
*/
private $description;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $descriptionTranslations;
/**
* @ORM\Column(type="string", length=2048, nullable=true)
*/
private ?string $credits;
/**
* @ORM\Column(type="json", nullable=true)
*/
private ?array $creditsTranslations;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="medias")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="owner_id", referencedColumnName="id")
* })
*/
private $owner;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\DnsitEntity", inversedBy="medias")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="entity_id", referencedColumnName="id")
* })
*/
private $entity;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @ORM\Column(type="integer", nullable=true, options={"default":0, "comment":"code de statut : 0=OK"})
*/
private $state;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\TagMedia", inversedBy="medias")
*/
private $mediaTags;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\OneToMany(targetEntity="App\Entity\BlockFieldItem", mappedBy="image", cascade={"persist"})
*/
private $blockFields;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\OneToMany(targetEntity="App\Entity\WebFilterItem", mappedBy="image", cascade={"persist"})
*/
private $filterItems;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\OneToMany(targetEntity="App\Entity\WebList", mappedBy="image", cascade={"persist"})
*/
private $weblists;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\OneToMany(targetEntity="App\Entity\EditionLegendeItem", mappedBy="media", cascade={"remove"})
*/
private $editionLegendeItems;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\OneToMany(targetEntity="App\Entity\WebMapItem", mappedBy="legendMedia", cascade={"remove"})
*/
private $webMapItemsLegend;
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\OneToMany(targetEntity="App\Entity\WebMapItem", mappedBy="mapMedia", cascade={"remove"})
*/
private $webMapItemsMap;
/**
* Media constructor.
*/
public function __construct()
{
$this->blockFields = new ArrayCollection();
$this->filterItems = new ArrayCollection();
$this->weblists = new ArrayCollection();
$this->mediaTags = new ArrayCollection();
$this->editionLegendeItems = new ArrayCollection();
$this->webMapItemsLegend = new ArrayCollection();
$this->webMapItemsMap = new ArrayCollection();
}
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @return File|null
*/
public function getMediaFile(): ?File
{
return $this->mediaFile;
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|null $mediaFile
* @throws \Exception
*/
public function setMediaFile(?File $mediaFile = null): self
{
$this->mediaFile = $mediaFile;
if (null !== $mediaFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->createdAt = new \DateTimeImmutable();
}
return $this;
}
/**
* @return string|null
*/
public function getPath(): ?string
{
return $this->path;
}
/**
* @param string $path
* @return Media
*/
public function setPath(?string $path): self
{
$this->path = $path;
return $this;
}
/**
* @return string|null
*/
public function getUrl(): ?string
{
return $this->url;
}
/**
* @param string $url
* @return Media
*/
public function setUrl(?string $url): self
{
$this->url = $url;
return $this;
}
/**
* @return string|null
*/
public function getMediaType(): ?string
{
return $this->mediaType;
}
/**
* @param string $mediaType
* @return Media
*/
public function setMediaType(string $mediaType): self
{
$this->mediaType = $mediaType;
return $this;
}
/**
* @return string|null
*/
public function getTitle(): ?string
{
return $this->title;
}
/**
* @param string $title
* @return Media
*/
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getTitleTranslations(): ?array
{
return $this->titleTranslations;
}
public function setTitleTranslations(?array $titleTranslations): self
{
$this->titleTranslations = $titleTranslations;
return $this;
}
/**
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* @param string $description
* @return Media
*/
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getDescriptionTranslations(): ?array
{
return $this->descriptionTranslations;
}
public function setDescriptionTranslations(?array $descriptionTranslations): self
{
$this->descriptionTranslations = $descriptionTranslations;
return $this;
}
/**
* @return string|null
*/
public function getCredits(): ?string
{
return $this->credits;
}
/**
* @param string|null $credits
* @return Media
*/
public function setCredits(?string $credits): self
{
$this->credits = $credits;
return $this;
}
/**
* @return array|null
*/
public function getCreditsTranslations(): ?array
{
return $this->creditsTranslations;
}
/**
* @param array|null $creditsTranslations
* @return Media
*/
public function setCreditsTranslations(?array $creditsTranslations): self
{
$this->creditsTranslations = $creditsTranslations;
return $this;
}
/**
* @return mixed
*/
public function getOwner()
{
return $this->owner;
}
/**
* @param mixed $owner
*/
public function setOwner($owner): void
{
$this->owner = $owner;
}
/**
* @return mixed
*/
public function getEntity()
{
return $this->entity;
}
/**
* @param mixed $entity
*/
public function setEntity($entity): void
{
$this->entity = $entity;
}
/**
* @return mixed
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* @param mixed $createdAt
*/
public function setCreatedAt($createdAt): void
{
$this->createdAt = $createdAt;
}
/**
* @return mixed
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* @param mixed $updatedAt
*/
public function setUpdatedAt($updatedAt): void
{
$this->updatedAt = $updatedAt;
}
/**
* @return mixed
*/
public function getState()
{
return $this->state;
}
/**
* @param mixed $state
*/
public function setState($state): void
{
$this->state = $state;
}
/**
* @return Collection|BlockFieldItem[]
*/
public function getBlockFields(): Collection
{
return $this->blockFields;
}
public function addBlockField(BlockFieldItem $blockField): self
{
if (!$this->blockFields->contains($blockField)) {
$this->blockFields[] = $blockField;
$blockField->setImage($this);
}
return $this;
}
public function removeBlockField(BlockFieldItem $blockField): self
{
if ($this->blockFields->contains($blockField)) {
$this->blockFields->removeElement($blockField);
// set the owning side to null (unless already changed)
if ($blockField->getImage() === $this) {
$blockField->setImage(null);
}
}
return $this;
}
/**
* @return Collection|WebFilterItem[]
*/
public function getFilterItems(): Collection
{
return $this->filterItems;
}
public function addFilterItem(WebFilterItem $filterItem): self
{
if (!$this->filterItems->contains($filterItem)) {
$this->filterItems[] = $filterItem;
$filterItem->setImage($this);
}
return $this;
}
public function removeFilterItem(WebFilterItem $filterItem): self
{
if ($this->filterItems->contains($filterItem)) {
$this->filterItems->removeElement($filterItem);
// set the owning side to null (unless already changed)
if ($filterItem->getImage() === $this) {
$filterItem->setImage(null);
}
}
return $this;
}
/**
* @return Collection|WebList[]
*/
public function getWeblists(): Collection
{
return $this->weblists;
}
public function addWeblist(WebList $weblist): self
{
if (!$this->weblists->contains($weblist)) {
$this->weblists[] = $weblist;
$weblist->setImage($this);
}
return $this;
}
public function removeWeblist(WebList $weblist): self
{
if ($this->weblists->contains($weblist)) {
$this->weblists->removeElement($weblist);
// set the owning side to null (unless already changed)
if ($weblist->getImage() === $this) {
$weblist->setImage(null);
}
}
return $this;
}
/**
* @return Collection|TagMedia[]
*/
public function getMediaTags(): Collection
{
return $this->mediaTags;
}
public function addMediaTag(TagMedia $tagMedia): self
{
if (!$this->mediaTags->contains($tagMedia)) {
$this->mediaTags[] = $tagMedia;
}
return $this;
}
public function removeMediaTag(TagMedia $tagMedia): self
{
if ($this->mediaTags->contains($tagMedia)) {
$this->mediaTags->removeElement($tagMedia);
}
return $this;
}
/**
* @return Collection|EditionLegendeItem[]
*/
public function getEditionLegendeItems(): Collection
{
return $this->editionLegendeItems;
}
public function addEditionLegendeItem(EditionLegendeItem $editionLegendeItem): self
{
if (!$this->editionLegendeItems->contains($editionLegendeItem)) {
$this->editionLegendeItems[] = $editionLegendeItem;
$editionLegendeItem->setMedia($this);
}
return $this;
}
public function removeEditionLegendeItem(EditionLegendeItem $editionLegendeItem): self
{
if ($this->editionLegendeItems->contains($editionLegendeItem)) {
$this->editionLegendeItems->removeElement($editionLegendeItem);
// set the owning side to null (unless already changed)
if ($editionLegendeItem->getMedia() === $this) {
$editionLegendeItem->setMedia(null);
}
}
return $this;
}
/**
* @return Collection|WebMapItem[]
*/
public function getWebMapItemsLegend(): Collection
{
return $this->webMapItemsLegend;
}
public function addWebMapItemLegend(WebMapItem $webMapItemLegend): self
{
if (!$this->webMapItemsLegend->contains($webMapItemLegend)) {
$this->webMapItemsLegend[] = $webMapItemLegend;
$webMapItemLegend->setMedia($this);
}
return $this;
}
public function removeWebMapItemLegend(WebMapItem $webMapItemLegend): self
{
if ($this->webMapItemsLegend->contains($webMapItemLegend)) {
$this->webMapItemsLegend->removeElement($webMapItemLegend);
// set the owning side to null (unless already changed)
if ($webMapItemLegend->getMedia() === $this) {
$webMapItemLegend->setMedia(null);
}
}
return $this;
}
/**
* @return Collection|WebMapItem[]
*/
public function getWebMapItemsMap(): Collection
{
return $this->webMapItemsMap;
}
public function addWebMapItemMap(WebMapItem $webMapItem): self
{
if (!$this->webMapItemsMap->contains($webMapItem)) {
$this->webMapItemsMap[] = $webMapItem;
$webMapItem->setMedia($this);
}
return $this;
}
public function removeWebMapItemMap(WebMapItem $webMapItem): self
{
if ($this->webMapItemsMap->contains($webMapItem)) {
$this->webMapItemsMap->removeElement($webMapItem);
// set the owning side to null (unless already changed)
if ($webMapItem->getMedia() === $this) {
$webMapItem->setMedia(null);
}
}
return $this;
}
/*public function addTagsMedium(TagMedia $tagsMedium): self
{
if (!$this->tagsMedia->contains($tagsMedium)) {
$this->tagsMedia[] = $tagsMedium;
}
return $this;
}
public function removeTagsMedium(TagMedia $tagsMedium): self
{
if ($this->tagsMedia->contains($tagsMedium)) {
$this->tagsMedia->removeElement($tagsMedium);
}
return $this;
}*/
/*public function __toString()
{
return (string) $this->getBlockFields();
}*/
}