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''news:read''user_docs: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''news:read''user_docs: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.     #[ORM\OneToMany(mappedBy'media'targetEntityUsersDocs::class)]
  101.     private Collection $usersDocs;
  102.     #[Groups(['media_object_create'])]
  103.     #[ORM\ManyToOne(inversedBy'media')]
  104.     private ?AccountWorker $accountWorker null;
  105.     
  106.     #[Groups(['media_object_create'])]
  107.     #[ORM\ManyToOne(inversedBy'media')]
  108.     private ?FormAnswer $formAnswer null;
  109.     #[Groups(['media_object_create'])]
  110.     #[ORM\ManyToOne(inversedBy'mediaObjects'cascade:['persist'])]
  111.     private ?Jobs $job null;
  112.     #[ORM\OneToMany(mappedBy'photo'targetEntityWorkers::class, cascade:['persist'])]
  113.     private Collection $workers;
  114.     #[ORM\OneToMany(mappedBy'document'targetEntityAccountJobsList::class, cascade:['persist'])]
  115.     private Collection $accountJobsLists;
  116.     #[ORM\OneToMany(mappedBy'commandment'targetEntityJobs::class, cascade:['persist'])]
  117.     private Collection $commandment_jobs;
  118.     #[ORM\OneToMany(mappedBy'graph'targetEntityJobs::class, cascade:['persist'])]
  119.     private Collection $graph_jobs;
  120.     #[ORM\OneToMany(mappedBy'protocole'targetEntityJobs::class, cascade:['persist'])]
  121.     private Collection $protocole_jobs;
  122.     #[ORM\OneToMany(mappedBy'mainMedia'targetEntityProducts::class)]
  123.     private Collection $MainProducts;
  124.     #[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''news:read'])]
  125.     #[ORM\Column(nullabletrue)]
  126.     private ?int $size null;
  127.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'resizeImagings')]
  128.     private ?self $resizeImgParent null;
  129.     #[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''news:read'])]
  130.     #[ORM\OneToMany(mappedBy'resizeImgParent'targetEntityself::class, cascade:['persist''remove'])]
  131.     private Collection $resizeImagings;
  132.     #[ORM\OneToMany(mappedBy'media'targetEntitySiteProductsMedia::class, cascade:['persist''remove'])]
  133.     private Collection $siteProductsMedia;
  134.  
  135.     #[ORM\OneToMany(mappedBy'media'targetEntityCategory::class, cascade:['persist'])]
  136.     private Collection $categories;
  137.     #[ORM\OneToMany(mappedBy'media'targetEntitySlide::class)]
  138.     private Collection $slides;
  139.     #[ORM\OneToMany(mappedBy'mainMediaHover'targetEntityProducts::class)]
  140.     private Collection $productsHover;
  141.     #[ORM\OneToMany(mappedBy'media'targetEntityNews::class)]
  142.     private Collection $news;
  143.     public function __construct()
  144.     {
  145.         $this->usersDocs = new ArrayCollection();
  146.         $this->workers = new ArrayCollection();
  147.         $this->accountJobsLists = new ArrayCollection();
  148.         $this->commandment_jobs = new ArrayCollection();
  149.         $this->graph_jobs = new ArrayCollection();
  150.         $this->protocole_jobs = new ArrayCollection();
  151.         $this->MainProducts = new ArrayCollection();
  152.         $this->resizeImagings = new ArrayCollection();
  153.         $this->siteProductsMedia = new ArrayCollection();
  154.         $this->categories = new ArrayCollection();
  155.         $this->slides = new ArrayCollection();
  156.         $this->productsHover = new ArrayCollection();
  157.         $this->news = new ArrayCollection();
  158.     }
  159.     public function getId(): ?int
  160.     
  161.         return $this->id;
  162.     }
  163.     public function getUploadTimestamp(): ?\DateTimeInterface
  164.     {
  165.         return $this->uploadTimestamp;
  166.     }
  167.     public function getProduct(): ?Products
  168.     {
  169.         return $this->product;
  170.     }
  171.     public function setProduct(?Products $product): self
  172.     {
  173.         $this->product $product;
  174.         return $this;
  175.     }
  176.     public function getOrders(): ?Orders
  177.     {
  178.         return $this->orders;
  179.     }
  180.     public function setOrders(?Orders $orders): self
  181.     {
  182.         $this->orders $orders;
  183.         return $this;
  184.     }
  185.     public function getType(): ?string
  186.     {
  187.         return $this->type;
  188.     }
  189.     public function setType(string $type): self
  190.     {
  191.         $this->type $type;
  192.         return $this;
  193.     }
  194.     public function getName(): ?string
  195.     {
  196.         return $this->name;
  197.     }
  198.     public function setName(?string $name): self
  199.     {
  200.         $this->name $name;
  201.         return $this;
  202.     }
  203.     public function getUsers(): ?User
  204.     {
  205.         return $this->users;
  206.     }
  207.     public function setUsers(?User $users): self
  208.     {
  209.         $this->users $users;
  210.         return $this;
  211.     }
  212.     public function getAccountWorker(): ?AccountWorker
  213.     {
  214.         return $this->accountWorker;
  215.     }
  216.     public function setAccountWorker(?AccountWorker $accountWorker): self
  217.     {
  218.         $this->accountWorker $accountWorker;
  219.         return $this;
  220.     }
  221.     
  222.     public function setFormAnswer(?FormAnswer $formAnswer): self
  223.     {
  224.         $this->formAnswer $formAnswer;
  225.         return $this;
  226.     }
  227.     /**
  228.      * @return Collection<int, UsersDocs>
  229.      */
  230.     public function getUsersDocs(): Collection
  231.     {
  232.         return $this->usersDocs;
  233.     }
  234.     public function addUsersDoc(UsersDocs $usersDoc): static
  235.     {
  236.         if (!$this->usersDocs->contains($usersDoc)) {
  237.             $this->usersDocs->add($usersDoc);
  238.             $usersDoc->setMedia($this);
  239.         }
  240.         return $this;
  241.     }
  242.     
  243.     public function getJob(): ?Jobs
  244.     {
  245.         return $this->job;
  246.     }
  247.     public function setJob(?Jobs $job): self
  248.     {
  249.         $this->job $job;
  250.         return $this;
  251.     }
  252.     /**
  253.      * @return Collection<int, Workers>
  254.      */
  255.     public function getWorkers(): Collection
  256.     {
  257.         return $this->workers;
  258.     }
  259.     public function addWorker(Workers $worker): self
  260.     {
  261.         if (!$this->workers->contains($worker)) {
  262.             $this->workers->add($worker);
  263.             $worker->setPhoto($this);
  264.         }
  265.         return $this;
  266.     }
  267.     public function removeUsersDoc(UsersDocs $usersDoc): static
  268.     {
  269.         if ($this->usersDocs->removeElement($usersDoc)) {
  270.             // set the owning side to null (unless already changed)
  271.             if ($usersDoc->getMedia() === $this) {
  272.                 $usersDoc->setMedia(null);
  273.             }
  274.         }
  275.         return $this;
  276.     }
  277.     public function removeWorker(Workers $worker): self
  278.     {
  279.         if ($this->workers->removeElement($worker)) {
  280.             // set the owning side to null (unless already changed)
  281.             if ($worker->getPhoto() === $this) {
  282.                 $worker->setPhoto(null);
  283.             }
  284.         }
  285.         return $this;
  286.     }
  287.     /**
  288.      * @return Collection<int, AccountJobsList>
  289.      */
  290.     public function getAccountJobsLists(): Collection
  291.     {
  292.         return $this->accountJobsLists;
  293.     }
  294.     public function addAccountJobsList(AccountJobsList $accountJobsList): self
  295.     {
  296.         if (!$this->accountJobsLists->contains($accountJobsList)) {
  297.             $this->accountJobsLists->add($accountJobsList);
  298.             $accountJobsList->setDocument($this);
  299.         }
  300.         return $this;
  301.     }
  302.     public function removeAccountJobsList(AccountJobsList $accountJobsList): self
  303.     {
  304.         if ($this->accountJobsLists->removeElement($accountJobsList)) {
  305.             // set the owning side to null (unless already changed)
  306.             if ($accountJobsList->getDocument() === $this) {
  307.                 $accountJobsList->setDocument(null);
  308.             }
  309.         }
  310.         return $this;
  311.     }
  312.     /**
  313.      * @return Collection<int, Jobs>
  314.      */
  315.     public function getCommandmentJobs(): Collection
  316.     {
  317.         return $this->commandment_jobs;
  318.     }
  319.     public function addCommandmentJob(Jobs $commandmentJob): self
  320.     {
  321.         if (!$this->commandment_jobs->contains($commandmentJob)) {
  322.             $this->commandment_jobs->add($commandmentJob);
  323.             $commandmentJob->setCommandment($this);
  324.         }
  325.         return $this;
  326.     }
  327.     public function removeCommandmentJob(Jobs $commandmentJob): self
  328.     {
  329.         if ($this->commandment_jobs->removeElement($commandmentJob)) {
  330.             // set the owning side to null (unless already changed)
  331.             if ($commandmentJob->getCommandment() === $this) {
  332.                 $commandmentJob->setCommandment(null);
  333.             }
  334.         }
  335.         return $this;
  336.     }
  337.     /**
  338.      * @return Collection<int, Jobs>
  339.      */
  340.     public function getGraphJobs(): Collection
  341.     {
  342.         return $this->graph_jobs;
  343.     }
  344.     public function addGraphJob(Jobs $graphJob): self
  345.     {
  346.         if (!$this->graph_jobs->contains($graphJob)) {
  347.             $this->graph_jobs->add($graphJob);
  348.             $graphJob->setGraph($this);
  349.         }
  350.         return $this;
  351.     }
  352.     public function removeGraphJob(Jobs $graphJob): self
  353.     {
  354.         if ($this->graph_jobs->removeElement($graphJob)) {
  355.             // set the owning side to null (unless already changed)
  356.             if ($graphJob->getGraph() === $this) {
  357.                 $graphJob->setGraph(null);
  358.             }
  359.         }
  360.         return $this;
  361.     }
  362.     /**
  363.      * @return Collection<int, Jobs>
  364.      */
  365.     public function getProtocoleJobs(): Collection
  366.     {
  367.         return $this->protocole_jobs;
  368.     }
  369.     public function addProtocoleJob(Jobs $protocoleJob): self
  370.     {
  371.         if (!$this->protocole_jobs->contains($protocoleJob)) {
  372.             $this->protocole_jobs->add($protocoleJob);
  373.             $protocoleJob->setProtocole($this);
  374.         }
  375.         return $this;
  376.     }
  377.     public function removeProtocoleJob(Jobs $protocoleJob): self
  378.     {
  379.         if ($this->protocole_jobs->removeElement($protocoleJob)) {
  380.             // set the owning side to null (unless already changed)
  381.             if ($protocoleJob->getProtocole() === $this) {
  382.                 $protocoleJob->setProtocole(null);
  383.             }
  384.         }
  385.         return $this;
  386.     }
  387.     public function isMain(): ?bool
  388.     {
  389.         return $this->main;
  390.     }
  391.     public function setMain(?bool $main): self
  392.     {
  393.         $this->main $main;
  394.         return $this;
  395.     }
  396.     /**
  397.      * @return Collection<int, Products>
  398.      */
  399.     public function getMainProducts(): Collection
  400.     {
  401.         return $this->MainProducts;
  402.     }
  403.     public function addMainProduct(Products $mainProduct): self
  404.     {
  405.         if (!$this->MainProducts->contains($mainProduct)) {
  406.             $this->MainProducts->add($mainProduct);
  407.             $mainProduct->setMainMedia($this);
  408.         }
  409.         return $this;
  410.     }
  411.     public function removeMainProduct(Products $mainProduct): self
  412.     {
  413.         if ($this->MainProducts->removeElement($mainProduct)) {
  414.             // set the owning side to null (unless already changed)
  415.             if ($mainProduct->getMainMedia() === $this) {
  416.                 $mainProduct->setMainMedia(null);
  417.             }
  418.         }
  419.         return $this;
  420.     }
  421.     #[ORM\PrePersist]
  422.     public function setCreatedAtValue(): void
  423.     {
  424.         $this->uploadTimestamp = new \DateTime(); 
  425.     }
  426.     public function getSize(): ?int
  427.     {
  428.         return $this->size;
  429.     }
  430.     public function setSize(?int $size): static
  431.     {
  432.         $this->size $size;
  433.         return $this;
  434.     }
  435.     public function getResizeImgParent(): ?self
  436.     {
  437.         return $this->resizeImgParent;
  438.     }
  439.     public function setResizeImgParent(?self $resizeImgParent): static
  440.     {
  441.         $this->resizeImgParent $resizeImgParent;
  442.         return $this;
  443.     }
  444.     /**
  445.      * @return Collection<int, self>
  446.      */
  447.     public function getResizeImagings(): Collection
  448.     {
  449.         return $this->resizeImagings;
  450.     }
  451.     public function addResizeImging(self $resizeImging): static
  452.     {
  453.         if (!$this->resizeImagings->contains($resizeImging)) {
  454.             $this->resizeImagings->add($resizeImging);
  455.             $resizeImging->setResizeImgParent($this);
  456.         }
  457.         return $this;
  458.     }
  459.     public function removeResizeImging(self $resizeImging): static
  460.     {
  461.         if ($this->resizeImagings->removeElement($resizeImging)) {
  462.             // set the owning side to null (unless already changed)
  463.             if ($resizeImging->getResizeImgParent() === $this) {
  464.                 $resizeImging->setResizeImgParent(null);
  465.             }
  466.         }
  467.         return $this;
  468.     }
  469.     /**
  470.      * @return Collection<int, SiteProductsMedia>
  471.      */
  472.     public function getSiteProductsMedia(): Collection
  473.     {
  474.         return $this->siteProductsMedia;
  475.     }
  476.     public function addSiteProductsMedium(SiteProductsMedia $siteProductsMedium): static
  477.     {
  478.         if (!$this->siteProductsMedia->contains($siteProductsMedium)) {
  479.             $this->siteProductsMedia->add($siteProductsMedium);
  480.             $siteProductsMedium->setMedia($this);
  481.         }
  482.         return $this;
  483.     }
  484.     public function removeSiteProductsMedium(SiteProductsMedia $siteProductsMedium): static
  485.     {
  486.         if ($this->siteProductsMedia->removeElement($siteProductsMedium)) {
  487.             // set the owning side to null (unless already changed)
  488.             if ($siteProductsMedium->getMedia() === $this) {
  489.                 $siteProductsMedium->setMedia(null);
  490.             }
  491.         }
  492.         return $this;
  493.     }
  494.     /**
  495.      * @return Collection<int, Category>
  496.      */
  497.     public function getCategories(): Collection
  498.     {
  499.         return $this->categories;
  500.     }
  501.     public function addCategory(Category $category): static
  502.     {
  503.         if (!$this->categories->contains($category)) {
  504.             $this->categories->add($category);
  505.             $category->setMedia($this);
  506.         }
  507.         return $this;
  508.     }
  509.     public function removeCategory(Category $category): static
  510.     {
  511.         if ($this->categories->removeElement($category)) {
  512.             // set the owning side to null (unless already changed)
  513.             if ($category->getMedia() === $this) {
  514.                 $category->setMedia(null);
  515.             }
  516.         }
  517.         return $this;
  518.     }
  519.     /**
  520.      * @return Collection<int, Slide>
  521.      */
  522.     public function getSlides(): Collection
  523.     {
  524.         return $this->slides;
  525.     }
  526.     public function addSlide(Slide $slide): static
  527.     {
  528.         if (!$this->slides->contains($slide)) {
  529.             $this->slides->add($slide);
  530.             $slide->setMedia($this);
  531.         }
  532.         return $this;
  533.     }
  534.     public function removeSlide(Slide $slide): static
  535.     {
  536.         if ($this->slides->removeElement($slide)) {
  537.             // set the owning side to null (unless already changed)
  538.             if ($slide->getMedia() === $this) {
  539.                 $slide->setMedia(null);
  540.             }
  541.         }
  542.         return $this;
  543.     }
  544.     /**
  545.      * @return Collection<int, Products>
  546.      */
  547.     public function getProductsHover(): Collection
  548.     {
  549.         return $this->productsHover;
  550.     }
  551.     public function addProductsHover(Products $productsHover): static
  552.     {
  553.         if (!$this->productsHover->contains($productsHover)) {
  554.             $this->productsHover->add($productsHover);
  555.             $productsHover->setMainMediaHover($this);
  556.         }
  557.         return $this;
  558.     }
  559.     public function removeProductsHover(Products $productsHover): static
  560.     {
  561.         if ($this->productsHover->removeElement($productsHover)) {
  562.             // set the owning side to null (unless already changed)
  563.             if ($productsHover->getMainMediaHover() === $this) {
  564.                 $productsHover->setMainMediaHover(null);
  565.             }
  566.         }
  567.         return $this;
  568.     }
  569.     /**
  570.      * @return Collection<int, News>
  571.      */
  572.     public function getNews(): Collection
  573.     {
  574.         return $this->news;
  575.     }
  576.     public function addNews(News $news): static
  577.     {
  578.         if (!$this->news->contains($news)) {
  579.             $this->news->add($news);
  580.             $news->setMedia($this);
  581.         }
  582.         return $this;
  583.     }
  584.     public function removeNews(News $news): static
  585.     {
  586.         if ($this->news->removeElement($news)) {
  587.             // set the owning side to null (unless already changed)
  588.             if ($news->getMedia() === $this) {
  589.                 $news->setMedia(null);
  590.             }
  591.         }
  592.         return $this;
  593.     }
  594. }