src/Entity/PropertyImages.php line 79

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Controller\Agent\Property\ArchivePropertyImageController;
  5. use App\Controller\Agent\Property\CreatePropertyImagesAction;
  6. use App\Controller\Agent\Property\UpdatePositionPropertyImagesAction;
  7. use App\Repository\PropertyImagesRepository;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\HttpFoundation\File\File;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  13. /**
  14.  * @ORM\Entity(repositoryClass=PropertyImagesRepository::class)
  15.  * @Vich\Uploadable
  16.  * @ApiResource(
  17.  *  iri= "https://schema.org/PropertyImages",
  18.  *  normalizationContext= {"groups" = {"property_images:read"},"swagger_definition_name"="Read"},
  19.  *  denormalizationContext={"groups"={"property_images:write"}, "swagger_definition_name"="Write"},
  20.  *  itemOperations= {
  21.  *          "get"={
  22.  *              "security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')"
  23.  *           },
  24.  *           "archive_property_image"={
  25.  *              "denormalization_context"={"groups"={"property_images:archive"}},
  26.  *              "security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
  27.  *              "method"="PATCH",
  28.  *              "path"="/property_image/{id}/archive",
  29.  *              "controller"=ArchivePropertyImageController::class,
  30.  *              "read"=true,
  31.  *              "write"=false,
  32.  *          },
  33.  *          "update_position_property_image"={
  34.  *              "denormalization_context"={"groups"={"property_images:update_position"}},
  35.  *              "security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')",
  36.  *              "method"="PATCH",
  37.  *              "path"="/property_image/update_position/{property}",
  38.  *              "controller"=UpdatePositionPropertyImagesAction::class,
  39.  *              "read"=false,
  40.  *              "write"=false,
  41.  *              "input_formats"={"json"={"application/ld+json","application/merge-patch+json", "application/json" }},
  42.  *              "output_formats"={"json"={"application/ld+json", "application/json"}}
  43.  *          }
  44.  *     },
  45.  *  collectionOperations= {
  46.  *       "get"={"security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER')" },
  47.  *        "post" = {
  48.  *            "controller" = CreatePropertyImagesAction::class,
  49.  *            "deserialize" = false,
  50.  *            "security"="is_granted('ROLE_AGENT') or is_granted('ROLE_MANAGER') ",
  51.  *            "validation_groups" = {"Default", "property_images_create"},
  52.  *            "openapi_context" = {
  53.  *                "requestBody" = {
  54.  *                    "content" = {
  55.  *                        "multipart/form-data" = {
  56.  *                            "schema" = {
  57.  *                                "type" = "object",
  58.  *                                "properties" = {
  59.  *                                    "file" = {
  60.  *                                        "type" = "string",
  61.  *                                        "format" = "binary",
  62.  *                                    },
  63.  *                                    "property"={
  64.  *                                          "type"="integer"
  65.  *                                  }
  66.  *                                },
  67.  *                            },
  68.  *                        },
  69.  *                    },
  70.  *                },
  71.  *            },
  72.  *        },
  73.  *    }
  74.  * )}
  75.  */
  76. class PropertyImages
  77. {
  78.     public const PROPERTY_IMAGE_ARCHIVED true;
  79.     public const PROPERTY_IMAGE_UNARCHIVED false;
  80.     public const PROPERTY_IMAGE_PATH '/public/property_images/';
  81.     /**
  82.       * @ORM\Column(type="integer")
  83.       * @ORM\GeneratedValue
  84.       * @ORM\Id
  85.      * @Groups({"property_images:read","property:read","milkiya:read"})
  86.       */
  87.     private ?int $id null;
  88.     /**
  89.      * @Groups({"property:read","milkiya:read"})
  90.     */
  91.     public ?string $contentUrl null;
  92.     /**
  93.      * @ORM\ManyToOne(targetEntity="App\Entity\Property", inversedBy="images")
  94.      * @ORM\JoinColumn(nullable=false)
  95.      * @Groups({"property_images:read", "property_images:write"})
  96.      */
  97.     private ?Property $property;
  98.     /**
  99.      * @Vich\UploadableField(mapping="property_images", fileNameProperty="filePath")
  100.      * @Assert\Image(
  101.      *     maxSizeMessage = "File exceeds allowed size",
  102.      *     mimeTypesMessage = "Please upload a valid file"
  103.      * )
  104.     */
  105.     public ?File $file null;
  106.     /**
  107.      * @ORM\Column(nullable=true)
  108.      * @Groups({"property:read","milkiya:read"})
  109.      */
  110.     public ?string $filePath null;
  111.     /**
  112.      * @ORM\Column(type="boolean", nullable=true)
  113.      */
  114.     private $archived;
  115.     /**
  116.      * @ORM\Column(type="integer", nullable=true)
  117.      * @Groups({"property_images:read","property:read","milkiya:read"})
  118.      */
  119.     private $position;
  120.     public function getId(): ?int
  121.     {
  122.         return $this->id;
  123.     }
  124.     /**
  125.      * @return string|null
  126.      */
  127.     public function getFilePath(): ?string
  128.     {
  129.         return $this->filePath;
  130.     }
  131.     /**
  132.      * @param string|null $filePath
  133.      * @return $this
  134.      */
  135.     public function setFilePath(?string $filePath): self
  136.     {
  137.         $this->filePath $filePath;
  138.         return $this;
  139.     }
  140.     /**
  141.      * @return Property|null
  142.      */
  143.     public function getProperty(): ?Property
  144.     {
  145.         return $this->property;
  146.     }
  147.     /**
  148.      * @param Property|null $property
  149.      * @return $this
  150.      */
  151.     public function setProperty(?Property $property): self
  152.     {
  153.         $this->property $property;
  154.         return $this;
  155.     }
  156.     public function getArchived(): ?bool
  157.     {
  158.         return $this->archived;
  159.     }
  160.     public function setArchived(?bool $archived): self
  161.     {
  162.         $this->archived $archived;
  163.         return $this;
  164.     }
  165.     public function getPosition(): ?int
  166.     {
  167.         return $this->position;
  168.     }
  169.     public function setPosition(?int $position): self
  170.     {
  171.         $this->position $position;
  172.         return $this;
  173.     }
  174. }