<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\AvatarRepository;
use App\Controller\Agent\Agent\UploadAvatarFileController;
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;
/**
* @Vich\Uploadable
* @ApiResource(
* iri= "https://schema.org/collaborator/avatar",
* normalizationContext = {"groups" = {"avatar:read"} },
* denormalizationContext={"groups" = {"avatar:write"}, "swagger_definition_name"="Write"},
* itemOperations= {
* "get"={
* "security" = "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
* "path" = "/collaborator/avatar/{id}"
* },
* "delete" = {
* "security" = "is_granted('ROLE_MANAGER')",
* "path" = "/collaborator/avatar/{id}"
* }
* },
* collectionOperations= {
* "get"={"security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER') "},
* "post" = {
* "path"="/collaborator/avatar",
* "security"="is_granted('ROLE_MANAGER') ",
* "controller" = UploadAvatarFileController::class,
* "deserialize" = false,
* "validation_groups" = {"Default", "property_images_create"},
* "openapi_context" = {
* "requestBody" = {
* "content" = {
* "multipart/form-data" = {
* "schema" = {
* "type" = "object",
* "properties" = {
* "file" = {
* "type" = "string",
* "format" = "binary",
* },
* "collaborator" = {
* "type"="integer"
* }
* },
* },
* },
* },
* },
* },
* },
* }
* )}
* @ORM\Entity(repositoryClass=AvatarRepository::class)
*/
class Avatar
{
public const AVATAR_PATH = "/collaborator/avatar/";
/**
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
* @ORM\Id
* @Groups({"avatar:read","agent:read","abstract-collaborator:read","directory:collaborator:search"})
*/
private ?int $id = null;
/**
* @Vich\UploadableField(mapping="avatar_file", fileNameProperty="filePath")
* @Assert\File(
* maxSize = "10M",
* maxSizeMessage = "File exceeds allowed size",
* mimeTypes = {"image/png", "image/jpeg", "image/jpg"},
* mimeTypesMessage = "Please upload a valid format"
* )
*/
public ?File $file = null;
public ?string $contentUrl = null;
/**
* @ORM\Column(nullable=true)
* @Groups({"avatar:read","agent:read","abstract-collaborator:read","directory:collaborator:search", "milkiya:read"})
*/
public ?string $filePath = null;
/**
* @ORM\OneToOne(targetEntity=AbstractCollaborator::class, inversedBy="avatar")
*/
private ?AbstractCollaborator $collaborator;
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;
}
public function getCollaborator(): ?AbstractCollaborator
{
return $this->collaborator;
}
public function setCollaborator(?AbstractCollaborator $collaborator): self
{
$this->collaborator = $collaborator;
return $this;
}
}