src/Entity/Media.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiProperty;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Controller\CreateMediaObjectAction;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Symfony\Component\HttpFoundation\File\File;
  11. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  12. /**
  13.  * @ORM\Entity(repositoryClass="App\Repository\MediaRepository")
  14.  * @Vich\Uploadable
  15.  */
  16. class Media
  17. {
  18.     /**
  19.      * @ORM\Id()
  20.      * @ORM\GeneratedValue()
  21.      * @ORM\Column(type="integer")
  22.      */
  23.     public $id;
  24.     /**
  25.      * @var File|null
  26.      *
  27.      * @Assert\NotNull(groups={"media_object_create"})
  28.      * @Vich\UploadableField(mapping="media_object", fileNameProperty="path")
  29.      */
  30.     public $mediaFile;
  31.     /**
  32.      * @var string|null
  33.      *
  34.      * @ORM\Column(type="string", length=2048, nullable=true)
  35.      */
  36.     public $path;
  37.     /**
  38.      * @ApiProperty(iri="http://schema.org/contentUrl")
  39.      */
  40.     public $url;
  41.     /**
  42.      * @ORM\Column(type="string", length=50, options={"comment":"IMAGE ou VIDEO"})
  43.      */
  44.     private $mediaType;
  45.     /**
  46.      * @ORM\Column(type="string", length=255)
  47.      */
  48.     public $title;
  49.     /**
  50.      * @ORM\Column(type="json", nullable=true)
  51.      */
  52.     private $titleTranslations;
  53.     /**
  54.      * @ORM\Column(type="string", length=2048, nullable=true)
  55.      */
  56.     private $description;
  57.     /**
  58.      * @ORM\Column(type="json", nullable=true)
  59.      */
  60.     private $descriptionTranslations;
  61.     /**
  62.      * @ORM\Column(type="string", length=2048, nullable=true)
  63.      */
  64.     private ?string $credits;
  65.     /**
  66.      * @ORM\Column(type="json", nullable=true)
  67.      */
  68.     private ?array $creditsTranslations;
  69.     /**
  70.      * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="medias")
  71.      * @ORM\JoinColumns({
  72.      *   @ORM\JoinColumn(name="owner_id", referencedColumnName="id")
  73.      * })
  74.      */
  75.     private $owner;
  76.     /**
  77.      * @ORM\ManyToOne(targetEntity="App\Entity\DnsitEntity", inversedBy="medias")
  78.      * @ORM\JoinColumns({
  79.      *   @ORM\JoinColumn(name="entity_id", referencedColumnName="id")
  80.      * })
  81.      */
  82.     private $entity;
  83.     /**
  84.      * @ORM\Column(type="datetime", nullable=true)
  85.      */
  86.     private $createdAt;
  87.     /**
  88.      * @ORM\Column(type="datetime", nullable=true)
  89.      */
  90.     private $updatedAt;
  91.     /**
  92.      * @ORM\Column(type="integer", nullable=true, options={"default":0, "comment":"code de statut : 0=OK"})
  93.      */
  94.     private $state;
  95.     /**
  96.      * @ORM\ManyToMany(targetEntity="App\Entity\TagMedia", inversedBy="medias")
  97.      */
  98.     private $mediaTags;
  99.     /**
  100.      * @var \Doctrine\Common\Collections\Collection
  101.      *
  102.      * @ORM\OneToMany(targetEntity="App\Entity\BlockFieldItem", mappedBy="image", cascade={"persist"})
  103.      */
  104.     private $blockFields;
  105.     /**
  106.      * @var \Doctrine\Common\Collections\Collection
  107.      *
  108.      * @ORM\OneToMany(targetEntity="App\Entity\WebFilterItem", mappedBy="image", cascade={"persist"})
  109.      */
  110.     private $filterItems;
  111.     /**
  112.      * @var \Doctrine\Common\Collections\Collection
  113.      *
  114.      * @ORM\OneToMany(targetEntity="App\Entity\WebList", mappedBy="image", cascade={"persist"})
  115.      */
  116.     private $weblists;
  117.     /**
  118.      * @var \Doctrine\Common\Collections\Collection
  119.      *
  120.      * @ORM\OneToMany(targetEntity="App\Entity\EditionLegendeItem", mappedBy="media", cascade={"remove"})
  121.      */
  122.     private $editionLegendeItems;
  123.     /**
  124.      * @var \Doctrine\Common\Collections\Collection
  125.      *
  126.      * @ORM\OneToMany(targetEntity="App\Entity\WebMapItem", mappedBy="legendMedia", cascade={"remove"})
  127.      */
  128.     private $webMapItemsLegend;
  129.     /**
  130.      * @var \Doctrine\Common\Collections\Collection
  131.      *
  132.      * @ORM\OneToMany(targetEntity="App\Entity\WebMapItem", mappedBy="mapMedia", cascade={"remove"})
  133.      */
  134.     private $webMapItemsMap;
  135.     /**
  136.      * Media constructor.
  137.      */
  138.     public function __construct()
  139.     {
  140.         $this->blockFields = new ArrayCollection();
  141.         $this->filterItems = new ArrayCollection();
  142.         $this->weblists = new ArrayCollection();
  143.         $this->mediaTags = new ArrayCollection();
  144.         $this->editionLegendeItems = new ArrayCollection();
  145.         $this->webMapItemsLegend = new ArrayCollection();
  146.         $this->webMapItemsMap = new ArrayCollection();
  147.     }
  148.     /**
  149.      * @return int|null
  150.      */
  151.     public function getId(): ?int
  152.     {
  153.         return $this->id;
  154.     }
  155.     /**
  156.      * @return File|null
  157.      */
  158.     public function getMediaFile(): ?File
  159.     {
  160.         return $this->mediaFile;
  161.     }
  162.     /**
  163.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  164.      * of 'UploadedFile' is injected into this setter to trigger the update. If this
  165.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  166.      * must be able to accept an instance of 'File' as the bundle will inject one here
  167.      * during Doctrine hydration.
  168.      *
  169.      * @param File|null $mediaFile
  170.      * @throws \Exception
  171.      */
  172.     public function setMediaFile(?File $mediaFile null): self
  173.     {
  174.         $this->mediaFile $mediaFile;
  175.         if (null !== $mediaFile) {
  176.             // It is required that at least one field changes if you are using doctrine
  177.             // otherwise the event listeners won't be called and the file is lost
  178.             $this->createdAt = new \DateTimeImmutable();
  179.         }
  180.         return $this;
  181.     }
  182.     /**
  183.      * @return string|null
  184.      */
  185.     public function getPath(): ?string
  186.     {
  187.         return $this->path;
  188.     }
  189.     /**
  190.      * @param string $path
  191.      * @return Media
  192.      */
  193.     public function setPath(?string $path): self
  194.     {
  195.         $this->path $path;
  196.         return $this;
  197.     }
  198.     /**
  199.      * @return string|null
  200.      */
  201.     public function getUrl(): ?string
  202.     {
  203.         return $this->url;
  204.     }
  205.     /**
  206.      * @param string $url
  207.      * @return Media
  208.      */
  209.     public function setUrl(?string $url): self
  210.     {
  211.         $this->url $url;
  212.         return $this;
  213.     }
  214.     /**
  215.      * @return string|null
  216.      */
  217.     public function getMediaType(): ?string
  218.     {
  219.         return $this->mediaType;
  220.     }
  221.     /**
  222.      * @param string $mediaType
  223.      * @return Media
  224.      */
  225.     public function setMediaType(string $mediaType): self
  226.     {
  227.         $this->mediaType $mediaType;
  228.         return $this;
  229.     }
  230.     /**
  231.      * @return string|null
  232.      */
  233.     public function getTitle(): ?string
  234.     {
  235.         return $this->title;
  236.     }
  237.     /**
  238.      * @param string $title
  239.      * @return Media
  240.      */
  241.     public function setTitle(string $title): self
  242.     {
  243.         $this->title $title;
  244.         return $this;
  245.     }
  246.     public function getTitleTranslations(): ?array
  247.     {
  248.         return $this->titleTranslations;
  249.     }
  250.     public function setTitleTranslations(?array $titleTranslations): self
  251.     {
  252.         $this->titleTranslations $titleTranslations;
  253.         return $this;
  254.     }
  255.     /**
  256.      * @return string|null
  257.      */
  258.     public function getDescription(): ?string
  259.     {
  260.         return $this->description;
  261.     }
  262.     /**
  263.      * @param string $description
  264.      * @return Media
  265.      */
  266.     public function setDescription(string $description): self
  267.     {
  268.         $this->description $description;
  269.         return $this;
  270.     }
  271.     public function getDescriptionTranslations(): ?array
  272.     {
  273.         return $this->descriptionTranslations;
  274.     }
  275.     public function setDescriptionTranslations(?array $descriptionTranslations): self
  276.     {
  277.         $this->descriptionTranslations $descriptionTranslations;
  278.         return $this;
  279.     }
  280.     /**
  281.      * @return string|null
  282.      */
  283.     public function getCredits(): ?string
  284.     {
  285.         return $this->credits;
  286.     }
  287.     /**
  288.      * @param string|null $credits
  289.      * @return Media
  290.      */
  291.     public function setCredits(?string $credits): self
  292.     {
  293.         $this->credits $credits;
  294.         return $this;
  295.     }
  296.     /**
  297.      * @return array|null
  298.      */
  299.     public function getCreditsTranslations(): ?array
  300.     {
  301.         return $this->creditsTranslations;
  302.     }
  303.     /**
  304.      * @param array|null $creditsTranslations
  305.      * @return Media
  306.      */
  307.     public function setCreditsTranslations(?array $creditsTranslations): self
  308.     {
  309.         $this->creditsTranslations $creditsTranslations;
  310.         return $this;
  311.     }
  312.     /**
  313.      * @return mixed
  314.      */
  315.     public function getOwner()
  316.     {
  317.         return $this->owner;
  318.     }
  319.     /**
  320.      * @param mixed $owner
  321.      */
  322.     public function setOwner($owner): void
  323.     {
  324.         $this->owner $owner;
  325.     }
  326.     /**
  327.      * @return mixed
  328.      */
  329.     public function getEntity()
  330.     {
  331.         return $this->entity;
  332.     }
  333.     /**
  334.      * @param mixed $entity
  335.      */
  336.     public function setEntity($entity): void
  337.     {
  338.         $this->entity $entity;
  339.     }
  340.     /**
  341.      * @return mixed
  342.      */
  343.     public function getCreatedAt()
  344.     {
  345.         return $this->createdAt;
  346.     }
  347.     /**
  348.      * @param mixed $createdAt
  349.      */
  350.     public function setCreatedAt($createdAt): void
  351.     {
  352.         $this->createdAt $createdAt;
  353.     }
  354.     /**
  355.      * @return mixed
  356.      */
  357.     public function getUpdatedAt()
  358.     {
  359.         return $this->updatedAt;
  360.     }
  361.     /**
  362.      * @param mixed $updatedAt
  363.      */
  364.     public function setUpdatedAt($updatedAt): void
  365.     {
  366.         $this->updatedAt $updatedAt;
  367.     }
  368.     /**
  369.      * @return mixed
  370.      */
  371.     public function getState()
  372.     {
  373.         return $this->state;
  374.     }
  375.     /**
  376.      * @param mixed $state
  377.      */
  378.     public function setState($state): void
  379.     {
  380.         $this->state $state;
  381.     }
  382.     /**
  383.      * @return Collection|BlockFieldItem[]
  384.      */
  385.     public function getBlockFields(): Collection
  386.     {
  387.         return $this->blockFields;
  388.     }
  389.     public function addBlockField(BlockFieldItem $blockField): self
  390.     {
  391.         if (!$this->blockFields->contains($blockField)) {
  392.             $this->blockFields[] = $blockField;
  393.             $blockField->setImage($this);
  394.         }
  395.         return $this;
  396.     }
  397.     public function removeBlockField(BlockFieldItem $blockField): self
  398.     {
  399.         if ($this->blockFields->contains($blockField)) {
  400.             $this->blockFields->removeElement($blockField);
  401.             // set the owning side to null (unless already changed)
  402.             if ($blockField->getImage() === $this) {
  403.                 $blockField->setImage(null);
  404.             }
  405.         }
  406.         return $this;
  407.     }
  408.     /**
  409.      * @return Collection|WebFilterItem[]
  410.      */
  411.     public function getFilterItems(): Collection
  412.     {
  413.         return $this->filterItems;
  414.     }
  415.     public function addFilterItem(WebFilterItem $filterItem): self
  416.     {
  417.         if (!$this->filterItems->contains($filterItem)) {
  418.             $this->filterItems[] = $filterItem;
  419.             $filterItem->setImage($this);
  420.         }
  421.         return $this;
  422.     }
  423.     public function removeFilterItem(WebFilterItem $filterItem): self
  424.     {
  425.         if ($this->filterItems->contains($filterItem)) {
  426.             $this->filterItems->removeElement($filterItem);
  427.             // set the owning side to null (unless already changed)
  428.             if ($filterItem->getImage() === $this) {
  429.                 $filterItem->setImage(null);
  430.             }
  431.         }
  432.         return $this;
  433.     }
  434.     /**
  435.      * @return Collection|WebList[]
  436.      */
  437.     public function getWeblists(): Collection
  438.     {
  439.         return $this->weblists;
  440.     }
  441.     public function addWeblist(WebList $weblist): self
  442.     {
  443.         if (!$this->weblists->contains($weblist)) {
  444.             $this->weblists[] = $weblist;
  445.             $weblist->setImage($this);
  446.         }
  447.         return $this;
  448.     }
  449.     public function removeWeblist(WebList $weblist): self
  450.     {
  451.         if ($this->weblists->contains($weblist)) {
  452.             $this->weblists->removeElement($weblist);
  453.             // set the owning side to null (unless already changed)
  454.             if ($weblist->getImage() === $this) {
  455.                 $weblist->setImage(null);
  456.             }
  457.         }
  458.         return $this;
  459.     }
  460.     /**
  461.      * @return Collection|TagMedia[]
  462.      */
  463.     public function getMediaTags(): Collection
  464.     {
  465.         return $this->mediaTags;
  466.     }
  467.     public function addMediaTag(TagMedia $tagMedia): self
  468.     {
  469.         if (!$this->mediaTags->contains($tagMedia)) {
  470.             $this->mediaTags[] = $tagMedia;
  471.         }
  472.         return $this;
  473.     }
  474.     public function removeMediaTag(TagMedia $tagMedia): self
  475.     {
  476.         if ($this->mediaTags->contains($tagMedia)) {
  477.             $this->mediaTags->removeElement($tagMedia);
  478.         }
  479.         return $this;
  480.     }
  481.     /**
  482.      * @return Collection|EditionLegendeItem[]
  483.      */
  484.     public function getEditionLegendeItems(): Collection
  485.     {
  486.         return $this->editionLegendeItems;
  487.     }
  488.     public function addEditionLegendeItem(EditionLegendeItem $editionLegendeItem): self
  489.     {
  490.         if (!$this->editionLegendeItems->contains($editionLegendeItem)) {
  491.             $this->editionLegendeItems[] = $editionLegendeItem;
  492.             $editionLegendeItem->setMedia($this);
  493.         }
  494.         return $this;
  495.     }
  496.     public function removeEditionLegendeItem(EditionLegendeItem $editionLegendeItem): self
  497.     {
  498.         if ($this->editionLegendeItems->contains($editionLegendeItem)) {
  499.             $this->editionLegendeItems->removeElement($editionLegendeItem);
  500.             // set the owning side to null (unless already changed)
  501.             if ($editionLegendeItem->getMedia() === $this) {
  502.                 $editionLegendeItem->setMedia(null);
  503.             }
  504.         }
  505.         return $this;
  506.     }
  507.     /**
  508.      * @return Collection|WebMapItem[]
  509.      */
  510.     public function getWebMapItemsLegend(): Collection
  511.     {
  512.         return $this->webMapItemsLegend;
  513.     }
  514.     public function addWebMapItemLegend(WebMapItem $webMapItemLegend): self
  515.     {
  516.         if (!$this->webMapItemsLegend->contains($webMapItemLegend)) {
  517.             $this->webMapItemsLegend[] = $webMapItemLegend;
  518.             $webMapItemLegend->setMedia($this);
  519.         }
  520.         return $this;
  521.     }
  522.     public function removeWebMapItemLegend(WebMapItem $webMapItemLegend): self
  523.     {
  524.         if ($this->webMapItemsLegend->contains($webMapItemLegend)) {
  525.             $this->webMapItemsLegend->removeElement($webMapItemLegend);
  526.             // set the owning side to null (unless already changed)
  527.             if ($webMapItemLegend->getMedia() === $this) {
  528.                 $webMapItemLegend->setMedia(null);
  529.             }
  530.         }
  531.         return $this;
  532.     }
  533.         /**
  534.      * @return Collection|WebMapItem[]
  535.      */
  536.     public function getWebMapItemsMap(): Collection
  537.     {
  538.         return $this->webMapItemsMap;
  539.     }
  540.     public function addWebMapItemMap(WebMapItem $webMapItem): self
  541.     {
  542.         if (!$this->webMapItemsMap->contains($webMapItem)) {
  543.             $this->webMapItemsMap[] = $webMapItem;
  544.             $webMapItem->setMedia($this);
  545.         }
  546.         return $this;
  547.     }
  548.     public function removeWebMapItemMap(WebMapItem $webMapItem): self
  549.     {
  550.         if ($this->webMapItemsMap->contains($webMapItem)) {
  551.             $this->webMapItemsMap->removeElement($webMapItem);
  552.             // set the owning side to null (unless already changed)
  553.             if ($webMapItem->getMedia() === $this) {
  554.                 $webMapItem->setMedia(null);
  555.             }
  556.         }
  557.         return $this;
  558.     }
  559.     /*public function addTagsMedium(TagMedia $tagsMedium): self
  560.     {
  561.         if (!$this->tagsMedia->contains($tagsMedium)) {
  562.             $this->tagsMedia[] = $tagsMedium;
  563.         }
  564.         return $this;
  565.     }
  566.     public function removeTagsMedium(TagMedia $tagsMedium): self
  567.     {
  568.         if ($this->tagsMedia->contains($tagsMedium)) {
  569.             $this->tagsMedia->removeElement($tagsMedium);
  570.         }
  571.         return $this;
  572.     }*/
  573.     /*public function __toString()
  574.     {
  575.         return (string) $this->getBlockFields();
  576.     }*/
  577. }