<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Controller\Agent\Property\ArchivePropertyImageController;
use App\Controller\Agent\Property\CreatePropertyImagesAction;
use App\Controller\Agent\Property\UpdatePositionPropertyImagesAction;
use App\Repository\PropertyImagesRepository;
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\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=PropertyImagesRepository::class)
* @Vich\Uploadable
* @ApiResource(
* iri= "https://schema.org/PropertyImages",
* normalizationContext= {"groups" = {"property_images:read"},"swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"property_images:write"}, "swagger_definition_name"="Write"},
* itemOperations= {
* "get"={
* "security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')"
* },
* "archive_property_image"={
* "denormalization_context"={"groups"={"property_images:archive"}},
* "security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
* "method"="PATCH",
* "path"="/property_image/{id}/archive",
* "controller"=ArchivePropertyImageController::class,
* "read"=true,
* "write"=false,
* },
* "update_position_property_image"={
* "denormalization_context"={"groups"={"property_images:update_position"}},
* "security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
* "method"="PATCH",
* "path"="/property_image/update_position/{property}",
* "controller"=UpdatePositionPropertyImagesAction::class,
* "read"=false,
* "write"=false,
* "input_formats"={"json"={"application/ld+json","application/merge-patch+json", "application/json" }},
* "output_formats"={"json"={"application/ld+json", "application/json"}}
* }
* },
* collectionOperations= {
* "get"={"security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')" },
* "post" = {
* "controller" = CreatePropertyImagesAction::class,
* "deserialize" = false,
* "security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER') ",
* "validation_groups" = {"Default", "property_images_create"},
* "openapi_context" = {
* "requestBody" = {
* "content" = {
* "multipart/form-data" = {
* "schema" = {
* "type" = "object",
* "properties" = {
* "file" = {
* "type" = "string",
* "format" = "binary",
* },
* "property"={
* "type"="integer"
* }
* },
* },
* },
* },
* },
* },
* },
* }
* )}
*/
class PropertyImages
{
public const PROPERTY_IMAGE_ARCHIVED = true;
public const PROPERTY_IMAGE_UNARCHIVED = false;
public const PROPERTY_IMAGE_PATH = '/public/property_images/';
/**
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
* @ORM\Id
* @Groups({"property_images:read","property:read","milkiya:read"})
*/
private ?int $id = null;
/**
* @Groups({"property:read","milkiya:read"})
*/
public ?string $contentUrl = null;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Property", inversedBy="images")
* @ORM\JoinColumn(nullable=false)
* @Groups({"property_images:read", "property_images:write"})
*/
private ?Property $property;
/**
* @Vich\UploadableField(mapping="property_images", fileNameProperty="filePath")
* @Assert\Image(
* maxSizeMessage = "File exceeds allowed size",
* mimeTypesMessage = "Please upload a valid file"
* )
*/
public ?File $file = null;
/**
* @ORM\Column(nullable=true)
* @Groups({"property:read","milkiya:read"})
*/
public ?string $filePath = null;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $archived;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"property_images:read","property:read","milkiya:read"})
*/
private $position;
public function getId(): ?int
{
return $this->id;
}
/**
* @return string|null
*/
public function getFilePath(): ?string
{
return $this->filePath;
}
/**
* @param string|null $filePath
* @return $this
*/
public function setFilePath(?string $filePath): self
{
$this->filePath = $filePath;
return $this;
}
/**
* @return Property|null
*/
public function getProperty(): ?Property
{
return $this->property;
}
/**
* @param Property|null $property
* @return $this
*/
public function setProperty(?Property $property): self
{
$this->property = $property;
return $this;
}
public function getArchived(): ?bool
{
return $this->archived;
}
public function setArchived(?bool $archived): self
{
$this->archived = $archived;
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(?int $position): self
{
$this->position = $position;
return $this;
}
}