src/Entity/Album.php line 48

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Controller\CreateMediaObjectAction;
  5. use App\Repository\AlbumRepository;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. /**
  12.  * @Vich\Uploadable
  13.  */
  14. #[ORM\Entity(repositoryClassAlbumRepository::class)]
  15. #[ApiResource(
  16.     iri'http://schema.org/Albums',
  17.     normalizationContext: ['groups' => ['media_object:read']],
  18.     itemOperations: ['get'],
  19.     collectionOperations: [
  20.         'get',
  21.         'post' => [
  22.             'controller' => CreateMediaObjectAction::class,
  23.             'deserialize' => false,
  24.             'validation_groups' => ['Default''media_object_create'],
  25.             'openapi_context' => [
  26.                 'requestBody' => [
  27.                     'content' => [
  28.                         'multipart/form-data' => [
  29.                             'schema' => [
  30.                                 'type' => 'object',
  31.                                 'properties' => [
  32.                                     'file' => [
  33.                                         'type' => 'string',
  34.                                         'format' => 'binary',
  35.                                     ],
  36.                                 ],
  37.                             ],
  38.                         ],
  39.                     ],
  40.                 ],
  41.             ],
  42.         ],
  43.     ]
  44. )]
  45. class Album
  46. {
  47.     #[ORM\Id]
  48.     #[ORM\GeneratedValue]
  49.     #[ORM\Column(type'integer')]
  50.     #[Groups(['pitch:read'])]
  51.     private $id;
  52.     #[Groups(['media_object:read','pitch:read','favoris:read','reservation:read'])]
  53.     public $url;
  54.     #[ORM\Column(type'string'length100)]
  55.     #[Groups(['media_object:read','pitch:read','favoris:read','reservation:read'])]
  56.     private $name;
  57.     /**
  58.      * @Vich\UploadableField(mapping="albums_pitch", fileNameProperty="name")
  59.      */
  60.     #[Assert\NotNull(groups: ['media_object_create'])]
  61.     public ?File $file null;
  62.     #[ORM\ManyToOne(targetEntityPitch::class, inversedBy'albums',cascade:["persist"])]
  63.     private $pitch;
  64.     public function getId(): ?int
  65.     {
  66.         return $this->id;
  67.     }
  68.     public function getUrl(): ?string
  69.     {
  70.         return $this->url;
  71.     }
  72.     public function setUrl(string $url): self
  73.     {
  74.         $this->url $url;
  75.         return $this;
  76.     }
  77.     public function getName(): ?string
  78.     {
  79.         return $this->name;
  80.     }
  81.     public function setName(string $name): self
  82.     {
  83.         $this->name $name;
  84.         return $this;
  85.     }
  86.     public function getPitch(): ?Pitch
  87.     {
  88.         return $this->pitch;
  89.     }
  90.     public function setPitch(?Pitch $pitch): self
  91.     {
  92.         $this->pitch $pitch;
  93.         return $this;
  94.     }
  95. }