src/Entity/MediaObject.php line 135

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiFilter;
  4. use ApiPlatform\Metadata\ApiProperty;
  5. use ApiPlatform\Metadata\ApiResource;
  6. use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
  7. use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
  8. use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  9. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  10. use ApiPlatform\Metadata\Put;
  11. use ApiPlatform\Metadata\Post;
  12. use ApiPlatform\Metadata\Get;
  13. use ApiPlatform\Metadata\GetCollection;
  14. use ApiPlatform\Metadata\Patch;
  15. use ApiPlatform\Metadata\Delete;
  16. use App\Controller\CreateMediaObjectAction;
  17. use App\Controller\UpdateMediaObjectAction;
  18. use App\Action\MediaAction;
  19. use App\Repository\MediaObjectRepository;
  20. use DateTime;
  21. use DateTimeInterface;
  22. use Doctrine\ORM\Mapping as ORM;
  23. use Symfony\Component\HttpFoundation\File\File;
  24. use Symfony\Component\Serializer\Annotation\Groups;
  25. use Symfony\Component\Validator\Constraints as Assert;
  26. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  27. #[ApiResource(
  28.     security"is_granted('ROLE_USER')",
  29.     types: [""],
  30.     normalizationContext: [
  31.         'groups' => 'media_object_read'
  32.     ],
  33.     operations: [
  34.         new Get(),
  35.         new GetCollection(),
  36.         new Put(security"is_granted('ROLE_USER')",),
  37.         new Patch(security"is_granted('ROLE_USER')",),
  38.         new Delete(security"is_granted('ROLE_USER')",),
  39.         new Post(
  40.             security"is_granted('ROLE_USER')",
  41.             controllerCreateMediaObjectAction::class,
  42.             deserializefalse,
  43.             validationContext: [],
  44.             openapiContext: [
  45.                 "requestBody" => [
  46.                     "content" => [
  47.                         "multipart/form-data" => [
  48.                             "schema" => [
  49.                                 "type" => "object",
  50.                                 "properties" => [
  51.                                     "file" => [
  52.                                         "type" => "string",
  53.                                         "format" => "binary"
  54.                                     ]
  55.                                 ]
  56.                             ]
  57.                         ]
  58.                     ]
  59.                 ]
  60.             ]
  61.         ),
  62.         new Post(
  63.             security"is_granted('ROLE_USER')",
  64.             name"replace_image",
  65.             controllerUpdateMediaObjectAction::class,
  66.             deserializefalse,
  67.             uriTemplate"/media_objects/{id}",
  68.             validationContext: ["Default""media_object_update"],
  69.             openapiContext: [
  70.                 "parameters" => [
  71.                     [
  72.                         "name" => "id",
  73.                         "in" => "uriTemplate",
  74.                         "type" => "string",
  75.                         "required" => true,
  76.                     ]
  77.                 ],
  78.                 "requestBody" => [
  79.                     "content" => [
  80.                         "multipart/form-data" => [
  81.                             "schema" => [
  82.                                 "type" => "object",
  83.                                 "properties" => [
  84.                                     "file" => [
  85.                                         "type" => "string",
  86.                                         "format" => "binary"
  87.                                     ]
  88.                                 ]
  89.                             ]
  90.                         ]
  91.                     ]
  92.                 ]
  93.             ]
  94.         ),
  95.         new Post(
  96.             security"is_granted('ROLE_USER')",
  97.             name"get_size",
  98.             controllerMediaAction::class,
  99.             uriTemplate"/media_objects/resize/{id}/{size}",
  100.             openapiContext: [
  101.                 "parameters" => [
  102.                     [
  103.                         "name" => "User Login",
  104.                         "in" => "body",
  105.                         "required" => true,
  106.                         "schema" => [
  107.                             "type" => "object",
  108.                             "required" => [
  109.                                 "email",
  110.                                 "password"
  111.                             ],
  112.                             "properties" => [
  113.                                 "email" => ["type" => "string"],
  114.                                 "password" => ["type" => "string"]
  115.                             ]
  116.                         ]
  117.                     ]
  118.                 ]
  119.             ]
  120.         ),
  121.     ],
  122. )]
  123. #[Vich\Uploadable]
  124. #[GetCollection]
  125. #[ApiFilter(OrderFilter::class)]
  126. #[ApiFilter(DateFilter::class, properties: ["createdAt"])]
  127. #[ApiFilter(SearchFilter::class, properties: ["id" => "exact""filePath" => "partial"])]
  128. #[ORM\Entity(repositoryClassMediaObjectRepository::class)]
  129. #[ORM\HasLifecycleCallbacks]
  130. class MediaObject
  131. {
  132.     /**
  133.      * @var int|null
  134.      */
  135.     #[ORM\Column(type\Doctrine\DBAL\Types\Types::INTEGER)]
  136.     #[ORM\GeneratedValue]
  137.     #[ORM\Id]
  138.     protected ?int $id null;
  139.     /**
  140.      * @var string|null
  141.      */
  142.     #[ApiProperty(types: ["https://schema.org/contentUrl"])]
  143.     #[Groups(['media_object_read''product:read'])]
  144.     public $contentUrl;
  145.     /**
  146.      * @var File|null   
  147.      *
  148.      */
  149.     #[Vich\UploadableField(mapping"media_object"fileNameProperty"filePath")]
  150.     #[Assert\NotNull(groups: ['media_object_create''media_object_update'])]
  151.     #[Groups(['product:read'])]
  152.     public $file;
  153.     /**
  154.      * @var string|null
  155.      */
  156.     #[Groups(['media_object_read''product:read'])]
  157.     #[ORM\Column(nullabletrue)]
  158.     public $filePath;
  159.     public function getId(): ?int
  160.     {
  161.         return $this->id;
  162.     }
  163.     
  164.     public function getFilename(): ?string
  165.     {
  166.         return $this->filename;
  167.     }
  168.     public function setFilename(string $filename): self
  169.     {
  170.         $this->filename $filename;
  171.         return $this;
  172.     }
  173.     public function getAlt(): ?string
  174.     {
  175.         return $this->alt;
  176.     }
  177.     public function setAlt(?string $alt): self
  178.     {
  179.         $this->alt $alt;
  180.         return $this;
  181.     }
  182.     public function getFiletype(): ?string
  183.     {
  184.         return $this->filetype;
  185.     }
  186.     public function setFiletype(string $filetype): self
  187.     {
  188.         $this->filetype $filetype;
  189.         return $this;
  190.     }
  191.     public function getFilesize(): ?int
  192.     {
  193.         return $this->filesize;
  194.     }
  195.     public function setFilesize(?int $filesize): self
  196.     {
  197.         $this->filesize $filesize;
  198.         return $this;
  199.     }
  200.     public function getFilePath(): ?string
  201.     {
  202.         return $this->filePath;
  203.     }
  204.     public function setFilePath(?string $filePath): self
  205.     {
  206.         $this->filePath $filePath;
  207.         return $this;
  208.     }
  209. }