<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Get;
use App\Controller\Action\ImageMediaController;
use App\Controller\Action\UploadFileController;
use App\Repository\MediaRepository;
use App\Traits\AutoTimestampTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: MediaRepository::class)]
#[ApiResource(
operations: [
new GetCollection(),
new Post(
security: 'user.isMasterAdmin()',
),
new Get(),
new Post(
security: 'user.isMasterAdmin()',
uriTemplate: 'upload_file',
controller: UploadFileController::class,
openapiContext: [
'requestBody' => [
'content' => [
'multipart/form-data' => [
'schema' => [
'type' => 'object',
'properties' => [
'type' => [
'type' => 'string',
'format' => 'string'
],
'url' => [
'type' => 'string',
'format' => 'string'
],
'idDoc' => [
'type' => 'int',
'format' => 'int'
],
'illustrationsFile' => [
'type' => 'string',
'format' => 'binary'
],
'summaryFile' => [
'type' => 'string',
'format' => 'binary'
],
]
]
]
]
]
],
deserialize: false,
validate: false,
name: '_api_/upload_file'
),
new Put(
security: 'user.isMasterAdmin()',
),
new Get(
uriTemplate: '/media_picture',
controller: ImageMediaController::class,
read: false,
write: false,
name: '_api_/media_picture'
),
new Delete(
security: 'user.isMasterAdmin()',
),
],
)]
#[ORM\HasLifecycleCallbacks]
class Media
{
use AutoTimestampTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['document.get', 'plan.get', 'compliance.get', 'user.get'])]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Groups(['document.get'])]
private ?string $type = null;
#[ORM\Column(length: 255)]
#[Groups(['document.get', 'plan.get', 'compliance.get', 'user.get'])]
private ?string $name = null;
#[ORM\ManyToOne]
private ?User $userUpload = null;
#[ORM\OneToMany(mappedBy: 'illustrationsFile', targetEntity: Document::class)]
private Collection $illustrationsFile;
#[ORM\OneToMany(mappedBy: 'summaryFile', targetEntity: Document::class)]
private Collection $summaryFile;
#[ORM\Column(length: 255)]
#[Groups(['document.get','compliance.get', 'plan.get', 'user.get'])]
private ?string $pathName = null;
#[ORM\OneToMany(mappedBy: 'action_plan_file', targetEntity: ActionPlan::class)]
private Collection $actionsPlanFile;
#[ORM\OneToMany(mappedBy: 'profile_picture', targetEntity: User::class)]
private Collection $profile_picture;
#[ORM\OneToMany(mappedBy: 'evaluation_file', targetEntity: Evaluation::class)]
private Collection $evaluation_file;
public function __construct()
{
$this->illustrationsFile = new ArrayCollection();
$this->summaryFile = new ArrayCollection();
$this->actionsPlanFile = new ArrayCollection();
$this->profile_picture = new ArrayCollection();
$this->evaluation_file = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
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 getUserUpload(): ?User
{
return $this->userUpload;
}
public function setUserUpload(?User $userUpload): self
{
$this->userUpload = $userUpload;
return $this;
}
/**
* @return Collection<int, Document>
*/
public function getIllustrationsFile(): Collection
{
return $this->illustrationsFile;
}
public function addIllustrationsFile(Document $document): self
{
if (!$this->illustrationsFile->contains($document)) {
$this->illustrationsFile->add($document);
$document->setIllustrationsFile($this);
}
return $this;
}
public function removeIllustrationsFile(Document $document): self
{
if ($this->documents->removeElement($document)) {
// set the owning side to null (unless already changed)
if ($document->getIllustrationsFile() === $this) {
$document->setIllustrationsFile(null);
}
}
return $this;
}
/**
* @return Collection<int, Document>
*/
public function getSummaryFile(): Collection
{
return $this->summaryFile;
}
public function addSummaryFile(Document $document): self
{
if (!$this->documents->contains($document)) {
$this->documents->add($document);
$document->setSummaryFile($this);
}
return $this;
}
public function removeSummaryFile(Document $document): self
{
if ($this->documents->removeElement($document)) {
// set the owning side to null (unless already changed)
if ($document->getSummaryFile() === $this) {
$document->setSummaryFile(null);
}
}
return $this;
}
public function getPathName(): ?string
{
return $this->pathName;
}
public function setPathName(string $pathName): self
{
$this->pathName = $pathName;
return $this;
}
/**
* @return Collection<int, ActionPlan>
*/
public function getActionsPlanFile(): Collection
{
return $this->actionsPlanFile;
}
public function addActionsPlanFile(ActionPlan $actionsPlanFile): self
{
if (!$this->actionsPlanFile->contains($actionsPlanFile)) {
$this->actionsPlanFile->add($actionsPlanFile);
$actionsPlanFile->setActionPlanFile($this);
}
return $this;
}
public function removeActionsPlanFile(ActionPlan $actionsPlanFile): self
{
if ($this->actionsPlanFile->removeElement($actionsPlanFile)) {
// set the owning side to null (unless already changed)
if ($actionsPlanFile->getActionPlanFile() === $this) {
$actionsPlanFile->setActionPlanFile(null);
}
}
return $this;
}
/**
* @return Collection<int, Evaluation>
*/
public function getEvaluationFile(): Collection
{
return $this->evaluation_file;
}
public function addEvaluationFile(Evaluation $evaluationFile): self
{
if (!$this->evaluation_file->contains($evaluationFile)) {
$this->evaluation_file->add($evaluationFile);
$evaluationFile->setEvaluationFile($this);
}
return $this;
}
public function removeEvaluationFile(Evaluation $evaluationFile): self
{
if ($this->evaluation_file->removeElement($evaluationFile)) {
// set the owning side to null (unless already changed)
if ($evaluationFile->getEvaluationFile() === $this) {
$evaluationFile->setEvaluationFile(null);
}
}
return $this;
}
/**
* @return Collection<int, User>
*/
public function getProfilePicture(): Collection
{
return $this->profile_picture;
}
public function addProfilePicture(User $profilePicture): self
{
if (!$this->profile_picture->contains($profilePicture)) {
$this->profile_picture->add($profilePicture);
$profilePicture->setProfilePicture($this);
}
return $this;
}
public function removeProfilePicture(User $profilePicture): self
{
if ($this->profile_picture->removeElement($profilePicture)) {
// set the owning side to null (unless already changed)
if ($profilePicture->getProfilePicture() === $this) {
$profilePicture->setProfilePicture(null);
}
}
return $this;
}
}