<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Entity\File as EmbeddedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass="App\Repository\MediaImageRepository")
* @ORM\HasLifecycleCallbacks()
* @Vich\Uploadable
*/
#[ApiResource(
normalizationContext: ['groups' => ['mediaImage:read']],
denormalizationContext: ['groups' => ['mediaImage:write']],
collectionOperations: [
'get',
'post' => [
'input_formats' => [
'multipart' => ['multipart/form-data'],
],
],
],
)]
#[ApiFilter(SearchFilter::class, properties: ['id', 'pinpointCampaigns' => 'exact', 'imageAlt' => 'partial'])]
#[ApiFilter(PropertyFilter::class)]
#[ApiFilter(OrderFilter::class, properties: ['id', 'imageAlt', 'updatedAt'], arguments: ['orderParameterName' => 'order'])]
class MediaImage
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
#[ApiProperty(identifier: true)]
private $id;
/**
* @var string
*
* @ORM\Column(type="string", length=1000, nullable=true)
* @Groups({"mediaImage:read","mediaImage:write","pinpointCampaign:list"})
*/
private $loginTextTop;
/**
* @var string
*
* @ORM\Column(type="string", length=1000, nullable=true)
* @Groups({"mediaImage:read","mediaImage:write","pinpointCampaign:list"})
*/
private $loginTextBottom;
/**
* @var string
*
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"mediaImage:read","mediaImage:write","pinpointCampaign:list"})
*/
private $imageAlt;
#[ApiProperty(iri: 'http://schema.org/contentUrl')]
#[Groups(['mediaImage:read', 'pinpointCampaign:list'])]
public ?string $imageUrl = null;
/**
* @ORM\Embedded(class="Vich\UploaderBundle\Entity\File")
*/
private $image;
/**
* @Vich\UploadableField(mapping="pinpoint_image", fileNameProperty="image.name", size="image.size", mimeType="image.mimeType", originalName="image.originalName", dimensions="image.dimensions")
* @Assert\Image(maxSize="8M", mimeTypes={"image/jpeg", "image/png", "image/gif"})
* @Assert\Expression(expression="this.getImageFile() or this.getImage().getName()")
*/
#[Groups(['mediaImage:write'])]
public ?File $imageFile = null;
#[ORM\Column(type: 'datetime')]
#[Groups(['mediaImage:read'])]
private ?\DateTimeInterface $updatedAt = null;
/**
* @ORM\OneToMany(targetEntity=PinpointCampaign::class, mappedBy="image")
* @Groups({"mediaImage:read","mediaImage:write"})
*/
private $pinpointCampaigns;
public function __construct()
{
$this->image = new EmbeddedFile();
$this->pinpointCampaigns = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
// #########################################################################
public function getLoginTextTop(): ?string
{
return $this->loginTextTop;
}
public function setLoginTextTop(string $loginTextTop): self
{
$this->loginTextTop = $loginTextTop;
return $this;
}
public function getLoginTextBottom(): ?string
{
return $this->loginTextBottom;
}
public function setLoginTextBottom(string $loginTextBottom): self
{
$this->loginTextBottom = $loginTextBottom;
return $this;
}
// #######################################################################
public function getImageAlt(): ?string
{
return $this->imageAlt;
}
public function setImageAlt(string $imageAlt): self
{
$this->imageAlt = $imageAlt;
return $this;
}
public function getImage(): EmbeddedFile
{
return $this->image;
}
public function setImage(EmbeddedFile $image): self
{
$this->image = $image;
return $this;
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
/**
* @param File|null $image
*
* @throws Exception
*/
public function setImageFile(?File $imageFile = null): self
{
$this->imageFile = $imageFile;
if (null !== $imageFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTimeImmutable();
}
return $this;
}
/**
* @return Collection<int, PinpointCampaign>
*/
public function getPinpointCampaigns(): Collection
{
return $this->pinpointCampaigns;
}
public function addPinpointCampaign(PinpointCampaign $pinpointCampaign): self
{
if (!$this->pinpointCampaigns->contains($pinpointCampaign)) {
$this->pinpointCampaigns[] = $pinpointCampaign;
$pinpointCampaign->setImage($this);
}
return $this;
}
public function removePinpointCampaign(PinpointCampaign $pinpointCampaign): self
{
if ($this->pinpointCampaigns->removeElement($pinpointCampaign)) {
// set the owning side to null (unless already changed)
if ($pinpointCampaign->getImage() === $this) {
$pinpointCampaign->setImage(null);
}
}
return $this;
}
/**
* @Groups({"mediaImage:read"})
* Returns updatedAt.
*/
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
}