src/Entity/IdentityVerificationImage.php line 111

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Controller\Agent\Agent\AgentIdentityVerificationImageShowController;
  5. use App\Controller\Agent\Agent\AgentIdentityVerificationImageUploadController;
  6. use App\Controller\Agent\Sponsorship\CandidateIdentityVerificationImageShowController;
  7. use App\Controller\Agent\Sponsorship\CandidateIdentityVerificationImageUploadController;
  8. use App\Repository\IdentityVerificationImageRepository;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use InvalidArgumentException;
  11. use Symfony\Component\HttpFoundation\File\File;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  15. /**
  16.  * @Vich\Uploadable
  17.  * @ApiResource(
  18.  *   iri= "https://schema.org/IdentityVerificationImages",
  19.  *   normalizationContext = {"groups" = {"identity-verification:read"} },
  20.  *   denormalizationContext={"groups" = {"identity-verification:write"}, "swagger_definition_name"="Write"},
  21.  *   itemOperations= {
  22.  *          "get_candidate"={
  23.  *                  "security" = "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
  24.  *                  "path" = "/candidate/identity_documents/upload/{id}",
  25.  *                  "controller" = CandidateIdentityVerificationImageShowController::class,
  26.  *                   "method"="GET"
  27.  *              },
  28.  *          "get_agent"={
  29.  *                  "security" = "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
  30.  *                  "path" = "/agent/identity_documents/upload/{id}",
  31.  *                  "controller" = AgentIdentityVerificationImageShowController::class,
  32.  *                   "method"="GET"
  33.  *              },
  34.  *         "delete_candidate" = {
  35.  *                   "security" = "is_granted('ROLE_MANAGER')",
  36.  *                   "path" = "/candidate/identity_documents/delete/{id}",
  37.  *                   "method"="DELETE",
  38.  *             },
  39.  *         "delete_agent" = {
  40.  *                   "security" = "is_granted('ROLE_MANAGER')",
  41.  *                   "path" = "/agent/identity_documents/delete/{id}",
  42.  *                   "method"="DELETE"
  43.  *               }
  44.  *   },
  45.  *   collectionOperations= {
  46.  *         "get"={"security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER') " },
  47.  *         "post_candidate" = {
  48.  *            "path"="/candidate/identity_documents/upload",
  49.  *            "method"="post",
  50.  *            "security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER') ",
  51.  *            "controller" = CandidateIdentityVerificationImageUploadController::class,
  52.  *            "deserialize" = false,
  53.  *            "validation_groups" = {"Default", "property_images_create"},
  54.  *            "openapi_context" = {
  55.  *                "requestBody" = {
  56.  *                    "content" = {
  57.  *                        "multipart/form-data" = {
  58.  *                            "schema" = {
  59.  *                                "type" = "object",
  60.  *                                "properties" = {
  61.  *                                    "file" = {
  62.  *                                        "type" = "string",
  63.  *                                        "format" = "binary",
  64.  *                                    },
  65.  *                                    "peopleId" = {
  66.  *                                          "type"="integer"
  67.  *                                    }
  68.  *                                },
  69.  *                            },
  70.  *                        },
  71.  *                    },
  72.  *                },
  73.  *            },
  74.  *          },
  75.  *
  76.  *        "post_agent" = {
  77.  *            "path"="/agent/identity_documents/upload",
  78.  *            "method"="post",
  79.  *            "security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER') ",
  80.  *            "controller" = AgentIdentityVerificationImageUploadController::class,
  81.  *            "deserialize" = false,
  82.  *            "validation_groups" = {"Default", "property_images_create"},
  83.  *            "openapi_context" = {
  84.  *                "requestBody" = {
  85.  *                    "content" = {
  86.  *                        "multipart/form-data" = {
  87.  *                            "schema" = {
  88.  *                                "type" = "object",
  89.  *                                "properties" = {
  90.  *                                    "file" = {
  91.  *                                        "type" = "string",
  92.  *                                        "format" = "binary",
  93.  *                                    },
  94.  *                                    "peopleId" = {
  95.  *                                          "type"="integer"
  96.  *                                    }
  97.  *                                },
  98.  *                            },
  99.  *                        },
  100.  *                    },
  101.  *                },
  102.  *            },
  103.  *        },
  104.  *    }
  105.  *     )
  106.  * @ORM\Entity(repositoryClass=IdentityVerificationImageRepository::class)
  107.  */
  108. class IdentityVerificationImage
  109. {
  110.     public const REFERENCE_IDENTITY_TYPE_ID_CARD 'reference.image.type.ID_CARD';
  111.     public const ALL_REFERENCE_IDENTITY_TYPE = [self::REFERENCE_IDENTITY_TYPE_ID_CARD];
  112.     /**
  113.      * @ORM\Column(type="integer")
  114.      * @ORM\GeneratedValue
  115.      * @ORM\Id
  116.      * @Groups({
  117.      *     "identity-verification:read","candidate:read",
  118.      *     "directory:collaborator:search",
  119.      *     "abstract-collaborator:read",
  120.      *     "agent:read",
  121.      *  })
  122.      */
  123.     private ?int $id null;
  124.     /**
  125.      * @Groups({
  126.      *     "candidate:read"
  127.      * })
  128.      */
  129.     public ?string $contentUrl null;
  130.     /**
  131.      * @Vich\UploadableField(mapping="identity_images", fileNameProperty="filePath")
  132.      * @Assert\File(
  133.      *     maxSizeMessage = "File exceeds allowed size",
  134.      *     mimeTypes = {"image/png","image/jpeg","image/webp"},
  135.      *     mimeTypesMessage = "Please upload a valid file"
  136.      * )
  137.      */
  138.     public ?File $file null;
  139.     /**
  140.      * @ORM\Column(nullable=true)
  141.      * @Groups({
  142.      *     "identity-verification:read","candidate:read",
  143.      *     "directory:collaborator:search",
  144.      *     "abstract-collaborator:read",
  145.      *     "agent:read",
  146.      * })
  147.      */
  148.     public ?string $filePath null;
  149.     /**
  150.      * @ORM\Column(type="string", length=255, nullable=true)
  151.      * @Groups({
  152.      *     "identity-verification:read","candidate:read",
  153.      *     "directory:collaborator:search",
  154.      *     "abstract-collaborator:read",
  155.      *     "agent:read",
  156.      * })
  157.      */
  158.     public ?string $type;
  159.     /**
  160.      * @ORM\ManyToOne(targetEntity=Candidate::class, inversedBy="identityFiles")
  161.      */
  162.     private ?Candidate $candidate null;
  163.     /**
  164.      * @ORM\ManyToOne(targetEntity=Agent::class, inversedBy="identityFiles")
  165.      */
  166.     private ?Agent $agent null;
  167.     public function getId(): ?int
  168.     {
  169.         return $this->id;
  170.     }
  171.     /**
  172.      * @return string|null
  173.      */
  174.     public function getFilePath(): ?string
  175.     {
  176.         return $this->filePath;
  177.     }
  178.     /**
  179.      * @param string|null $filePath
  180.      * @return $this
  181.      */
  182.     public function setFilePath(?string $filePath): self
  183.     {
  184.         $this->filePath $filePath;
  185.         return $this;
  186.     }
  187.     public function getType(): ?string
  188.     {
  189.         return $this->type;
  190.     }
  191.     public function setType(?string $type): self
  192.     {
  193.         if ($type != self::REFERENCE_IDENTITY_TYPE_ID_CARD) {
  194.             throw new InvalidArgumentException("Invalid identity type $type");
  195.         }
  196.         $this->type $type;
  197.         return $this;
  198.     }
  199.     public function getCandidate(): ?Candidate
  200.     {
  201.         return $this->candidate;
  202.     }
  203.     public function setCandidate(?Candidate $candidate): self
  204.     {
  205.         $this->candidate $candidate;
  206.         return $this;
  207.     }
  208.     public function getAgent(): ?Agent
  209.     {
  210.         return $this->agent;
  211.     }
  212.     public function setAgent(?Agent $agent): self
  213.     {
  214.         $this->agent $agent;
  215.         return $this;
  216.     }
  217.     public static function getPath(string $basePath string $directoryIdentityVerificationImage $identityVerification): string
  218.     {
  219.         return sprintf('%s/%s/%s'$basePath$directory$identityVerification->getFilePath());
  220.     }
  221. }