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'])]
  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'])]
  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.     #[ORM\ManyToOne(inversedBy'media')]
  93.     private ?FormAnswer $formAnswer null;
  94.     #[Groups(['media_object:read''media_object_create'])]
  95.     #[ORM\Column(length100nullabletrue)]
  96.     private ?string $code1c null;
  97.     public function __construct()
  98.     {
  99.     }
  100.     public function getId(): ?int
  101.     
  102.         return $this->id;
  103.     }
  104.     public function getProduct(): ?Products
  105.     {
  106.         return $this->product;
  107.     }
  108.     public function setProduct(?Products $product): self
  109.     {
  110.         $this->product $product;
  111.         return $this;
  112.     }
  113.     public function getOrders(): ?Orders
  114.     {
  115.         return $this->orders;
  116.     }
  117.     public function setOrders(?Orders $orders): self
  118.     {
  119.         $this->orders $orders;
  120.         return $this;
  121.     }
  122.     public function getType(): ?string
  123.     {
  124.         return $this->type;
  125.     }
  126.     public function setType(string $type): self
  127.     {
  128.         $this->type $type;
  129.         return $this;
  130.     }
  131.     public function getName(): ?string
  132.     {
  133.         return $this->name;
  134.     }
  135.     public function setName(?string $name): self
  136.     {
  137.         $this->name $name;
  138.         return $this;
  139.     }
  140.     public function getUsers(): ?User
  141.     {
  142.         return $this->users;
  143.     }
  144.     public function setUsers(?User $users): self
  145.     {
  146.         $this->users $users;
  147.         return $this;
  148.     }
  149.     public function getAccountWorker(): ?AccountWorker
  150.     {
  151.         return $this->accountWorker;
  152.     }
  153.     public function setAccountWorker(?AccountWorker $accountWorker): self
  154.     {
  155.         $this->accountWorker $accountWorker;
  156.         return $this;
  157.     }
  158.     
  159.     public function setFormAnswer(?FormAnswer $formAnswer): self
  160.     {
  161.         $this->formAnswer $formAnswer;
  162.         return $this;
  163.     }
  164.     public function getCode1c(): ?string
  165.     {
  166.         return $this->code1c;
  167.     }
  168.     public function setCode1c(?string $code1c): static
  169.     {
  170.         $this->code1c $code1c;
  171.         return $this;
  172.     }
  173. }