src/Entity/MediaObject.php line 63

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. #[Vich\Uploadable]
  21. #[ORM\Entity]
  22. #[ApiResource(
  23.     normalizationContext: ['groups' => ['media_object:read']], 
  24.     types: ['https://schema.org/MediaObject'],
  25.     operations: [
  26.         new Get(),
  27.         new GetCollection(),
  28.         new Delete(),
  29.         new Post(
  30.             controllerCreateMediaObjectAction::class, 
  31.             deserializefalse
  32.             validationContext: ['groups' => ['Default''media_object_create']], 
  33.             openapiContext: [
  34.                 'requestBody' => [
  35.                     'content' => [
  36.                         'multipart/form-data' => [
  37.                             'schema' => [
  38.                                 'type' => 'object'
  39.                                 'properties' => [
  40.                                     'file' => [
  41.                                         'type' => 'string'
  42.                                         'format' => 'binary'
  43.                                     ]
  44.                                 ]
  45.                             ]
  46.                         ]
  47.                     ]
  48.                 ]
  49.             ]
  50.         )
  51.     ],
  52.     order: ['id' => 'DESC'],
  53. )]
  54. #[ApiFilter(SearchFilter::class, properties: [
  55.     'product.id' => 'exact'
  56.     'orders.id' => 'exact',
  57.     'orders.account.user.id' => 'exact',
  58. ])]  
  59. class MediaObject
  60. {
  61.     #[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''user_docs:read',  'account_worker:read''job:read''faq:read'])]
  62.     #[ORM\IdORM\ColumnORM\GeneratedValue]
  63.     private ?int $id null;
  64.     #[ApiProperty(types: ['https://schema.org/contentUrl'])]
  65.     #[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''user_docs:read''account_worker:read''job:read''faq:read'])]
  66.     public ?string $contentUrl null;
  67.     #[Vich\UploadableField(mapping"media_object"fileNameProperty"filePath")]
  68.     #[Assert\NotNull(groups: ['media_object_create'])]
  69.     public ?File $file null;
  70.     #[ORM\Column(nullabletrue)] 
  71.     public ?string $filePath null;
  72.     
  73.     #[Groups(['media_object:read''media_object_create'])]
  74.     #[ORM\ManyToOne(inversedBy'mediaObjects')]
  75.     private ?Products $product null;
  76.     #[Groups(['media_object:read''media_object_create'])]
  77.     #[ORM\ManyToOne(inversedBy'mediaObjects')]
  78.     private ?Orders $orders null;
  79.     #[Groups(['media_object:read''media_object_create'])]
  80.     #[ORM\Column(length100nullabletrue)]
  81.     private ?string $type null;
  82.     #[Groups(['media_object:read''media_object_create'])]
  83.     #[ORM\Column(length255nullabletrue)]
  84.     private ?string $name null;
  85.     #[Groups(['media_object:read''media_object_create'])]
  86.     #[ORM\ManyToOne(inversedBy'mediaObjects')]
  87.     private ?User $users null;
  88.     #[Groups(['media_object:read''media_object_create'])]
  89.     #[ORM\ManyToOne(inversedBy'media')]
  90.     private ?AccountWorker $accountWorker null;
  91.     
  92.     #[Groups(['media_object:read''media_object_create'])]
  93.     #[ORM\ManyToOne(inversedBy'media')]
  94.     private ?FormAnswer $formAnswer null;
  95.     #[Groups(['media_object:read''media_object_create'])]
  96.     #[ORM\ManyToOne(inversedBy'mediaObjects'cascade:['persist'])]
  97.     private ?Jobs $job null;
  98.     #[ORM\OneToMany(mappedBy'photo'targetEntityWorkers::class, cascade:['persist'])]
  99.     private Collection $workers;
  100.     #[ORM\OneToMany(mappedBy'document'targetEntityAccountJobsList::class, cascade:['persist'])]
  101.     private Collection $accountJobsLists;
  102.     #[ORM\OneToMany(mappedBy'commandment'targetEntityJobs::class, cascade:['persist'])]
  103.     private Collection $commandment_jobs;
  104.     #[ORM\OneToMany(mappedBy'graph'targetEntityJobs::class, cascade:['persist'])]
  105.     private Collection $graph_jobs;
  106.     #[ORM\OneToMany(mappedBy'protocole'targetEntityJobs::class, cascade:['persist'])]
  107.     private Collection $protocole_jobs;
  108.     #[ORM\OneToMany(mappedBy'media'targetEntityUsersDocs::class)]
  109.     private Collection $usersDocs;
  110.     #[ORM\OneToMany(mappedBy'media'targetEntityFaqDocs::class)]
  111.     private Collection $faqDocs;
  112.     #[ORM\OneToMany(mappedBy'media'targetEntitySpecialMachinery::class)]
  113.     private Collection $specialMachineries;
  114.     public function __construct()
  115.     {
  116.         $this->workers = new ArrayCollection();
  117.         $this->accountJobsLists = new ArrayCollection();
  118.         $this->commandment_jobs = new ArrayCollection();
  119.         $this->graph_jobs = new ArrayCollection();
  120.         $this->protocole_jobs = new ArrayCollection();
  121.         $this->usersDocs = new ArrayCollection();
  122.         $this->faqDocs = new ArrayCollection();
  123.         $this->specialMachineries = new ArrayCollection();
  124.     }
  125.     public function getId(): ?int
  126.     
  127.         return $this->id;
  128.     }
  129.     public function getProduct(): ?Products
  130.     {
  131.         return $this->product;
  132.     }
  133.     public function setProduct(?Products $product): self
  134.     {
  135.         $this->product $product;
  136.         return $this;
  137.     }
  138.     public function getOrders(): ?Orders
  139.     {
  140.         return $this->orders;
  141.     }
  142.     public function setOrders(?Orders $orders): self
  143.     {
  144.         $this->orders $orders;
  145.         return $this;
  146.     }
  147.     public function getType(): ?string
  148.     {
  149.         return $this->type;
  150.     }
  151.     public function setType(string $type): self
  152.     {
  153.         $this->type $type;
  154.         return $this;
  155.     }
  156.     public function getName(): ?string
  157.     {
  158.         return $this->name;
  159.     }
  160.     public function setName(?string $name): self
  161.     {
  162.         $this->name $name;
  163.         return $this;
  164.     }
  165.     public function getUsers(): ?User
  166.     {
  167.         return $this->users;
  168.     }
  169.     public function setUsers(?User $users): self
  170.     {
  171.         $this->users $users;
  172.         return $this;
  173.     }
  174.     public function getAccountWorker(): ?AccountWorker
  175.     {
  176.         return $this->accountWorker;
  177.     }
  178.     public function setAccountWorker(?AccountWorker $accountWorker): self
  179.     {
  180.         $this->accountWorker $accountWorker;
  181.         return $this;
  182.     }
  183.     
  184.     public function setFormAnswer(?FormAnswer $formAnswer): self
  185.     {
  186.         $this->formAnswer $formAnswer;
  187.         return $this;
  188.     }
  189.     public function getJob(): ?Jobs
  190.     {
  191.         return $this->job;
  192.     }
  193.     public function setJob(?Jobs $job): self
  194.     {
  195.         $this->job $job;
  196.         return $this;
  197.     }
  198.     /**
  199.      * @return Collection<int, Workers>
  200.      */
  201.     public function getWorkers(): Collection
  202.     {
  203.         return $this->workers;
  204.     }
  205.     public function addWorker(Workers $worker): self
  206.     {
  207.         if (!$this->workers->contains($worker)) {
  208.             $this->workers->add($worker);
  209.             $worker->setPhoto($this);
  210.         }
  211.         return $this;
  212.     }
  213.     
  214.     /**
  215.      * @return Collection<int, UsersDocs>
  216.      */
  217.     public function getUsersDocs(): Collection
  218.     {
  219.         return $this->usersDocs;
  220.     }
  221.     public function addUsersDoc(UsersDocs $usersDoc): static
  222.     {
  223.         if (!$this->usersDocs->contains($usersDoc)) {
  224.             $this->usersDocs->add($usersDoc);
  225.             $usersDoc->setMedia($this);
  226.         }
  227.         return $this;
  228.     }
  229.     public function removeWorker(Workers $worker): self
  230.     {
  231.         if ($this->workers->removeElement($worker)) {
  232.             // set the owning side to null (unless already changed)
  233.             if ($worker->getPhoto() === $this) {
  234.                 $worker->setPhoto(null);
  235.             }
  236.         }
  237.         return $this;
  238.     }
  239.     /**
  240.      * @return Collection<int, AccountJobsList>
  241.      */
  242.     public function getAccountJobsLists(): Collection
  243.     {
  244.         return $this->accountJobsLists;
  245.     }
  246.     public function addAccountJobsList(AccountJobsList $accountJobsList): self
  247.     {
  248.         if (!$this->accountJobsLists->contains($accountJobsList)) {
  249.             $this->accountJobsLists->add($accountJobsList);
  250.             $accountJobsList->setDocument($this);
  251.         }
  252.         return $this;
  253.     }
  254.     public function removeAccountJobsList(AccountJobsList $accountJobsList): self
  255.     {
  256.         if ($this->accountJobsLists->removeElement($accountJobsList)) {
  257.             // set the owning side to null (unless already changed)
  258.             if ($accountJobsList->getDocument() === $this) {
  259.                 $accountJobsList->setDocument(null);
  260.             }
  261.         }
  262.         return $this;
  263.     }
  264.     /**
  265.      * @return Collection<int, Jobs>
  266.      */
  267.     public function getCommandmentJobs(): Collection
  268.     {
  269.         return $this->commandment_jobs;
  270.     }
  271.     public function addCommandmentJob(Jobs $commandmentJob): self
  272.     {
  273.         if (!$this->commandment_jobs->contains($commandmentJob)) {
  274.             $this->commandment_jobs->add($commandmentJob);
  275.             $commandmentJob->setCommandment($this);
  276.         }
  277.         return $this;
  278.     }
  279.     public function removeCommandmentJob(Jobs $commandmentJob): self
  280.     {
  281.         if ($this->commandment_jobs->removeElement($commandmentJob)) {
  282.             // set the owning side to null (unless already changed)
  283.             if ($commandmentJob->getCommandment() === $this) {
  284.                 $commandmentJob->setCommandment(null);
  285.             }
  286.         }
  287.         return $this;
  288.     }
  289.     /**
  290.      * @return Collection<int, Jobs>
  291.      */
  292.     public function getGraphJobs(): Collection
  293.     {
  294.         return $this->graph_jobs;
  295.     }
  296.     public function addGraphJob(Jobs $graphJob): self
  297.     {
  298.         if (!$this->graph_jobs->contains($graphJob)) {
  299.             $this->graph_jobs->add($graphJob);
  300.             $graphJob->setGraph($this);
  301.         }
  302.         return $this;
  303.     }
  304.     public function removeGraphJob(Jobs $graphJob): self
  305.     {
  306.         if ($this->graph_jobs->removeElement($graphJob)) {
  307.             // set the owning side to null (unless already changed)
  308.             if ($graphJob->getGraph() === $this) {
  309.                 $graphJob->setGraph(null);
  310.             }
  311.         }
  312.         return $this;
  313.     }
  314.     /**
  315.      * @return Collection<int, Jobs>
  316.      */
  317.     public function getProtocoleJobs(): Collection
  318.     {
  319.         return $this->protocole_jobs;
  320.     }
  321.     public function addProtocoleJob(Jobs $protocoleJob): self
  322.     {
  323.         if (!$this->protocole_jobs->contains($protocoleJob)) {
  324.             $this->protocole_jobs->add($protocoleJob);
  325.             $protocoleJob->setProtocole($this);
  326.         }
  327.         return $this;
  328.     }
  329.     public function removeProtocoleJob(Jobs $protocoleJob): self
  330.     {
  331.         if ($this->protocole_jobs->removeElement($protocoleJob)) {
  332.             // set the owning side to null (unless already changed)
  333.             if ($protocoleJob->getProtocole() === $this) {
  334.                 $protocoleJob->setProtocole(null);
  335.             }
  336.         }
  337.         return $this;
  338.     }
  339.     public function removeUsersDoc(UsersDocs $usersDoc): static
  340.     {
  341.         if ($this->usersDocs->removeElement($usersDoc)) {
  342.             // set the owning side to null (unless already changed)
  343.             if ($usersDoc->getMedia() === $this) {
  344.                 $usersDoc->setMedia(null);
  345.             }
  346.         }
  347.         return $this;
  348.     }
  349.     /**
  350.      * @return Collection<int, FaqDocs>
  351.      */
  352.     public function getFaqDocs(): Collection
  353.     {
  354.         return $this->faqDocs;
  355.     }
  356.     public function addFaqDoc(FaqDocs $faqDoc): self
  357.     {
  358.         if (!$this->faqDocs->contains($faqDoc)) {
  359.             $this->faqDocs->add($faqDoc);
  360.             $faqDoc->setMedia($this);
  361.         }
  362.         return $this;
  363.     }
  364.     public function removeFaqDoc(FaqDocs $faqDoc): self
  365.     {
  366.         if ($this->faqDocs->removeElement($faqDoc)) {
  367.             // set the owning side to null (unless already changed)
  368.             if ($faqDoc->getMedia() === $this) {
  369.                 $faqDoc->setMedia(null);
  370.             }
  371.         }
  372.         return $this;
  373.     }
  374.     /**
  375.      * @return Collection<int, SpecialMachineries>
  376.      */
  377.     public function getSpecialMachineries(): Collection
  378.     {
  379.         return $this->specialMachineries;
  380.     }
  381.     public function addSpecialMachinery(SpecialMachinery $specialMachinery): static
  382.     {
  383.         if (!$this->specialMachineries->contains($specialMachinery)) {
  384.             $this->specialMachineries->add($specialMachinery);
  385.             $specialMachinery->setMedia($this);
  386.         }
  387.         return $this;
  388.     }
  389.     public function removeSpecialMachinery(SpecialMachinery $specialMachinery): static
  390.     {
  391.         if ($this->specialMachineries->removeElement($specialMachinery)) {
  392.             // set the owning side to null (unless already changed)
  393.             if ($specialMachinery->getMedia() === $this) {
  394.                 $specialMachinery->setMedia(null);
  395.             }
  396.         }
  397.         return $this;
  398.     }
  399. }