<?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;
#[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',
])]
class MediaObject
{
#[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', 'user_docs:read', 'account_worker:read', 'job:read', 'faq: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', 'user_docs:read', 'account_worker:read', 'job:read', 'faq:read'])]
public ?string $contentUrl = null;
#[Vich\UploadableField(mapping: "media_object", fileNameProperty: "filePath")]
#[Assert\NotNull(groups: ['media_object_create'])]
public ?File $file = null;
#[ORM\Column(nullable: true)]
public ?string $filePath = null;
#[Groups(['media_object:read', 'media_object_create'])]
#[ORM\ManyToOne(inversedBy: 'mediaObjects')]
private ?Products $product = null;
#[Groups(['media_object:read', '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:read', 'media_object_create'])]
#[ORM\ManyToOne(inversedBy: 'mediaObjects')]
private ?User $users = null;
#[Groups(['media_object:read', 'media_object_create'])]
#[ORM\ManyToOne(inversedBy: 'media')]
private ?AccountWorker $accountWorker = null;
#[Groups(['media_object:read', 'media_object_create'])]
#[ORM\ManyToOne(inversedBy: 'media')]
private ?FormAnswer $formAnswer = null;
#[Groups(['media_object:read', '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: 'media', targetEntity: UsersDocs::class)]
private Collection $usersDocs;
#[ORM\OneToMany(mappedBy: 'media', targetEntity: FaqDocs::class)]
private Collection $faqDocs;
#[ORM\OneToMany(mappedBy: 'media', targetEntity: SpecialMachinery::class)]
private Collection $specialMachineries;
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->usersDocs = new ArrayCollection();
$this->faqDocs = new ArrayCollection();
$this->specialMachineries = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
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;
}
/**
* @return Collection<int, UsersDocs>
*/
public function getUsersDocs(): Collection
{
return $this->usersDocs;
}
public function addUsersDoc(UsersDocs $usersDoc): static
{
if (!$this->usersDocs->contains($usersDoc)) {
$this->usersDocs->add($usersDoc);
$usersDoc->setMedia($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 removeUsersDoc(UsersDocs $usersDoc): static
{
if ($this->usersDocs->removeElement($usersDoc)) {
// set the owning side to null (unless already changed)
if ($usersDoc->getMedia() === $this) {
$usersDoc->setMedia(null);
}
}
return $this;
}
/**
* @return Collection<int, FaqDocs>
*/
public function getFaqDocs(): Collection
{
return $this->faqDocs;
}
public function addFaqDoc(FaqDocs $faqDoc): self
{
if (!$this->faqDocs->contains($faqDoc)) {
$this->faqDocs->add($faqDoc);
$faqDoc->setMedia($this);
}
return $this;
}
public function removeFaqDoc(FaqDocs $faqDoc): self
{
if ($this->faqDocs->removeElement($faqDoc)) {
// set the owning side to null (unless already changed)
if ($faqDoc->getMedia() === $this) {
$faqDoc->setMedia(null);
}
}
return $this;
}
/**
* @return Collection<int, SpecialMachineries>
*/
public function getSpecialMachineries(): Collection
{
return $this->specialMachineries;
}
public function addSpecialMachinery(SpecialMachinery $specialMachinery): static
{
if (!$this->specialMachineries->contains($specialMachinery)) {
$this->specialMachineries->add($specialMachinery);
$specialMachinery->setMedia($this);
}
return $this;
}
public function removeSpecialMachinery(SpecialMachinery $specialMachinery): static
{
if ($this->specialMachineries->removeElement($specialMachinery)) {
// set the owning side to null (unless already changed)
if ($specialMachinery->getMedia() === $this) {
$specialMachinery->setMedia(null);
}
}
return $this;
}
}