src/Entity/Avatar.php line 63

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\AvatarRepository;
  5. use App\Controller\Agent\Agent\UploadAvatarFileController;
  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/collaborator/avatar",
  15.  *   normalizationContext = {"groups" = {"avatar:read"} },
  16.  *   denormalizationContext={"groups" = {"avatar:write"}, "swagger_definition_name"="Write"},
  17.  *   itemOperations= {
  18.  *         "get"={
  19.  *                  "security" = "is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
  20.  *                  "path" = "/collaborator/avatar/{id}"
  21.  *              },
  22.  *         "delete" = {
  23.  *                   "security" = "is_granted('ROLE_MANAGER')",
  24.  *                   "path" = "/collaborator/avatar/{id}"
  25.  *               }
  26.  *   },
  27.  *   collectionOperations= {
  28.  *        "get"={"security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER') "},
  29.  *        "post" = {
  30.  *            "path"="/collaborator/avatar",
  31.  *            "security"="is_granted('ROLE_MANAGER') ",
  32.  *            "controller" = UploadAvatarFileController::class,
  33.  *            "deserialize" = false,
  34.  *            "validation_groups" = {"Default", "property_images_create"},
  35.  *            "openapi_context" = {
  36.  *                "requestBody" = {
  37.  *                    "content" = {
  38.  *                        "multipart/form-data" = {
  39.  *                            "schema" = {
  40.  *                                "type" = "object",
  41.  *                                "properties" = {
  42.  *                                    "file" = {
  43.  *                                        "type" = "string",
  44.  *                                        "format" = "binary",
  45.  *                                    },
  46.  *                                    "collaborator" = {
  47.  *                                          "type"="integer"
  48.  *                                    }
  49.  *                                },
  50.  *                            },
  51.  *                        },
  52.  *                    },
  53.  *                },
  54.  *            },
  55.  *        },
  56.  *    }
  57.  * )}
  58.  * @ORM\Entity(repositoryClass=AvatarRepository::class)
  59.  */
  60. class Avatar
  61. {
  62.     public const AVATAR_PATH "/collaborator/avatar/";
  63.     /**
  64.      * @ORM\Column(type="integer")
  65.      * @ORM\GeneratedValue
  66.      * @ORM\Id
  67.      * @Groups({"avatar:read","agent:read","abstract-collaborator:read","directory:collaborator:search"})
  68.      */
  69.     private ?int $id null;
  70.     /**
  71.      * @Vich\UploadableField(mapping="avatar_file", fileNameProperty="filePath")
  72.      * @Assert\File(
  73.      *     maxSize = "10M",
  74.      *     maxSizeMessage = "File exceeds allowed size",
  75.      *     mimeTypes = {"image/png", "image/jpeg", "image/jpg"},
  76.      *     mimeTypesMessage = "Please upload a valid format"
  77.      * )
  78.      */
  79.     public ?File $file null;
  80.     public ?string $contentUrl null;
  81.     /**
  82.      * @ORM\Column(nullable=true)
  83.      * @Groups({"avatar:read","agent:read","abstract-collaborator:read","directory:collaborator:search", "milkiya:read"})
  84.      */
  85.     public ?string $filePath null;
  86.     /**
  87.      * @ORM\OneToOne(targetEntity=AbstractCollaborator::class, inversedBy="avatar")
  88.      */
  89.     private ?AbstractCollaborator $collaborator;
  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.      * @return $this
  104.      */
  105.     public function setFilePath(?string $filePath): self
  106.     {
  107.         $this->filePath $filePath;
  108.         return $this;
  109.     }
  110.     public function getCollaborator(): ?AbstractCollaborator
  111.     {
  112.         return $this->collaborator;
  113.     }
  114.     public function setCollaborator(?AbstractCollaborator $collaborator): self
  115.     {
  116.         $this->collaborator $collaborator;
  117.         return $this;
  118.     }
  119. }