src/Entity/Photo.php line 72

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Controller\Api\Photo\DeletePhotoController;
  5. use App\Controller\Api\Photo\PostController;
  6. use App\Repository\PhotoRepository;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Timestampable\Traits\TimestampableEntity;
  10. use Symfony\Component\HttpFoundation\File\UploadedFile;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. #[ORM\Entity(repositoryClassPhotoRepository::class)]
  13. #[ApiResource(
  14.     collectionOperations: [
  15.         'get' => [
  16.             'normalization_context' => [
  17.                 'groups' => 'read:photo:collection:get',
  18.             ],
  19.         ],
  20.         'delete_companies_photos' => [
  21.             "method" => "DELETE",
  22.             "path" => "/photos/companies",
  23.             "controller" => DeletePhotoController::class,
  24.         ],
  25.         'post' => [
  26.             'normalization_context' => [
  27.                 'groups' => 'read:photo:collection:post',
  28.             ],
  29.             'controller' => PostController::class,
  30.             'method' => 'POST',
  31.             'path' => '/photos',
  32.             'deserialize' => false,
  33.             'openapi_context' => [
  34.                 'requestBody' => [
  35.                     'content' => [
  36.                         'multipart/form-data' => [
  37.                             'schema' => [
  38.                                 'type' => 'object',
  39.                                 'properties' => [
  40.                                     'file' => [
  41.                                         'type' => 'string',
  42.                                         'format' => 'binary',
  43.                                     ],
  44.                                 ],
  45.                             ],
  46.                         ],
  47.                     ],
  48.                 ],
  49.             ],
  50.         ],
  51.     ],
  52.     itemOperations: [
  53.         'delete',
  54.         'get' => [
  55.             'normalization_context' => [
  56.                 'groups' => 'read:photo:item:get',
  57.             ],
  58.         ],
  59.     ],
  60.     subresourceOperations: [
  61.         'api_users_photos_get_subresource' => [
  62.             'method' => 'GET',
  63.             'normalization_context' => [
  64.                 'groups' => ['read:photo:collection:get'],
  65.             ],
  66.         ],
  67.     ],
  68. )]
  69. class Photo
  70. {
  71.     #[ORM\Id]
  72.     #[ORM\GeneratedValue]
  73.     #[ORM\Column()]
  74.     #[Groups([
  75.         'read:photo:collection:get',
  76.         'read:photo:collection:post',
  77.         'read:photo:item:get',
  78.         'read:outfit:collection:get',
  79.         'read:outfit:item:get',
  80.         'read:user:item:book',
  81.         'read:club:collection:getCompanies',
  82.         'read:company:collection:get',
  83.     ])]
  84.     private ?int $id null;
  85.     use TimestampableEntity;
  86.     #[ORM\ManyToOne(cascade: ["persist""remove"])]
  87.     #[ORM\JoinColumn(nullabletrueonDelete"SET NULL")]
  88.     #[Groups([
  89.         'read:photo:collection:get',
  90.         'read:photo:item:get',
  91.         'read:photo:collection:post',
  92.     ])]
  93.     private ?Document $imageLarge null;
  94.     #[ORM\ManyToOne(cascade: ["persist""remove"])]
  95.     #[ORM\JoinColumn(nullabletrueonDelete"SET NULL")]
  96.     #[Groups([
  97.         'read:photo:collection:get',
  98.         'read:photo:item:get',
  99.         'read:photo:collection:post',
  100.     ])]
  101.     private ?Document $imageMedium null;
  102.     #[ORM\ManyToOne(cascade: ["persist""remove"])]
  103.     #[ORM\JoinColumn(nullabletrueonDelete"SET NULL")]
  104.     #[Groups([
  105.         'read:photo:collection:get',
  106.         'read:photo:item:get',
  107.         'read:photo:collection:post',
  108.     ])]
  109.     private ?Document $imageSmall null;
  110.     #[ORM\Column(length255nullabletrue)]
  111.     #[Groups([
  112.         'read:photo:collection:get',
  113.         'read:photo:item:get',
  114.     ])]
  115.     private ?string $title null;
  116.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  117.     #[Groups([
  118.         'read:photo:collection:get',
  119.         'read:photo:item:get',
  120.     ])]
  121.     private ?string $description null;
  122.     #[Groups([
  123.         'read:user:item:book',
  124.         'read:contest:collection:get',
  125.         'read:contest:item:get',
  126.     ])]
  127.     #[ORM\Column(nullabletrue)]
  128.     private ?bool $main null;
  129.     private ?UploadedFile $imageFile null;
  130.     #[ORM\Column()]
  131.     private ?bool $visible false;
  132.     #[ORM\ManyToOne(targetEntityUser::class, cascade: ["persist"], inversedBy'photos')]
  133.     #[ORM\JoinColumn(nullabletrueonDelete"SET NULL")]
  134.     private ?User $user null;
  135.     #[ORM\ManyToOne(cascade: ["persist"], inversedBy'photos')]
  136.     #[ORM\JoinColumn(nullabletrueonDelete"SET NULL")]
  137.     private ?Company $company null;
  138.     #[ORM\ManyToOne(cascade: ["persist"], inversedBy'photos')]
  139.     #[ORM\JoinColumn(nullabletrueonDelete"SET NULL")]
  140.     private ?Club $club null;
  141.     #[ORM\ManyToOne(cascade: ["persist"], inversedBy'photos')]
  142.     #[ORM\JoinColumn(nullabletrueonDelete"SET NULL")]
  143.     private ?Post $post null;
  144.     #[ORM\ManyToOne(cascade: ["persist"], inversedBy'photos')]
  145.     #[ORM\JoinColumn(nullabletrueonDelete"SET NULL")]
  146.     private ?Ad $ad null;
  147.     #[ORM\ManyToOne(cascade: ["persist"], inversedBy'photos')]
  148.     #[ORM\JoinColumn(nullabletrueonDelete"SET NULL")]
  149.     private ?Deal $deal null;
  150.     #[ORM\ManyToOne(cascade: ["persist"], inversedBy'photos')]
  151.     #[ORM\JoinColumn(nullabletrueonDelete"SET NULL")]
  152.     private ?Widget $widget null;
  153.     #[ORM\ManyToOne(cascade: ["persist"], inversedBy'photos')]
  154.     #[ORM\JoinColumn(nullabletrueonDelete"SET NULL")]
  155.     private ?Alert $alert null;
  156.     #[ORM\ManyToOne(cascade: ["persist"], inversedBy'photos')]
  157.     #[ORM\JoinColumn(nullabletrueonDelete"SET NULL")]
  158.     private ?ClubPresentation $clubPresentation null;
  159.     public function __construct()
  160.     {
  161.     }
  162.     public function getImageFile(): ?UploadedFile
  163.     {
  164.         return $this->imageFile;
  165.     }
  166.     public function setImageFile(?UploadedFile $imageFile): self
  167.     {
  168.         $this->imageFile $imageFile;
  169.         return $this;
  170.     }
  171.     #[Groups([
  172.         'read:user:item:get',
  173.         'read:club:collection:getCompanies',
  174.         'read:company:collection:get',
  175.     ])]
  176.     public function getImageUrl(): string
  177.     {
  178.         if ($this->getImageLarge()) {
  179.             return $this->getImageLarge()->getUrl();
  180.         }
  181.         return 'https://localbeez.ri7.fr/assets/img/image_placeholder.jpg';
  182.     }
  183.     #[Groups([
  184.         'read:user:item:get',
  185.     ])]
  186.     public function getSmallImageUrl(): string
  187.     {
  188.         if ($this->getImageSmall()) {
  189.             return $this->getImageSmall()->getUrl();
  190.         }
  191.         return 'https://localbeez.ri7.fr/assets/img/image_placeholder.jpg';
  192.     }
  193.     #[Groups([
  194.         'read:user:item:get',
  195.         'read:club:collection:getCompanies',
  196.         'read:company:collection:get',
  197.     ])]
  198.     public function getMediumImageUrl(): string
  199.     {
  200.         if ($this->getImageMedium()) {
  201.             return $this->getImageMedium()->getUrl();
  202.         }
  203.         return 'https://localbeez.ri7.fr/assets/img/image_placeholder.jpg';
  204.     }
  205.     public function getId(): ?int
  206.     {
  207.         return $this->id;
  208.     }
  209.     public function getTitle(): ?string
  210.     {
  211.         return $this->title;
  212.     }
  213.     public function setTitle(?string $title): self
  214.     {
  215.         $this->title $title;
  216.         return $this;
  217.     }
  218.     public function getDescription(): ?string
  219.     {
  220.         return $this->description;
  221.     }
  222.     public function setDescription(?string $description): self
  223.     {
  224.         $this->description $description;
  225.         return $this;
  226.     }
  227.     public function isMain(): ?bool
  228.     {
  229.         return $this->main;
  230.     }
  231.     public function setMain(?bool $main): self
  232.     {
  233.         $this->main $main;
  234.         return $this;
  235.     }
  236.     public function isVisible(): ?bool
  237.     {
  238.         return $this->visible;
  239.     }
  240.     public function setVisible(bool $visible): self
  241.     {
  242.         $this->visible $visible;
  243.         return $this;
  244.     }
  245.     public function getImageLarge(): ?Document
  246.     {
  247.         return $this->imageLarge;
  248.     }
  249.     public function setImageLarge(?Document $imageLarge): self
  250.     {
  251.         $this->imageLarge $imageLarge;
  252.         return $this;
  253.     }
  254.     public function getImageMedium(): ?Document
  255.     {
  256.         return $this->imageMedium;
  257.     }
  258.     public function setImageMedium(?Document $imageMedium): self
  259.     {
  260.         $this->imageMedium $imageMedium;
  261.         return $this;
  262.     }
  263.     public function getImageSmall(): ?Document
  264.     {
  265.         return $this->imageSmall;
  266.     }
  267.     public function setImageSmall(?Document $imageSmall): self
  268.     {
  269.         $this->imageSmall $imageSmall;
  270.         return $this;
  271.     }
  272.     public function getUser(): ?User
  273.     {
  274.         return $this->user;
  275.     }
  276.     public function setUser(?User $user): self
  277.     {
  278.         $this->user $user;
  279.         return $this;
  280.     }
  281.     public function getCompany(): ?Company
  282.     {
  283.         return $this->company;
  284.     }
  285.     public function setCompany(?Company $company): self
  286.     {
  287.         $this->company $company;
  288.         return $this;
  289.     }
  290.     public function getClub(): ?Club
  291.     {
  292.         return $this->club;
  293.     }
  294.     public function setClub(?Club $club): self
  295.     {
  296.         $this->club $club;
  297.         return $this;
  298.     }
  299.     public function getPost(): ?Post
  300.     {
  301.         return $this->post;
  302.     }
  303.     public function setPost(?Post $post): self
  304.     {
  305.         $this->post $post;
  306.         return $this;
  307.     }
  308.     public function getAd(): ?Ad
  309.     {
  310.         return $this->ad;
  311.     }
  312.     public function setAd(?Ad $ad): self
  313.     {
  314.         $this->ad $ad;
  315.         return $this;
  316.     }
  317.     public function getDeal(): ?Deal
  318.     {
  319.         return $this->deal;
  320.     }
  321.     public function setDeal(?Deal $deal): self
  322.     {
  323.         $this->deal $deal;
  324.         return $this;
  325.     }
  326.     public function getWidget(): ?Widget
  327.     {
  328.         return $this->widget;
  329.     }
  330.     public function setWidget(?Widget $widget): static
  331.     {
  332.         $this->widget $widget;
  333.         return $this;
  334.     }
  335.     public function getAlert(): ?Alert
  336.     {
  337.         return $this->alert;
  338.     }
  339.     public function setAlert(?Alert $alert): static
  340.     {
  341.         $this->alert $alert;
  342.         return $this;
  343.     }
  344.     public function getClubPresentation(): ?ClubPresentation
  345.     {
  346.         return $this->clubPresentation;
  347.     }
  348.     public function setClubPresentation(?ClubPresentation $clubPresentation): static
  349.     {
  350.         $this->clubPresentation $clubPresentation;
  351.         return $this;
  352.     }
  353. }