src/Entity/MediaObject.php line 70

Open in your IDE?
  1. <?php
  2. // api/src/Entity/MediaObject.php
  3. namespace App\Entity;
  4. use ApiPlatform\Metadata\ApiProperty;
  5. use ApiPlatform\Metadata\ApiResource;
  6. use ApiPlatform\Metadata\Get;
  7. use ApiPlatform\Metadata\GetCollection;
  8. use ApiPlatform\Metadata\Post;
  9. use ApiPlatform\Metadata\Delete;
  10. use App\Controller\CreateMediaObjectAction;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Symfony\Component\HttpFoundation\File\File;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  18. use ApiPlatform\Metadata\ApiFilter;
  19. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  20. use Doctrine\DBAL\Types\Types;
  21. use Symfony\Component\Serializer\Annotation\MaxDepth;
  22. #[Vich\Uploadable]
  23. #[ORM\Entity]
  24. #[ApiResource(
  25.     normalizationContext: ['groups' => ['media_object:read']], 
  26.     types: ['https://schema.org/MediaObject'],
  27.     operations: [
  28.         new Get(),
  29.         new GetCollection(),
  30.         new Delete(),
  31.         new Post(
  32.             controllerCreateMediaObjectAction::class, 
  33.             deserializefalse
  34.             validationContext: ['groups' => ['Default''media_object_create']], 
  35.             openapiContext: [
  36.                 'requestBody' => [
  37.                     'content' => [
  38.                         'multipart/form-data' => [
  39.                             'schema' => [
  40.                                 'type' => 'object'
  41.                                 'properties' => [
  42.                                     'file' => [
  43.                                         'type' => 'string'
  44.                                         'format' => 'binary'
  45.                                     ]
  46.                                 ]
  47.                             ]
  48.                         ]
  49.                     ]
  50.                 ]
  51.             ]
  52.         )
  53.     ],
  54.     order: ['id' => 'DESC'],
  55. )]
  56. #[ApiFilter(SearchFilter::class, properties: [
  57.     'product.id' => 'exact'
  58.     'orders.id' => 'exact',
  59.     'orders.account.user.id' => 'exact',
  60. ])]  
  61. #[ORM\HasLifecycleCallbacks]
  62. class MediaObject
  63. {
  64.     #[Groups(['media_object:read''product:read''cat:read',  'user_like:read''pre_order_product:read''pre_order:read''order:read''order_product:read','order_product:read','user:read''account:read''load_invoice:read''worker:read''account_worker:read''job:read''site_product:read'])]
  65.     #[ORM\IdORM\ColumnORM\GeneratedValue]
  66.     private ?int $id null;
  67.     #[ApiProperty(types: ['https://schema.org/contentUrl'])]
  68.     #[Groups(['media_object:read''product:read''cat:read''user_like:read''pre_order_product:read''pre_order:read''order:read''order_product:read','order_product:read''user:read''account:read''load_invoice:read''worker:read''account_worker:read''job:read''site_product:read'])]
  69.     public ?string $contentUrl null;
  70.     
  71.     #[Vich\UploadableField(mapping"media_object"fileNameProperty"filePath")]
  72.     #[Assert\NotNull(groups: ['media_object_create'])]
  73.     public ?File $file null;
  74.     #[Groups(['media_object:read''product:read''cat:read''user_like:read''pre_order_product:read''pre_order:read''order:read''order_product:read','order_product:read''user:read''account:read''load_invoice:read''worker:read''account_worker:read''job:read''site_product:read'])]
  75.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  76.     public $uploadTimestamp;
  77.     
  78.     #[Groups(['media_object:read''product:read''user_like:read''pre_order_product:read''pre_order:read''order:read''order_product:read','order_product:read','user:read''account:read''load_invoice:read''worker:read''account_worker:read''job:read''cat:read''site_product:read'])]  
  79.     #[ORM\Column(nullabletrue)]
  80.     private ?bool $main null;
  81.     #[ORM\Column(nullabletrue)] 
  82.     #[Groups(['media_object:read''product:read''cat:read''user_like:read''pre_order_product:read''pre_order:read''order:read''order_product:read','order_product:read''user:read''account:read''load_invoice:read''worker:read''account_worker:read''job:read''site_product:read'])]
  83.     public ?string $filePath null;
  84.     
  85.     #[Groups(['media_object_create'])]
  86.     #[ORM\ManyToOne(inversedBy'media')]
  87.     private ?Products $product null;
  88.     #[Groups(['media_object_create'])]
  89.     #[ORM\ManyToOne(inversedBy'mediaObjects')]
  90.     private ?Orders $orders null;
  91.     #[Groups(['media_object:read''media_object_create'])]
  92.     #[ORM\Column(length100nullabletrue)]
  93.     private ?string $type null;
  94.     #[Groups(['media_object:read''media_object_create'])]
  95.     #[ORM\Column(length255nullabletrue)]
  96.     private ?string $name null;
  97.     #[Groups(['media_object_create'])]
  98.     #[ORM\ManyToOne(inversedBy'mediaObjects')]
  99.     private ?User $users null;
  100.     #[Groups(['media_object_create'])]
  101.     #[ORM\ManyToOne(inversedBy'media')]
  102.     private ?AccountWorker $accountWorker null;
  103.     
  104.     #[Groups(['media_object_create'])]
  105.     #[ORM\ManyToOne(inversedBy'media')]
  106.     private ?FormAnswer $formAnswer null;
  107.     #[Groups(['media_object_create'])]
  108.     #[ORM\ManyToOne(inversedBy'mediaObjects'cascade:['persist'])]
  109.     private ?Jobs $job null;
  110.     #[ORM\OneToMany(mappedBy'photo'targetEntityWorkers::class, cascade:['persist'])]
  111.     private Collection $workers;
  112.     #[ORM\OneToMany(mappedBy'document'targetEntityAccountJobsList::class, cascade:['persist'])]
  113.     private Collection $accountJobsLists;
  114.     #[ORM\OneToMany(mappedBy'commandment'targetEntityJobs::class, cascade:['persist'])]
  115.     private Collection $commandment_jobs;
  116.     #[ORM\OneToMany(mappedBy'graph'targetEntityJobs::class, cascade:['persist'])]
  117.     private Collection $graph_jobs;
  118.     #[ORM\OneToMany(mappedBy'protocole'targetEntityJobs::class, cascade:['persist'])]
  119.     private Collection $protocole_jobs;
  120.     #[ORM\OneToMany(mappedBy'mainMedia'targetEntityProducts::class)]
  121.     private Collection $MainProducts;
  122.     #[Groups(['media_object:read''product:read''user_like:read''pre_order_product:read''pre_order:read''order:read''order_product:read','order_product:read','user:read''account:read''load_invoice:read''worker:read''account_worker:read''job:read''site_product:read''cat:read'])]
  123.     #[ORM\Column(nullabletrue)]
  124.     private ?int $size null;
  125.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'resizeImagings')]
  126.     private ?self $resizeImgParent null;
  127.     #[Groups(['media_object:read''product:read''user_like:read''pre_order_product:read''pre_order:read''order:read''order_product:read','order_product:read','user:read''account:read''load_invoice:read''worker:read''account_worker:read''job:read''site_product:read''cat:read'])]
  128.     #[ORM\OneToMany(mappedBy'resizeImgParent'targetEntityself::class, cascade:['persist''remove'])]
  129.     private Collection $resizeImagings;
  130.     #[ORM\OneToMany(mappedBy'media'targetEntitySiteProductsMedia::class, cascade:['persist''remove'])]
  131.     private Collection $siteProductsMedia;
  132.  
  133.     #[ORM\OneToMany(mappedBy'media'targetEntityCategory::class, cascade:['persist'])]
  134.     private Collection $categories;
  135.     #[ORM\OneToMany(mappedBy'media'targetEntitySlide::class)]
  136.     private Collection $slides;
  137.     #[ORM\OneToMany(mappedBy'mainMediaHover'targetEntityProducts::class)]
  138.     private Collection $productsHover;
  139.     public function __construct()
  140.     {
  141.         $this->workers = new ArrayCollection();
  142.         $this->accountJobsLists = new ArrayCollection();
  143.         $this->commandment_jobs = new ArrayCollection();
  144.         $this->graph_jobs = new ArrayCollection();
  145.         $this->protocole_jobs = new ArrayCollection();
  146.         $this->MainProducts = new ArrayCollection();
  147.         $this->resizeImagings = new ArrayCollection();
  148.         $this->siteProductsMedia = new ArrayCollection();
  149.         $this->categories = new ArrayCollection();
  150.         $this->slides = new ArrayCollection();
  151.         $this->productsHover = new ArrayCollection();
  152.     }
  153.     public function getId(): ?int
  154.     
  155.         return $this->id;
  156.     }
  157.     public function getUploadTimestamp(): ?\DateTimeInterface
  158.     {
  159.         return $this->uploadTimestamp;
  160.     }
  161.     public function getProduct(): ?Products
  162.     {
  163.         return $this->product;
  164.     }
  165.     public function setProduct(?Products $product): self
  166.     {
  167.         $this->product $product;
  168.         return $this;
  169.     }
  170.     public function getOrders(): ?Orders
  171.     {
  172.         return $this->orders;
  173.     }
  174.     public function setOrders(?Orders $orders): self
  175.     {
  176.         $this->orders $orders;
  177.         return $this;
  178.     }
  179.     public function getType(): ?string
  180.     {
  181.         return $this->type;
  182.     }
  183.     public function setType(string $type): self
  184.     {
  185.         $this->type $type;
  186.         return $this;
  187.     }
  188.     public function getName(): ?string
  189.     {
  190.         return $this->name;
  191.     }
  192.     public function setName(?string $name): self
  193.     {
  194.         $this->name $name;
  195.         return $this;
  196.     }
  197.     public function getUsers(): ?User
  198.     {
  199.         return $this->users;
  200.     }
  201.     public function setUsers(?User $users): self
  202.     {
  203.         $this->users $users;
  204.         return $this;
  205.     }
  206.     public function getAccountWorker(): ?AccountWorker
  207.     {
  208.         return $this->accountWorker;
  209.     }
  210.     public function setAccountWorker(?AccountWorker $accountWorker): self
  211.     {
  212.         $this->accountWorker $accountWorker;
  213.         return $this;
  214.     }
  215.     
  216.     public function setFormAnswer(?FormAnswer $formAnswer): self
  217.     {
  218.         $this->formAnswer $formAnswer;
  219.         return $this;
  220.     }
  221.     public function getJob(): ?Jobs
  222.     {
  223.         return $this->job;
  224.     }
  225.     public function setJob(?Jobs $job): self
  226.     {
  227.         $this->job $job;
  228.         return $this;
  229.     }
  230.     /**
  231.      * @return Collection<int, Workers>
  232.      */
  233.     public function getWorkers(): Collection
  234.     {
  235.         return $this->workers;
  236.     }
  237.     public function addWorker(Workers $worker): self
  238.     {
  239.         if (!$this->workers->contains($worker)) {
  240.             $this->workers->add($worker);
  241.             $worker->setPhoto($this);
  242.         }
  243.         return $this;
  244.     }
  245.     public function removeWorker(Workers $worker): self
  246.     {
  247.         if ($this->workers->removeElement($worker)) {
  248.             // set the owning side to null (unless already changed)
  249.             if ($worker->getPhoto() === $this) {
  250.                 $worker->setPhoto(null);
  251.             }
  252.         }
  253.         return $this;
  254.     }
  255.     /**
  256.      * @return Collection<int, AccountJobsList>
  257.      */
  258.     public function getAccountJobsLists(): Collection
  259.     {
  260.         return $this->accountJobsLists;
  261.     }
  262.     public function addAccountJobsList(AccountJobsList $accountJobsList): self
  263.     {
  264.         if (!$this->accountJobsLists->contains($accountJobsList)) {
  265.             $this->accountJobsLists->add($accountJobsList);
  266.             $accountJobsList->setDocument($this);
  267.         }
  268.         return $this;
  269.     }
  270.     public function removeAccountJobsList(AccountJobsList $accountJobsList): self
  271.     {
  272.         if ($this->accountJobsLists->removeElement($accountJobsList)) {
  273.             // set the owning side to null (unless already changed)
  274.             if ($accountJobsList->getDocument() === $this) {
  275.                 $accountJobsList->setDocument(null);
  276.             }
  277.         }
  278.         return $this;
  279.     }
  280.     /**
  281.      * @return Collection<int, Jobs>
  282.      */
  283.     public function getCommandmentJobs(): Collection
  284.     {
  285.         return $this->commandment_jobs;
  286.     }
  287.     public function addCommandmentJob(Jobs $commandmentJob): self
  288.     {
  289.         if (!$this->commandment_jobs->contains($commandmentJob)) {
  290.             $this->commandment_jobs->add($commandmentJob);
  291.             $commandmentJob->setCommandment($this);
  292.         }
  293.         return $this;
  294.     }
  295.     public function removeCommandmentJob(Jobs $commandmentJob): self
  296.     {
  297.         if ($this->commandment_jobs->removeElement($commandmentJob)) {
  298.             // set the owning side to null (unless already changed)
  299.             if ($commandmentJob->getCommandment() === $this) {
  300.                 $commandmentJob->setCommandment(null);
  301.             }
  302.         }
  303.         return $this;
  304.     }
  305.     /**
  306.      * @return Collection<int, Jobs>
  307.      */
  308.     public function getGraphJobs(): Collection
  309.     {
  310.         return $this->graph_jobs;
  311.     }
  312.     public function addGraphJob(Jobs $graphJob): self
  313.     {
  314.         if (!$this->graph_jobs->contains($graphJob)) {
  315.             $this->graph_jobs->add($graphJob);
  316.             $graphJob->setGraph($this);
  317.         }
  318.         return $this;
  319.     }
  320.     public function removeGraphJob(Jobs $graphJob): self
  321.     {
  322.         if ($this->graph_jobs->removeElement($graphJob)) {
  323.             // set the owning side to null (unless already changed)
  324.             if ($graphJob->getGraph() === $this) {
  325.                 $graphJob->setGraph(null);
  326.             }
  327.         }
  328.         return $this;
  329.     }
  330.     /**
  331.      * @return Collection<int, Jobs>
  332.      */
  333.     public function getProtocoleJobs(): Collection
  334.     {
  335.         return $this->protocole_jobs;
  336.     }
  337.     public function addProtocoleJob(Jobs $protocoleJob): self
  338.     {
  339.         if (!$this->protocole_jobs->contains($protocoleJob)) {
  340.             $this->protocole_jobs->add($protocoleJob);
  341.             $protocoleJob->setProtocole($this);
  342.         }
  343.         return $this;
  344.     }
  345.     public function removeProtocoleJob(Jobs $protocoleJob): self
  346.     {
  347.         if ($this->protocole_jobs->removeElement($protocoleJob)) {
  348.             // set the owning side to null (unless already changed)
  349.             if ($protocoleJob->getProtocole() === $this) {
  350.                 $protocoleJob->setProtocole(null);
  351.             }
  352.         }
  353.         return $this;
  354.     }
  355.     public function isMain(): ?bool
  356.     {
  357.         return $this->main;
  358.     }
  359.     public function setMain(?bool $main): self
  360.     {
  361.         $this->main $main;
  362.         return $this;
  363.     }
  364.     /**
  365.      * @return Collection<int, Products>
  366.      */
  367.     public function getMainProducts(): Collection
  368.     {
  369.         return $this->MainProducts;
  370.     }
  371.     public function addMainProduct(Products $mainProduct): self
  372.     {
  373.         if (!$this->MainProducts->contains($mainProduct)) {
  374.             $this->MainProducts->add($mainProduct);
  375.             $mainProduct->setMainMedia($this);
  376.         }
  377.         return $this;
  378.     }
  379.     public function removeMainProduct(Products $mainProduct): self
  380.     {
  381.         if ($this->MainProducts->removeElement($mainProduct)) {
  382.             // set the owning side to null (unless already changed)
  383.             if ($mainProduct->getMainMedia() === $this) {
  384.                 $mainProduct->setMainMedia(null);
  385.             }
  386.         }
  387.         return $this;
  388.     }
  389.     #[ORM\PrePersist]
  390.     public function setCreatedAtValue(): void
  391.     {
  392.         $this->uploadTimestamp = new \DateTime(); 
  393.     }
  394.     public function getSize(): ?int
  395.     {
  396.         return $this->size;
  397.     }
  398.     public function setSize(?int $size): static
  399.     {
  400.         $this->size $size;
  401.         return $this;
  402.     }
  403.     public function getResizeImgParent(): ?self
  404.     {
  405.         return $this->resizeImgParent;
  406.     }
  407.     public function setResizeImgParent(?self $resizeImgParent): static
  408.     {
  409.         $this->resizeImgParent $resizeImgParent;
  410.         return $this;
  411.     }
  412.     /**
  413.      * @return Collection<int, self>
  414.      */
  415.     public function getResizeImagings(): Collection
  416.     {
  417.         return $this->resizeImagings;
  418.     }
  419.     public function addResizeImging(self $resizeImging): static
  420.     {
  421.         if (!$this->resizeImagings->contains($resizeImging)) {
  422.             $this->resizeImagings->add($resizeImging);
  423.             $resizeImging->setResizeImgParent($this);
  424.         }
  425.         return $this;
  426.     }
  427.     public function removeResizeImging(self $resizeImging): static
  428.     {
  429.         if ($this->resizeImagings->removeElement($resizeImging)) {
  430.             // set the owning side to null (unless already changed)
  431.             if ($resizeImging->getResizeImgParent() === $this) {
  432.                 $resizeImging->setResizeImgParent(null);
  433.             }
  434.         }
  435.         return $this;
  436.     }
  437.     /**
  438.      * @return Collection<int, SiteProductsMedia>
  439.      */
  440.     public function getSiteProductsMedia(): Collection
  441.     {
  442.         return $this->siteProductsMedia;
  443.     }
  444.     public function addSiteProductsMedium(SiteProductsMedia $siteProductsMedium): static
  445.     {
  446.         if (!$this->siteProductsMedia->contains($siteProductsMedium)) {
  447.             $this->siteProductsMedia->add($siteProductsMedium);
  448.             $siteProductsMedium->setMedia($this);
  449.         }
  450.         return $this;
  451.     }
  452.     public function removeSiteProductsMedium(SiteProductsMedia $siteProductsMedium): static
  453.     {
  454.         if ($this->siteProductsMedia->removeElement($siteProductsMedium)) {
  455.             // set the owning side to null (unless already changed)
  456.             if ($siteProductsMedium->getMedia() === $this) {
  457.                 $siteProductsMedium->setMedia(null);
  458.             }
  459.         }
  460.         return $this;
  461.     }
  462.     /**
  463.      * @return Collection<int, Category>
  464.      */
  465.     public function getCategories(): Collection
  466.     {
  467.         return $this->categories;
  468.     }
  469.     public function addCategory(Category $category): static
  470.     {
  471.         if (!$this->categories->contains($category)) {
  472.             $this->categories->add($category);
  473.             $category->setMedia($this);
  474.         }
  475.         return $this;
  476.     }
  477.     public function removeCategory(Category $category): static
  478.     {
  479.         if ($this->categories->removeElement($category)) {
  480.             // set the owning side to null (unless already changed)
  481.             if ($category->getMedia() === $this) {
  482.                 $category->setMedia(null);
  483.             }
  484.         }
  485.         return $this;
  486.     }
  487.     /**
  488.      * @return Collection<int, Slide>
  489.      */
  490.     public function getSlides(): Collection
  491.     {
  492.         return $this->slides;
  493.     }
  494.     public function addSlide(Slide $slide): static
  495.     {
  496.         if (!$this->slides->contains($slide)) {
  497.             $this->slides->add($slide);
  498.             $slide->setMedia($this);
  499.         }
  500.         return $this;
  501.     }
  502.     public function removeSlide(Slide $slide): static
  503.     {
  504.         if ($this->slides->removeElement($slide)) {
  505.             // set the owning side to null (unless already changed)
  506.             if ($slide->getMedia() === $this) {
  507.                 $slide->setMedia(null);
  508.             }
  509.         }
  510.         return $this;
  511.     }
  512.     /**
  513.      * @return Collection<int, Products>
  514.      */
  515.     public function getProductsHover(): Collection
  516.     {
  517.         return $this->productsHover;
  518.     }
  519.     public function addProductsHover(Products $productsHover): static
  520.     {
  521.         if (!$this->productsHover->contains($productsHover)) {
  522.             $this->productsHover->add($productsHover);
  523.             $productsHover->setMainMediaHover($this);
  524.         }
  525.         return $this;
  526.     }
  527.     public function removeProductsHover(Products $productsHover): static
  528.     {
  529.         if ($this->productsHover->removeElement($productsHover)) {
  530.             // set the owning side to null (unless already changed)
  531.             if ($productsHover->getMainMediaHover() === $this) {
  532.                 $productsHover->setMainMediaHover(null);
  533.             }
  534.         }
  535.         return $this;
  536.     }
  537. }