<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Controller\Agent\Agent\AgentIdentityVerificationImageShowController;
use App\Controller\Agent\Agent\AgentIdentityVerificationImageUploadController;
use App\Controller\Agent\Sponsorship\CandidateIdentityVerificationImageShowController;
use App\Controller\Agent\Sponsorship\CandidateIdentityVerificationImageUploadController;
use App\Repository\IdentityVerificationImageRepository;
use Doctrine\ORM\Mapping as ORM;
use InvalidArgumentException;
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/IdentityVerificationImages",
* normalizationContext = {"groups" = {"identity-verification:read"} },
* denormalizationContext={"groups" = {"identity-verification:write"}, "swagger_definition_name"="Write"},
* itemOperations= {
* "get_candidate"={
* "security" = "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
* "path" = "/candidate/identity_documents/upload/{id}",
* "controller" = CandidateIdentityVerificationImageShowController::class,
* "method"="GET"
* },
* "get_agent"={
* "security" = "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
* "path" = "/agent/identity_documents/upload/{id}",
* "controller" = AgentIdentityVerificationImageShowController::class,
* "method"="GET"
* },
* "delete_candidate" = {
* "security" = "is_granted('ROLE_MANAGER')",
* "path" = "/candidate/identity_documents/delete/{id}",
* "method"="DELETE",
* },
* "delete_agent" = {
* "security" = "is_granted('ROLE_MANAGER')",
* "path" = "/agent/identity_documents/delete/{id}",
* "method"="DELETE"
* }
* },
* collectionOperations= {
* "get"={"security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER') " },
* "post_candidate" = {
* "path"="/candidate/identity_documents/upload",
* "method"="post",
* "security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER') ",
* "controller" = CandidateIdentityVerificationImageUploadController::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",
* },
* "peopleId" = {
* "type"="integer"
* }
* },
* },
* },
* },
* },
* },
* },
*
* "post_agent" = {
* "path"="/agent/identity_documents/upload",
* "method"="post",
* "security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER') ",
* "controller" = AgentIdentityVerificationImageUploadController::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",
* },
* "peopleId" = {
* "type"="integer"
* }
* },
* },
* },
* },
* },
* },
* },
* }
* )
* @ORM\Entity(repositoryClass=IdentityVerificationImageRepository::class)
*/
class IdentityVerificationImage
{
public const REFERENCE_IDENTITY_TYPE_ID_CARD = 'reference.image.type.ID_CARD';
public const ALL_REFERENCE_IDENTITY_TYPE = [self::REFERENCE_IDENTITY_TYPE_ID_CARD];
/**
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
* @ORM\Id
* @Groups({
* "identity-verification:read","candidate:read",
* "directory:collaborator:search",
* "abstract-collaborator:read",
* "agent:read",
* })
*/
private ?int $id = null;
/**
* @Groups({
* "candidate:read"
* })
*/
public ?string $contentUrl = null;
/**
* @Vich\UploadableField(mapping="identity_images", fileNameProperty="filePath")
* @Assert\File(
* maxSizeMessage = "File exceeds allowed size",
* mimeTypes = {"image/png","image/jpeg","image/webp"},
* mimeTypesMessage = "Please upload a valid file"
* )
*/
public ?File $file = null;
/**
* @ORM\Column(nullable=true)
* @Groups({
* "identity-verification:read","candidate:read",
* "directory:collaborator:search",
* "abstract-collaborator:read",
* "agent:read",
* })
*/
public ?string $filePath = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({
* "identity-verification:read","candidate:read",
* "directory:collaborator:search",
* "abstract-collaborator:read",
* "agent:read",
* })
*/
public ?string $type;
/**
* @ORM\ManyToOne(targetEntity=Candidate::class, inversedBy="identityFiles")
*/
private ?Candidate $candidate = null;
/**
* @ORM\ManyToOne(targetEntity=Agent::class, inversedBy="identityFiles")
*/
private ?Agent $agent = null;
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 getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
if ($type != self::REFERENCE_IDENTITY_TYPE_ID_CARD) {
throw new InvalidArgumentException("Invalid identity type $type");
}
$this->type = $type;
return $this;
}
public function getCandidate(): ?Candidate
{
return $this->candidate;
}
public function setCandidate(?Candidate $candidate): self
{
$this->candidate = $candidate;
return $this;
}
public function getAgent(): ?Agent
{
return $this->agent;
}
public function setAgent(?Agent $agent): self
{
$this->agent = $agent;
return $this;
}
public static function getPath(string $basePath , string $directory, IdentityVerificationImage $identityVerification): string
{
return sprintf('%s/%s/%s', $basePath, $directory, $identityVerification->getFilePath());
}
}