<?php
// api/src/Entity/MediaObject.php
namespace App\Entity;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Delete;
use App\Controller\CreateMediaObjectAction;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use Doctrine\DBAL\Types\Types;
use Symfony\Component\Serializer\Annotation\MaxDepth;
#[Vich\Uploadable]
#[ORM\Entity]
#[ApiResource(
normalizationContext: ['groups' => ['media_object:read']],
types: ['https://schema.org/MediaObject'],
operations: [
new Get(),
new GetCollection(),
new Delete(),
new Post(
controller: CreateMediaObjectAction::class,
deserialize: false,
validationContext: ['groups' => ['Default', 'media_object_create']],
openapiContext: [
'requestBody' => [
'content' => [
'multipart/form-data' => [
'schema' => [
'type' => 'object',
'properties' => [
'file' => [
'type' => 'string',
'format' => 'binary'
]
]
]
]
]
]
]
)
],
order: ['id' => 'DESC'],
)]
#[ApiFilter(SearchFilter::class, properties: [
'product.id' => 'exact',
'orders.id' => 'exact',
'orders.account.user.id' => 'exact',
])]
#[ORM\HasLifecycleCallbacks]
class MediaObject
{
#[Groups(['media_object:read', 'product:read', 'cat:read', 'user_like:read', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read','order_product:read','user:read', 'account:read', 'load_invoice:read', 'worker:read', 'account_worker:read', 'job:read', 'site_product:read'])]
#[ORM\Id, ORM\Column, ORM\GeneratedValue]
private ?int $id = null;
#[ApiProperty(types: ['https://schema.org/contentUrl'])]
#[Groups(['media_object:read', 'product:read', 'cat:read', 'user_like:read', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read','order_product:read', 'user:read', 'account:read', 'load_invoice:read', 'worker:read', 'account_worker:read', 'job:read', 'site_product:read'])]
public ?string $contentUrl = null;
#[Vich\UploadableField(mapping: "media_object", fileNameProperty: "filePath")]
#[Assert\NotNull(groups: ['media_object_create'])]
public ?File $file = null;
#[Groups(['media_object:read', 'product:read', 'cat:read', 'user_like:read', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read','order_product:read', 'user:read', 'account:read', 'load_invoice:read', 'worker:read', 'account_worker:read', 'job:read', 'site_product:read'])]
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
public $uploadTimestamp;
#[Groups(['media_object:read', 'product:read', 'user_like:read', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read','order_product:read','user:read', 'account:read', 'load_invoice:read', 'worker:read', 'account_worker:read', 'job:read', 'cat:read', 'site_product:read'])]
#[ORM\Column(nullable: true)]
private ?bool $main = null;
#[ORM\Column(nullable: true)]
#[Groups(['media_object:read', 'product:read', 'cat:read', 'user_like:read', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read','order_product:read', 'user:read', 'account:read', 'load_invoice:read', 'worker:read', 'account_worker:read', 'job:read', 'site_product:read'])]
public ?string $filePath = null;
#[Groups(['media_object_create'])]
#[ORM\ManyToOne(inversedBy: 'media')]
private ?Products $product = null;
#[Groups(['media_object_create'])]
#[ORM\ManyToOne(inversedBy: 'mediaObjects')]
private ?Orders $orders = null;
#[Groups(['media_object:read', 'media_object_create'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $type = null;
#[Groups(['media_object:read', 'media_object_create'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
#[Groups(['media_object_create'])]
#[ORM\ManyToOne(inversedBy: 'mediaObjects')]
private ?User $users = null;
#[Groups(['media_object_create'])]
#[ORM\ManyToOne(inversedBy: 'media')]
private ?AccountWorker $accountWorker = null;
#[Groups(['media_object_create'])]
#[ORM\ManyToOne(inversedBy: 'media')]
private ?FormAnswer $formAnswer = null;
#[Groups(['media_object_create'])]
#[ORM\ManyToOne(inversedBy: 'mediaObjects', cascade:['persist'])]
private ?Jobs $job = null;
#[ORM\OneToMany(mappedBy: 'photo', targetEntity: Workers::class, cascade:['persist'])]
private Collection $workers;
#[ORM\OneToMany(mappedBy: 'document', targetEntity: AccountJobsList::class, cascade:['persist'])]
private Collection $accountJobsLists;
#[ORM\OneToMany(mappedBy: 'commandment', targetEntity: Jobs::class, cascade:['persist'])]
private Collection $commandment_jobs;
#[ORM\OneToMany(mappedBy: 'graph', targetEntity: Jobs::class, cascade:['persist'])]
private Collection $graph_jobs;
#[ORM\OneToMany(mappedBy: 'protocole', targetEntity: Jobs::class, cascade:['persist'])]
private Collection $protocole_jobs;
#[ORM\OneToMany(mappedBy: 'mainMedia', targetEntity: Products::class)]
private Collection $MainProducts;
#[Groups(['media_object:read', 'product:read', 'user_like:read', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read','order_product:read','user:read', 'account:read', 'load_invoice:read', 'worker:read', 'account_worker:read', 'job:read', 'site_product:read', 'cat:read'])]
#[ORM\Column(nullable: true)]
private ?int $size = null;
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'resizeImagings')]
private ?self $resizeImgParent = null;
#[Groups(['media_object:read', 'product:read', 'user_like:read', 'pre_order_product:read', 'pre_order:read', 'order:read', 'order_product:read','order_product:read','user:read', 'account:read', 'load_invoice:read', 'worker:read', 'account_worker:read', 'job:read', 'site_product:read', 'cat:read'])]
#[ORM\OneToMany(mappedBy: 'resizeImgParent', targetEntity: self::class, cascade:['persist', 'remove'])]
private Collection $resizeImagings;
#[ORM\OneToMany(mappedBy: 'media', targetEntity: SiteProductsMedia::class, cascade:['persist', 'remove'])]
private Collection $siteProductsMedia;
#[ORM\OneToMany(mappedBy: 'media', targetEntity: Category::class, cascade:['persist'])]
private Collection $categories;
#[ORM\OneToMany(mappedBy: 'media', targetEntity: Slide::class)]
private Collection $slides;
#[ORM\OneToMany(mappedBy: 'mainMediaHover', targetEntity: Products::class)]
private Collection $productsHover;
public function __construct()
{
$this->workers = new ArrayCollection();
$this->accountJobsLists = new ArrayCollection();
$this->commandment_jobs = new ArrayCollection();
$this->graph_jobs = new ArrayCollection();
$this->protocole_jobs = new ArrayCollection();
$this->MainProducts = new ArrayCollection();
$this->resizeImagings = new ArrayCollection();
$this->siteProductsMedia = new ArrayCollection();
$this->categories = new ArrayCollection();
$this->slides = new ArrayCollection();
$this->productsHover = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getUploadTimestamp(): ?\DateTimeInterface
{
return $this->uploadTimestamp;
}
public function getProduct(): ?Products
{
return $this->product;
}
public function setProduct(?Products $product): self
{
$this->product = $product;
return $this;
}
public function getOrders(): ?Orders
{
return $this->orders;
}
public function setOrders(?Orders $orders): self
{
$this->orders = $orders;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getUsers(): ?User
{
return $this->users;
}
public function setUsers(?User $users): self
{
$this->users = $users;
return $this;
}
public function getAccountWorker(): ?AccountWorker
{
return $this->accountWorker;
}
public function setAccountWorker(?AccountWorker $accountWorker): self
{
$this->accountWorker = $accountWorker;
return $this;
}
public function setFormAnswer(?FormAnswer $formAnswer): self
{
$this->formAnswer = $formAnswer;
return $this;
}
public function getJob(): ?Jobs
{
return $this->job;
}
public function setJob(?Jobs $job): self
{
$this->job = $job;
return $this;
}
/**
* @return Collection<int, Workers>
*/
public function getWorkers(): Collection
{
return $this->workers;
}
public function addWorker(Workers $worker): self
{
if (!$this->workers->contains($worker)) {
$this->workers->add($worker);
$worker->setPhoto($this);
}
return $this;
}
public function removeWorker(Workers $worker): self
{
if ($this->workers->removeElement($worker)) {
// set the owning side to null (unless already changed)
if ($worker->getPhoto() === $this) {
$worker->setPhoto(null);
}
}
return $this;
}
/**
* @return Collection<int, AccountJobsList>
*/
public function getAccountJobsLists(): Collection
{
return $this->accountJobsLists;
}
public function addAccountJobsList(AccountJobsList $accountJobsList): self
{
if (!$this->accountJobsLists->contains($accountJobsList)) {
$this->accountJobsLists->add($accountJobsList);
$accountJobsList->setDocument($this);
}
return $this;
}
public function removeAccountJobsList(AccountJobsList $accountJobsList): self
{
if ($this->accountJobsLists->removeElement($accountJobsList)) {
// set the owning side to null (unless already changed)
if ($accountJobsList->getDocument() === $this) {
$accountJobsList->setDocument(null);
}
}
return $this;
}
/**
* @return Collection<int, Jobs>
*/
public function getCommandmentJobs(): Collection
{
return $this->commandment_jobs;
}
public function addCommandmentJob(Jobs $commandmentJob): self
{
if (!$this->commandment_jobs->contains($commandmentJob)) {
$this->commandment_jobs->add($commandmentJob);
$commandmentJob->setCommandment($this);
}
return $this;
}
public function removeCommandmentJob(Jobs $commandmentJob): self
{
if ($this->commandment_jobs->removeElement($commandmentJob)) {
// set the owning side to null (unless already changed)
if ($commandmentJob->getCommandment() === $this) {
$commandmentJob->setCommandment(null);
}
}
return $this;
}
/**
* @return Collection<int, Jobs>
*/
public function getGraphJobs(): Collection
{
return $this->graph_jobs;
}
public function addGraphJob(Jobs $graphJob): self
{
if (!$this->graph_jobs->contains($graphJob)) {
$this->graph_jobs->add($graphJob);
$graphJob->setGraph($this);
}
return $this;
}
public function removeGraphJob(Jobs $graphJob): self
{
if ($this->graph_jobs->removeElement($graphJob)) {
// set the owning side to null (unless already changed)
if ($graphJob->getGraph() === $this) {
$graphJob->setGraph(null);
}
}
return $this;
}
/**
* @return Collection<int, Jobs>
*/
public function getProtocoleJobs(): Collection
{
return $this->protocole_jobs;
}
public function addProtocoleJob(Jobs $protocoleJob): self
{
if (!$this->protocole_jobs->contains($protocoleJob)) {
$this->protocole_jobs->add($protocoleJob);
$protocoleJob->setProtocole($this);
}
return $this;
}
public function removeProtocoleJob(Jobs $protocoleJob): self
{
if ($this->protocole_jobs->removeElement($protocoleJob)) {
// set the owning side to null (unless already changed)
if ($protocoleJob->getProtocole() === $this) {
$protocoleJob->setProtocole(null);
}
}
return $this;
}
public function isMain(): ?bool
{
return $this->main;
}
public function setMain(?bool $main): self
{
$this->main = $main;
return $this;
}
/**
* @return Collection<int, Products>
*/
public function getMainProducts(): Collection
{
return $this->MainProducts;
}
public function addMainProduct(Products $mainProduct): self
{
if (!$this->MainProducts->contains($mainProduct)) {
$this->MainProducts->add($mainProduct);
$mainProduct->setMainMedia($this);
}
return $this;
}
public function removeMainProduct(Products $mainProduct): self
{
if ($this->MainProducts->removeElement($mainProduct)) {
// set the owning side to null (unless already changed)
if ($mainProduct->getMainMedia() === $this) {
$mainProduct->setMainMedia(null);
}
}
return $this;
}
#[ORM\PrePersist]
public function setCreatedAtValue(): void
{
$this->uploadTimestamp = new \DateTime();
}
public function getSize(): ?int
{
return $this->size;
}
public function setSize(?int $size): static
{
$this->size = $size;
return $this;
}
public function getResizeImgParent(): ?self
{
return $this->resizeImgParent;
}
public function setResizeImgParent(?self $resizeImgParent): static
{
$this->resizeImgParent = $resizeImgParent;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getResizeImagings(): Collection
{
return $this->resizeImagings;
}
public function addResizeImging(self $resizeImging): static
{
if (!$this->resizeImagings->contains($resizeImging)) {
$this->resizeImagings->add($resizeImging);
$resizeImging->setResizeImgParent($this);
}
return $this;
}
public function removeResizeImging(self $resizeImging): static
{
if ($this->resizeImagings->removeElement($resizeImging)) {
// set the owning side to null (unless already changed)
if ($resizeImging->getResizeImgParent() === $this) {
$resizeImging->setResizeImgParent(null);
}
}
return $this;
}
/**
* @return Collection<int, SiteProductsMedia>
*/
public function getSiteProductsMedia(): Collection
{
return $this->siteProductsMedia;
}
public function addSiteProductsMedium(SiteProductsMedia $siteProductsMedium): static
{
if (!$this->siteProductsMedia->contains($siteProductsMedium)) {
$this->siteProductsMedia->add($siteProductsMedium);
$siteProductsMedium->setMedia($this);
}
return $this;
}
public function removeSiteProductsMedium(SiteProductsMedia $siteProductsMedium): static
{
if ($this->siteProductsMedia->removeElement($siteProductsMedium)) {
// set the owning side to null (unless already changed)
if ($siteProductsMedium->getMedia() === $this) {
$siteProductsMedium->setMedia(null);
}
}
return $this;
}
/**
* @return Collection<int, Category>
*/
public function getCategories(): Collection
{
return $this->categories;
}
public function addCategory(Category $category): static
{
if (!$this->categories->contains($category)) {
$this->categories->add($category);
$category->setMedia($this);
}
return $this;
}
public function removeCategory(Category $category): static
{
if ($this->categories->removeElement($category)) {
// set the owning side to null (unless already changed)
if ($category->getMedia() === $this) {
$category->setMedia(null);
}
}
return $this;
}
/**
* @return Collection<int, Slide>
*/
public function getSlides(): Collection
{
return $this->slides;
}
public function addSlide(Slide $slide): static
{
if (!$this->slides->contains($slide)) {
$this->slides->add($slide);
$slide->setMedia($this);
}
return $this;
}
public function removeSlide(Slide $slide): static
{
if ($this->slides->removeElement($slide)) {
// set the owning side to null (unless already changed)
if ($slide->getMedia() === $this) {
$slide->setMedia(null);
}
}
return $this;
}
/**
* @return Collection<int, Products>
*/
public function getProductsHover(): Collection
{
return $this->productsHover;
}
public function addProductsHover(Products $productsHover): static
{
if (!$this->productsHover->contains($productsHover)) {
$this->productsHover->add($productsHover);
$productsHover->setMainMediaHover($this);
}
return $this;
}
public function removeProductsHover(Products $productsHover): static
{
if ($this->productsHover->removeElement($productsHover)) {
// set the owning side to null (unless already changed)
if ($productsHover->getMainMediaHover() === $this) {
$productsHover->setMainMediaHover(null);
}
}
return $this;
}
}