src/Entity/MediaObject.php line 53

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiProperty;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\GetCollection;
  7. use ApiPlatform\Metadata\Post;
  8. use App\Controller\CreateMediaObjectAction;
  9. use App\Repository\MediaObjectRepository;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\DBAL\Types\Types;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. use ApiPlatform\OpenApi\Model;
  18. use Symfony\Component\HttpFoundation\File\File;
  19. #[ORM\Entity(repositoryClassMediaObjectRepository::class)]
  20. #[ApiResource(
  21.     types: ['https://schema.org/MediaObject'],
  22.     operations: [
  23.         new Get(),
  24.         new GetCollection(),
  25.         new Post(
  26.             controllerCreateMediaObjectAction::class,
  27.             openapi: new Model\Operation(
  28.                 requestBody: new Model\RequestBody(
  29.                     content: new \ArrayObject([
  30.                         'multipart/form-data' => [
  31.                             'schema' => [
  32.                                 'type' => 'object',
  33.                                 'properties' => [
  34.                                     'file' => [
  35.                                         'type' => 'string',
  36.                                         'format' => 'binary'
  37.                                     ]
  38.                                 ]
  39.                             ]
  40.                         ]
  41.                     ])
  42.                 )
  43.             ),
  44.             validationContext: ['groups' => ['Default''media_object_create']],
  45.             deserializefalse
  46.         )
  47.     ],
  48.     normalizationContext: ['groups' => ['media_object:read']]
  49. )]
  50. class MediaObject
  51. {
  52.     #[ORM\Id]
  53.     #[ORM\GeneratedValue]
  54.     #[ORM\Column]
  55.     private ?int $id null;
  56.     #[ApiProperty(types: ['https://schema.org/contentUrl'])]
  57.     #[Groups(['media_object:read'])]
  58.     public ?string $contentUrl null;
  59.     #[Vich\UploadableField(mapping"media_object"fileNameProperty"filePath")]
  60.     #[Assert\NotNull(groups: ['media_object_create'])]
  61.     public ?File $file null;
  62.     #[ORM\Column(length255)]
  63.     #[Groups(['media_object:read''media_object_create'])]
  64.     private ?string $name '';
  65.     #[ORM\Column(typeTypes::TEXT)]
  66.     private ?string $filePath '';
  67.     #[ORM\OneToMany(mappedBy'mainImage'targetEntityCourse::class)]
  68.     private Collection $courses;
  69.     #[ORM\ManyToMany(targetEntityLesson::class, mappedBy'assets')]
  70.     private Collection $lessons;
  71.     #[ORM\OneToMany(mappedBy'video'targetEntityHealthInfoVideo::class)]
  72.     private Collection $healthInfoVideos;
  73.     #[ORM\OneToMany(mappedBy'video'targetEntityBreakRoomVideo::class)]
  74.     private Collection $breakRoomVideos;
  75.     #[ORM\OneToMany(mappedBy'icon'targetEntityBadge::class)]
  76.     private Collection $badges;
  77.     #[ORM\OneToMany(mappedBy'articulate'targetEntityLesson::class)]
  78.     private Collection $articulateLesson;
  79.     #[ORM\OneToMany(mappedBy'image'targetEntityLandingpageElement::class)]
  80.     private Collection $landingpageElements;
  81.     public function __construct()
  82.     {
  83.         $this->courses = new ArrayCollection();
  84.         $this->lessons = new ArrayCollection();
  85.         $this->healthInfoVideos = new ArrayCollection();
  86.         $this->breakRoomVideos = new ArrayCollection();
  87.         $this->badges = new ArrayCollection();
  88.         $this->filePath '';
  89.         $this->articulateLesson = new ArrayCollection();
  90.         $this->landingpageElements = new ArrayCollection();
  91.     }
  92.     public function getId(): ?int
  93.     {
  94.         return $this->id;
  95.     }
  96.     public function __toString(): string
  97.     {
  98.         return $this->name;
  99.     }
  100.     public function getName(): ?string
  101.     {
  102.         return $this->name;
  103.     }
  104.     public function setName(string $name): self
  105.     {
  106.         $this->name $name;
  107.         return $this;
  108.     }
  109.     public function getFilePath(): ?string
  110.     {
  111.         return $this->filePath;
  112.     }
  113.     public function setFilePath(?string $filePath): self
  114.     {
  115.         if (!is_null($filePath)) {
  116.             $this->filePath $filePath;
  117.         }
  118.         return $this;
  119.     }
  120.     /**
  121.      * @return Collection<int, Course>
  122.      */
  123.     public function getCourses(): Collection
  124.     {
  125.         return $this->courses;
  126.     }
  127.     public function addCourse(Course $course): self
  128.     {
  129.         if (!$this->courses->contains($course)) {
  130.             $this->courses->add($course);
  131.             $course->setMainImage($this);
  132.         }
  133.         return $this;
  134.     }
  135.     public function removeCourse(Course $course): self
  136.     {
  137.         if ($this->courses->removeElement($course)) {
  138.             // set the owning side to null (unless already changed)
  139.             if ($course->getMainImage() === $this) {
  140.                 $course->setMainImage(null);
  141.             }
  142.         }
  143.         return $this;
  144.     }
  145.     /**
  146.      * @return Collection<int, Lesson>
  147.      */
  148.     public function getLessons(): Collection
  149.     {
  150.         return $this->lessons;
  151.     }
  152.     public function addLesson(Lesson $lesson): self
  153.     {
  154.         if (!$this->lessons->contains($lesson)) {
  155.             $this->lessons->add($lesson);
  156.             $lesson->addAsset($this);
  157.         }
  158.         return $this;
  159.     }
  160.     public function removeLesson(Lesson $lesson): self
  161.     {
  162.         if ($this->lessons->removeElement($lesson)) {
  163.             $lesson->removeAsset($this);
  164.         }
  165.         return $this;
  166.     }
  167.     /**
  168.      * @return Collection<int, HealthInfoVideo>
  169.      */
  170.     public function getHealthInfoVideos(): Collection
  171.     {
  172.         return $this->healthInfoVideos;
  173.     }
  174.     public function addHealthInfoVideo(HealthInfoVideo $healthInfoVideo): self
  175.     {
  176.         if (!$this->healthInfoVideos->contains($healthInfoVideo)) {
  177.             $this->healthInfoVideos->add($healthInfoVideo);
  178.             $healthInfoVideo->setVideo($this);
  179.         }
  180.         return $this;
  181.     }
  182.     public function removeHealthInfoVideo(HealthInfoVideo $healthInfoVideo): self
  183.     {
  184.         if ($this->healthInfoVideos->removeElement($healthInfoVideo)) {
  185.             // set the owning side to null (unless already changed)
  186.             if ($healthInfoVideo->getVideo() === $this) {
  187.                 $healthInfoVideo->setVideo(null);
  188.             }
  189.         }
  190.         return $this;
  191.     }
  192.     /**
  193.      * @return Collection<int, BreakRoomVideo>
  194.      */
  195.     public function getBreakRoomVideos(): Collection
  196.     {
  197.         return $this->breakRoomVideos;
  198.     }
  199.     public function addBreakRoomVideo(BreakRoomVideo $breakRoomVideo): self
  200.     {
  201.         if (!$this->breakRoomVideos->contains($breakRoomVideo)) {
  202.             $this->breakRoomVideos->add($breakRoomVideo);
  203.             $breakRoomVideo->setVideo($this);
  204.         }
  205.         return $this;
  206.     }
  207.     public function removeBreakRoomVideo(BreakRoomVideo $breakRoomVideo): self
  208.     {
  209.         if ($this->breakRoomVideos->removeElement($breakRoomVideo)) {
  210.             // set the owning side to null (unless already changed)
  211.             if ($breakRoomVideo->getVideo() === $this) {
  212.                 $breakRoomVideo->setVideo(null);
  213.             }
  214.         }
  215.         return $this;
  216.     }
  217.     /**
  218.      * @return Collection<int, Badge>
  219.      */
  220.     public function getBadges(): Collection
  221.     {
  222.         return $this->badges;
  223.     }
  224.     public function addBadge(Badge $badge): self
  225.     {
  226.         if (!$this->badges->contains($badge)) {
  227.             $this->badges->add($badge);
  228.             $badge->setIcon($this);
  229.         }
  230.         return $this;
  231.     }
  232.     public function removeBadge(Badge $badge): self
  233.     {
  234.         if ($this->badges->removeElement($badge)) {
  235.             // set the owning side to null (unless already changed)
  236.             if ($badge->getIcon() === $this) {
  237.                 $badge->setIcon(null);
  238.             }
  239.         }
  240.         return $this;
  241.     }
  242.     /**
  243.      * @return Collection<int, Lesson>
  244.      */
  245.     public function getArticulateLesson(): Collection
  246.     {
  247.         return $this->articulateLesson;
  248.     }
  249.     public function addArticulateLesson(Lesson $articulateLesson): self
  250.     {
  251.         if (!$this->articulateLesson->contains($articulateLesson)) {
  252.             $this->articulateLesson->add($articulateLesson);
  253.             $articulateLesson->setArticulate($this);
  254.         }
  255.         return $this;
  256.     }
  257.     public function removeArticulateLesson(Lesson $articulateLesson): self
  258.     {
  259.         if ($this->articulateLesson->removeElement($articulateLesson)) {
  260.             // set the owning side to null (unless already changed)
  261.             if ($articulateLesson->getArticulate() === $this) {
  262.                 $articulateLesson->setArticulate(null);
  263.             }
  264.         }
  265.         return $this;
  266.     }
  267.     /**
  268.      * @return Collection<int, LandingpageElement>
  269.      */
  270.     public function getLandingpageElements(): Collection
  271.     {
  272.         return $this->landingpageElements;
  273.     }
  274.     public function addLandingpageElement(LandingpageElement $landingpageElement): self
  275.     {
  276.         if (!$this->landingpageElements->contains($landingpageElement)) {
  277.             $this->landingpageElements->add($landingpageElement);
  278.             $landingpageElement->setImage($this);
  279.         }
  280.         return $this;
  281.     }
  282.     public function removeLandingpageElement(LandingpageElement $landingpageElement): self
  283.     {
  284.         if ($this->landingpageElements->removeElement($landingpageElement)) {
  285.             // set the owning side to null (unless already changed)
  286.             if ($landingpageElement->getImage() === $this) {
  287.                 $landingpageElement->setImage(null);
  288.             }
  289.         }
  290.         return $this;
  291.     }
  292. }