src/Entity/Franchise/Media.php line 25

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Franchise;
  4. use App\Entity\Admin\MediaName;
  5. use App\Entity\Traits\ImageUrlTrait;
  6. use App\Entity\Traits\TimestampableTrait;
  7. use App\Repository\Franchise\MediaRepository;
  8. use App\Validator\Constraints\Attributes\ValidFile;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\HttpFoundation\File\File;
  11. use Symfony\Component\HttpFoundation\File\UploadedFile;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use Vich\UploaderBundle\Entity\File as EmbeddedFile;
  15. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  16. /**
  17.  * @ORM\Entity(repositoryClass=MediaRepository::class)
  18.  * @Vich\Uploadable
  19.  * @ORM\HasLifecycleCallbacks
  20.  */
  21. class Media implements MediaInterface\Serializable
  22. {
  23.     use ImageUrlTrait;
  24.     use TimestampableTrait;
  25.     /**
  26.      * @ORM\Id
  27.      * @ORM\GeneratedValue
  28.      * @ORM\Column(type="integer")
  29.      */
  30.     private $id;
  31.     #[Groups(['get:franchise'])]
  32.     private ?string $format null;
  33.     #[Groups(['get:franchise'])]
  34.     private ?string $typeFile null;
  35.     /**
  36.      * @ORM\Embedded(class="Vich\UploaderBundle\Entity\File")
  37.      *
  38.      * @var EmbeddedFile
  39.      */
  40.     private $url;
  41.     /**
  42.      * @Vich\UploadableField(mapping="medias_images", fileNameProperty="url.name", size="url.size", mimeType="url.mimeType", originalName="url.originalName", dimensions="url.dimensions")
  43.      * @ValidFile(fileType="image")
  44.      *
  45.      * @var null|File
  46.      */
  47.     private $mediaFile;
  48.     /**
  49.      * @Vich\UploadableField(mapping="medias_images", fileNameProperty="url.name", size="url.size", mimeType="url.mimeType", originalName="url.originalName", dimensions="url.dimensions")
  50.      * @Assert\File(
  51.      *     mimeTypes={"video/*"},
  52.      *     mimeTypesMessage="file.mime_types_video.message",
  53.      *     maxSize="5M",
  54.      *     maxSizeMessage="file.max_size.message"
  55.      * )
  56.      *
  57.      * @var null|File
  58.      */
  59.     private $videoFile;
  60.     /**
  61.      * @ORM\ManyToOne(targetEntity=Franchise::class, inversedBy="media")
  62.      * @ORM\JoinColumn(nullable=false)
  63.      */
  64.     private $franchise;
  65.     /**
  66.      * @ORM\ManyToOne(targetEntity=MediaName::class, inversedBy="medias")
  67.      * @ORM\JoinColumn(nullable=false)
  68.      */
  69.     private $mediaName;
  70.     #[Groups(['get:franchise'])]
  71.     private $code;
  72.     /**
  73.      * @ORM\Column(type="string", length=255, nullable=true)
  74.      */
  75.     #[Groups(['get:franchise''fixtures:franchise'])]
  76.     private $type;
  77.     private $fileType;
  78.     /**
  79.      * @ORM\Column(type="boolean", options={"default": true })
  80.      */
  81.     #[Groups(['get:franchise'])]
  82.     private $displayOnMenuSection true;
  83.     public function __construct()
  84.     {
  85.         $this->url = new EmbeddedFile();
  86.     }
  87.     public function getId(): ?int
  88.     {
  89.         return $this->id;
  90.     }
  91.     public function getUrl(): ?EmbeddedFile
  92.     {
  93.         return $this->url;
  94.     }
  95.     public function setUrl(?EmbeddedFile $url): void
  96.     {
  97.         $this->url $url;
  98.     }
  99.     /**
  100.      * @param null|File|UploadedFile $image
  101.      */
  102.     public function setMediaFile(File $image null): void
  103.     {
  104.         $this->mediaFile $image;
  105.         if ($image) {
  106.             $this->updatedAt = new \DateTime('now');
  107.         }
  108.     }
  109.     public function getMediaFile(): ?File
  110.     {
  111.         return $this->mediaFile;
  112.     }
  113.     /**
  114.      * @param null|File|UploadedFile $video
  115.      */
  116.     public function setVideoFile(File $video null): void
  117.     {
  118.         $this->videoFile $video;
  119.         if ($video) {
  120.             $this->updatedAt = new \DateTime('now');
  121.         }
  122.     }
  123.     public function getVideoFile(): ?File
  124.     {
  125.         return $this->videoFile;
  126.     }
  127.     public function getFranchise(): ?Franchise
  128.     {
  129.         return $this->franchise;
  130.     }
  131.     public function setFranchise(?Franchise $franchise): self
  132.     {
  133.         $this->franchise $franchise;
  134.         return $this;
  135.     }
  136.     public function getMediaName(): ?MediaName
  137.     {
  138.         return $this->mediaName;
  139.     }
  140.     public function setMediaName(?MediaName $mediaName): self
  141.     {
  142.         $this->mediaName $mediaName;
  143.         return $this;
  144.     }
  145.     public function getCode(): ?string
  146.     {
  147.         return $this->code;
  148.     }
  149.     public function setCode(?string $code): self
  150.     {
  151.         $this->code $code;
  152.         return $this;
  153.     }
  154.     public function setFormat(?string $format): self
  155.     {
  156.         $this->format $format;
  157.         return $this;
  158.     }
  159.     public function getFormat(): ?string
  160.     {
  161.         return $this->format;
  162.     }
  163.     public function setTypeFile(?string $typeFile): self
  164.     {
  165.         $this->typeFile $typeFile;
  166.         return $this;
  167.     }
  168.     public function getTypeFile(): ?string
  169.     {
  170.         return $this->typeFile;
  171.     }
  172.     public function getType(): ?string
  173.     {
  174.         return $this->type;
  175.     }
  176.     public function setType(?string $type): self
  177.     {
  178.         $this->type $type;
  179.         return $this;
  180.     }
  181.     public function getFileType(): ?string
  182.     {
  183.         return $this->fileType;
  184.     }
  185.     public function setFileType(?string $fileType): self
  186.     {
  187.         $this->fileType $fileType;
  188.         return $this;
  189.     }
  190.     /**
  191.      * Serialize.
  192.      *
  193.      * @throws \Exception
  194.      */
  195.     public function serialize(): string
  196.     {
  197.         return serialize([$this->id]);
  198.     }
  199.     /**
  200.      * Unserialize.
  201.      *
  202.      * @throws \Exception
  203.      */
  204.     public function unserialize(string $serialized): void
  205.     {
  206.         [$this->id] = unserialize($serialized);
  207.     }
  208.     public function isDisplayOnMenuSection(): bool
  209.     {
  210.         return $this->displayOnMenuSection;
  211.     }
  212.     public function setDisplayOnMenuSection(bool $displayOnMenuSection): self
  213.     {
  214.         $this->displayOnMenuSection $displayOnMenuSection;
  215.         return $this;
  216.     }
  217. }