src/Entity/CertificateOfOwnershipFile.php line 60

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Controller\Agent\Property\CreatePropertyCertificate;
  5. use App\Repository\CertificateOfOwnershipFileRepository;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  11. /**
  12.  * @Vich\Uploadable
  13.  * @ApiResource(
  14.  *  iri= "https://schema.org/ownership/propertyFiles",
  15.  *  normalizationContext= {"groups" = {"certificate_of_ownership_file:read"},"swagger_definition_name"="Read"},
  16.  *  denormalizationContext={"groups"={"certificate_of_ownership_file:write"}, "swagger_definition_name"="Write"},
  17.  *  itemOperations= {
  18.  *          "get"={
  19.  *              "security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')"
  20.  *           },
  21.  *         "delete" = {
  22.  *                  "security" = "is_granted('CERTIFICATE_DELETE', object)"
  23.  *               }
  24.  *     },
  25.  *  collectionOperations= {
  26.  *       "get"={"security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')" },
  27.  *        "post" = {
  28.  *            "controller" = CreatePropertyCertificate::class,
  29.  *            "deserialize" = false,
  30.  *            "security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER') ",
  31.  *            "validation_groups" = {"Default", "create_property_certificate"},
  32.  *            "openapi_context" = {
  33.  *                "requestBody" = {
  34.  *                    "content" = {
  35.  *                        "multipart/form-data" = {
  36.  *                            "schema" = {
  37.  *                                "type" = "object",
  38.  *                                "properties" = {
  39.  *                                    "file" = {
  40.  *                                        "type" = "string",
  41.  *                                        "format" = "binary",
  42.  *                                    },
  43.  *                                    "property"={
  44.  *                                          "type"="integer"
  45.  *                                  }
  46.  *                                },
  47.  *                            },
  48.  *                        },
  49.  *                    },
  50.  *                },
  51.  *            },
  52.  *        },
  53.  *    }
  54.  * )}
  55.  * @ORM\Entity(repositoryClass=CertificateOfOwnershipFileRepository::class)
  56.  */
  57. class CertificateOfOwnershipFile
  58. {
  59.     /**
  60.      * @ORM\Column(type="integer")
  61.      * @ORM\GeneratedValue
  62.      * @ORM\Id
  63.      * @Groups({"property_certificat:read","property:read","mandate:read"})
  64.      */
  65.     private ?int $id null;
  66.     /**
  67.      * @ORM\ManyToOne(targetEntity="App\Entity\Property", inversedBy="imgs")
  68.      * @ORM\JoinColumn(nullable=false)
  69.      * @Groups({"certificate_of_ownership_file:read", "certificate_of_ownership_file:write"})
  70.      */
  71.     private ?Property $property;
  72.     /**
  73.      * @Vich\UploadableField(mapping="ownership_file", fileNameProperty="filePath")
  74.      * @Assert\File(
  75.      *     maxSizeMessage = "File exceeds allowed size",
  76.      *     mimeTypes = {"application/octet-stream", "application/pdf", "application/x-pdf", "image/png","image/jpeg","image/webp"},
  77.      *     mimeTypesMessage = "Please upload a valid format"
  78.      * )
  79.      */
  80.     public ?File $file null;
  81.     /**
  82.      * @Groups({"property:read","mandate:read"})
  83.      */
  84.     public ?string $contentUrl null;
  85.     /**
  86.      * @ORM\Column(nullable=true)
  87.      * @Groups({"property:read","mandate:read"})
  88.      */
  89.     public ?string $filePath null;
  90.     public function getId(): ?int
  91.     {
  92.         return $this->id;
  93.     }
  94.     /**
  95.      * @return string|null
  96.      */
  97.     public function getFilePath(): ?string
  98.     {
  99.         return $this->filePath;
  100.     }
  101.     /**
  102.      * @param string|null $filePath
  103.      *
  104.      * @return $this
  105.      */
  106.     public function setFilePath(?string $filePath): self
  107.     {
  108.         $this->filePath $filePath;
  109.         return $this;
  110.     }
  111.     /**
  112.      * @return Property|null
  113.      */
  114.     public function getProperty(): ?Property
  115.     {
  116.         return $this->property;
  117.     }
  118.     /**
  119.      * @param Property|null $property
  120.      * @return $this
  121.      */
  122.     public function setProperty(?Property $property): self
  123.     {
  124.         $this->property $property;
  125.         return $this;
  126.     }
  127. }