src/Entity/MediaObject/MediaImage.php line 41

Open in your IDE?
  1. <?php
  2. namespace App\Entity\MediaObject;
  3. use ApiPlatform\Core\Annotation\ApiProperty;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Repository\MediaObject\MediaImageRepository;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Serializer\Annotation\SerializedName;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  12. /**
  13.  * @ApiResource(
  14.  *     attributes={
  15.  *          "normalization_context"={"groups"={
  16.  *              "media_object_read",
  17.  *              "MediaImage:output",
  18.  *              "MediaImage:io",
  19.  *          }},
  20.  *          "denormalization_context"={"groups"={
  21.  *              "media_object_read",
  22.  *              "MediaImage:input",
  23.  *              "MediaImage:io",
  24.  *          }}
  25.  *      },
  26.  *     iri="http://schema.org/MediaImage",
  27.  *     collectionOperations={
  28.  *         "get"
  29.  *     },
  30.  *     itemOperations={
  31.  *         "get"
  32.  *     }
  33.  * )
  34.  *
  35.  * @ORM\Entity(repositoryClass=MediaImageRepository::class)
  36.  * @Vich\Uploadable
  37.  */
  38. class MediaImage extends MediaObject
  39. {
  40.     /**
  41.      * @var string|null
  42.      * @ORM\JoinColumn(nullable=true, name="object_id")
  43.      */
  44.     private ?string $object_id null;
  45.     /**
  46.      * @var string|null
  47.      * @ApiProperty(iri="http://schema.org/contentUrl")
  48.      * @SerializedName("content_url")
  49.      * @Groups({
  50.      *     "MediaObject:output",
  51.      *     "MediaImage:output",
  52.      *     "media_object_read",
  53.      * })
  54.      */
  55.     private $contentUrl;
  56.     /**
  57.      * @var File|null
  58.      * @Assert\NotNull(
  59.      *     groups={
  60.      *     "media_object_read",
  61.      *     "MediaImage:io",
  62.      *     "MediaObject:output",
  63.      * })
  64.      * @Assert\File(
  65.      *     maxSize = "500k",
  66.      *     mimeTypes = {"image/jpeg", "image/jpg", "image/png", "image/gif"},
  67.      *     maxSizeMessage = "La taille de l'image maximale autorisée est de 500 Ko.",
  68.      *     mimeTypesMessage = "Seules les images au format .jpeg / .jpg / .png / .gif sont autorisées."
  69.      * )
  70.      * @Vich\UploadableField(mapping="library_image", fileNameProperty="filePath")
  71.      * @Groups({
  72.      *     "MediaImage:output",
  73.      * })
  74.      */
  75.     public $file;
  76.     /**
  77.      * @var string|null
  78.      *
  79.      * @ORM\Column(nullable=true)
  80.      * @SerializedName("file_path")
  81.      * @Groups({
  82.      *     "MediaImage:output",
  83.      * })
  84.      */
  85.     public $filePath;
  86.     /**
  87.      * @return string|null
  88.      */
  89.     public function getContentUrl(): ?string
  90.     {
  91.         return $this->contentUrl;
  92.     }
  93.     /**
  94.      * @param string|null $contentUrl
  95.      * @return MediaImage
  96.      */
  97.     public function setContentUrl(?string $contentUrl): MediaImage
  98.     {
  99.         $this->contentUrl $contentUrl;
  100.         return $this;
  101.     }
  102.     /**
  103.      * @return string|null
  104.      */
  105.     public function getObjectId(): ?string
  106.     {
  107.         return $this->object_id;
  108.     }
  109.     /**
  110.      * @param string|null $object_id
  111.      * @return MediaImage
  112.      */
  113.     public function setObjectId(?string $object_id): MediaImage
  114.     {
  115.         $this->contentUrl $object_id;
  116.         return $this;
  117.     }
  118. }