<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Controller\Api\Photo\DeletePhotoController;
use App\Controller\Api\Photo\PostController;
use App\Repository\PhotoRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: PhotoRepository::class)]
#[ApiResource(
collectionOperations: [
'get' => [
'normalization_context' => [
'groups' => 'read:photo:collection:get',
],
],
'delete_companies_photos' => [
"method" => "DELETE",
"path" => "/photos/companies",
"controller" => DeletePhotoController::class,
],
'post' => [
'normalization_context' => [
'groups' => 'read:photo:collection:post',
],
'controller' => PostController::class,
'method' => 'POST',
'path' => '/photos',
'deserialize' => false,
'openapi_context' => [
'requestBody' => [
'content' => [
'multipart/form-data' => [
'schema' => [
'type' => 'object',
'properties' => [
'file' => [
'type' => 'string',
'format' => 'binary',
],
],
],
],
],
],
],
],
],
itemOperations: [
'delete',
'get' => [
'normalization_context' => [
'groups' => 'read:photo:item:get',
],
],
],
subresourceOperations: [
'api_users_photos_get_subresource' => [
'method' => 'GET',
'normalization_context' => [
'groups' => ['read:photo:collection:get'],
],
],
],
)]
class Photo
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column()]
#[Groups([
'read:photo:collection:get',
'read:photo:collection:post',
'read:photo:item:get',
'read:outfit:collection:get',
'read:outfit:item:get',
'read:user:item:book',
'read:club:collection:getCompanies',
'read:company:collection:get',
])]
private ?int $id = null;
use TimestampableEntity;
#[ORM\ManyToOne(cascade: ["persist", "remove"])]
#[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")]
#[Groups([
'read:photo:collection:get',
'read:photo:item:get',
'read:photo:collection:post',
])]
private ?Document $imageLarge = null;
#[ORM\ManyToOne(cascade: ["persist", "remove"])]
#[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")]
#[Groups([
'read:photo:collection:get',
'read:photo:item:get',
'read:photo:collection:post',
])]
private ?Document $imageMedium = null;
#[ORM\ManyToOne(cascade: ["persist", "remove"])]
#[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")]
#[Groups([
'read:photo:collection:get',
'read:photo:item:get',
'read:photo:collection:post',
])]
private ?Document $imageSmall = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups([
'read:photo:collection:get',
'read:photo:item:get',
])]
private ?string $title = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups([
'read:photo:collection:get',
'read:photo:item:get',
])]
private ?string $description = null;
#[Groups([
'read:user:item:book',
'read:contest:collection:get',
'read:contest:item:get',
])]
#[ORM\Column(nullable: true)]
private ?bool $main = null;
private ?UploadedFile $imageFile = null;
#[ORM\Column()]
private ?bool $visible = false;
#[ORM\ManyToOne(targetEntity: User::class, cascade: ["persist"], inversedBy: 'photos')]
#[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")]
private ?User $user = null;
#[ORM\ManyToOne(cascade: ["persist"], inversedBy: 'photos')]
#[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")]
private ?Company $company = null;
#[ORM\ManyToOne(cascade: ["persist"], inversedBy: 'photos')]
#[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")]
private ?Club $club = null;
#[ORM\ManyToOne(cascade: ["persist"], inversedBy: 'photos')]
#[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")]
private ?Post $post = null;
#[ORM\ManyToOne(cascade: ["persist"], inversedBy: 'photos')]
#[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")]
private ?Ad $ad = null;
#[ORM\ManyToOne(cascade: ["persist"], inversedBy: 'photos')]
#[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")]
private ?Deal $deal = null;
#[ORM\ManyToOne(cascade: ["persist"], inversedBy: 'photos')]
#[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")]
private ?Widget $widget = null;
#[ORM\ManyToOne(cascade: ["persist"], inversedBy: 'photos')]
#[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")]
private ?Alert $alert = null;
#[ORM\ManyToOne(cascade: ["persist"], inversedBy: 'photos')]
#[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")]
private ?ClubPresentation $clubPresentation = null;
public function __construct()
{
}
public function getImageFile(): ?UploadedFile
{
return $this->imageFile;
}
public function setImageFile(?UploadedFile $imageFile): self
{
$this->imageFile = $imageFile;
return $this;
}
#[Groups([
'read:user:item:get',
'read:club:collection:getCompanies',
'read:company:collection:get',
])]
public function getImageUrl(): string
{
if ($this->getImageLarge()) {
return $this->getImageLarge()->getUrl();
}
return 'https://localbeez.ri7.fr/assets/img/image_placeholder.jpg';
}
#[Groups([
'read:user:item:get',
])]
public function getSmallImageUrl(): string
{
if ($this->getImageSmall()) {
return $this->getImageSmall()->getUrl();
}
return 'https://localbeez.ri7.fr/assets/img/image_placeholder.jpg';
}
#[Groups([
'read:user:item:get',
'read:club:collection:getCompanies',
'read:company:collection:get',
])]
public function getMediumImageUrl(): string
{
if ($this->getImageMedium()) {
return $this->getImageMedium()->getUrl();
}
return 'https://localbeez.ri7.fr/assets/img/image_placeholder.jpg';
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function isMain(): ?bool
{
return $this->main;
}
public function setMain(?bool $main): self
{
$this->main = $main;
return $this;
}
public function isVisible(): ?bool
{
return $this->visible;
}
public function setVisible(bool $visible): self
{
$this->visible = $visible;
return $this;
}
public function getImageLarge(): ?Document
{
return $this->imageLarge;
}
public function setImageLarge(?Document $imageLarge): self
{
$this->imageLarge = $imageLarge;
return $this;
}
public function getImageMedium(): ?Document
{
return $this->imageMedium;
}
public function setImageMedium(?Document $imageMedium): self
{
$this->imageMedium = $imageMedium;
return $this;
}
public function getImageSmall(): ?Document
{
return $this->imageSmall;
}
public function setImageSmall(?Document $imageSmall): self
{
$this->imageSmall = $imageSmall;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
public function getClub(): ?Club
{
return $this->club;
}
public function setClub(?Club $club): self
{
$this->club = $club;
return $this;
}
public function getPost(): ?Post
{
return $this->post;
}
public function setPost(?Post $post): self
{
$this->post = $post;
return $this;
}
public function getAd(): ?Ad
{
return $this->ad;
}
public function setAd(?Ad $ad): self
{
$this->ad = $ad;
return $this;
}
public function getDeal(): ?Deal
{
return $this->deal;
}
public function setDeal(?Deal $deal): self
{
$this->deal = $deal;
return $this;
}
public function getWidget(): ?Widget
{
return $this->widget;
}
public function setWidget(?Widget $widget): static
{
$this->widget = $widget;
return $this;
}
public function getAlert(): ?Alert
{
return $this->alert;
}
public function setAlert(?Alert $alert): static
{
$this->alert = $alert;
return $this;
}
public function getClubPresentation(): ?ClubPresentation
{
return $this->clubPresentation;
}
public function setClubPresentation(?ClubPresentation $clubPresentation): static
{
$this->clubPresentation = $clubPresentation;
return $this;
}
}