src/Entity/MediaImage.php line 40

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiProperty;
  5. use ApiPlatform\Core\Annotation\ApiResource;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  8. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Symfony\Component\HttpFoundation\File\File;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. use Vich\UploaderBundle\Entity\File as EmbeddedFile;
  16. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  17. /**
  18.  * @ORM\Entity(repositoryClass="App\Repository\MediaImageRepository")
  19.  * @ORM\HasLifecycleCallbacks()
  20.  * @Vich\Uploadable
  21.  */
  22. #[ApiResource(
  23.     normalizationContext: ['groups' => ['mediaImage:read']],
  24.     denormalizationContext: ['groups' => ['mediaImage:write']],
  25.     collectionOperations: [
  26.         'get',
  27.         'post' => [
  28.             'input_formats' => [
  29.                 'multipart' => ['multipart/form-data'],
  30.             ],
  31.         ],
  32.     ],
  33. )]
  34. #[ApiFilter(SearchFilter::class, properties: ['id''pinpointCampaigns' => 'exact''imageAlt' => 'partial'])]
  35. #[ApiFilter(PropertyFilter::class)]
  36. #[ApiFilter(OrderFilter::class, properties: ['id''imageAlt''updatedAt'], arguments: ['orderParameterName' => 'order'])]
  37. class MediaImage
  38. {
  39.     /**
  40.      * @ORM\Id()
  41.      * @ORM\GeneratedValue()
  42.      * @ORM\Column(type="integer")
  43.      */
  44.     #[ApiProperty(identifiertrue)]
  45.     private $id;
  46.     /**
  47.      * @var string
  48.      *
  49.      * @ORM\Column(type="string", length=1000, nullable=true)
  50.      * @Groups({"mediaImage:read","mediaImage:write","pinpointCampaign:list"})
  51.      */
  52.     private $loginTextTop;
  53.     /**
  54.      * @var string
  55.      *
  56.      * @ORM\Column(type="string", length=1000, nullable=true)
  57.      * @Groups({"mediaImage:read","mediaImage:write","pinpointCampaign:list"})
  58.      */
  59.     private $loginTextBottom;
  60.     /**
  61.      * @var string
  62.      *
  63.      * @ORM\Column(type="string", length=255, nullable=true)
  64.      * @Groups({"mediaImage:read","mediaImage:write","pinpointCampaign:list"})
  65.      */
  66.     private $imageAlt;
  67.     #[ApiProperty(iri'http://schema.org/contentUrl')]
  68.     #[Groups(['mediaImage:read''pinpointCampaign:list'])]
  69.     public ?string $imageUrl null;
  70.     /**
  71.      * @ORM\Embedded(class="Vich\UploaderBundle\Entity\File")
  72.      */
  73.     private $image;
  74.     /**
  75.      * @Vich\UploadableField(mapping="pinpoint_image", fileNameProperty="image.name", size="image.size", mimeType="image.mimeType", originalName="image.originalName", dimensions="image.dimensions")
  76.      * @Assert\Image(maxSize="8M", mimeTypes={"image/jpeg", "image/png", "image/gif"})
  77.      * @Assert\Expression(expression="this.getImageFile() or this.getImage().getName()")
  78.      */
  79.     #[Groups(['mediaImage:write'])]
  80.     public ?File $imageFile null;
  81.     #[ORM\Column(type'datetime')]
  82.     #[Groups(['mediaImage:read'])]
  83.     private ?\DateTimeInterface $updatedAt null;
  84.     /**
  85.      * @ORM\OneToMany(targetEntity=PinpointCampaign::class, mappedBy="image")
  86.      * @Groups({"mediaImage:read","mediaImage:write"})
  87.      */
  88.     private $pinpointCampaigns;
  89.     public function __construct()
  90.     {
  91.         $this->image = new EmbeddedFile();
  92.         $this->pinpointCampaigns = new ArrayCollection();
  93.     }
  94.     public function getId(): ?int
  95.     {
  96.         return $this->id;
  97.     }
  98.     // #########################################################################
  99.     public function getLoginTextTop(): ?string
  100.     {
  101.         return $this->loginTextTop;
  102.     }
  103.     public function setLoginTextTop(string $loginTextTop): self
  104.     {
  105.         $this->loginTextTop $loginTextTop;
  106.         return $this;
  107.     }
  108.     public function getLoginTextBottom(): ?string
  109.     {
  110.         return $this->loginTextBottom;
  111.     }
  112.     public function setLoginTextBottom(string $loginTextBottom): self
  113.     {
  114.         $this->loginTextBottom $loginTextBottom;
  115.         return $this;
  116.     }
  117.     // #######################################################################
  118.     public function getImageAlt(): ?string
  119.     {
  120.         return $this->imageAlt;
  121.     }
  122.     public function setImageAlt(string $imageAlt): self
  123.     {
  124.         $this->imageAlt $imageAlt;
  125.         return $this;
  126.     }
  127.     public function getImage(): EmbeddedFile
  128.     {
  129.         return $this->image;
  130.     }
  131.     public function setImage(EmbeddedFile $image): self
  132.     {
  133.         $this->image $image;
  134.         return $this;
  135.     }
  136.     public function getImageFile(): ?File
  137.     {
  138.         return $this->imageFile;
  139.     }
  140.     /**
  141.      * @param File|null $image
  142.      *
  143.      * @throws Exception
  144.      */
  145.     public function setImageFile(?File $imageFile null): self
  146.     {
  147.         $this->imageFile $imageFile;
  148.         if (null !== $imageFile) {
  149.             // It is required that at least one field changes if you are using doctrine
  150.             // otherwise the event listeners won't be called and the file is lost
  151.             $this->updatedAt = new \DateTimeImmutable();
  152.         }
  153.         return $this;
  154.     }
  155.     /**
  156.      * @return Collection<int, PinpointCampaign>
  157.      */
  158.     public function getPinpointCampaigns(): Collection
  159.     {
  160.         return $this->pinpointCampaigns;
  161.     }
  162.     public function addPinpointCampaign(PinpointCampaign $pinpointCampaign): self
  163.     {
  164.         if (!$this->pinpointCampaigns->contains($pinpointCampaign)) {
  165.             $this->pinpointCampaigns[] = $pinpointCampaign;
  166.             $pinpointCampaign->setImage($this);
  167.         }
  168.         return $this;
  169.     }
  170.     public function removePinpointCampaign(PinpointCampaign $pinpointCampaign): self
  171.     {
  172.         if ($this->pinpointCampaigns->removeElement($pinpointCampaign)) {
  173.             // set the owning side to null (unless already changed)
  174.             if ($pinpointCampaign->getImage() === $this) {
  175.                 $pinpointCampaign->setImage(null);
  176.             }
  177.         }
  178.         return $this;
  179.     }
  180.     /**
  181.      * @Groups({"mediaImage:read"})
  182.      * Returns updatedAt.
  183.      */
  184.     public function getUpdatedAt(): ?\DateTimeInterface
  185.     {
  186.         return $this->updatedAt;
  187.     }
  188. }