src/Entity/Media.php line 88

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Delete;
  5. use ApiPlatform\Metadata\GetCollection;
  6. use ApiPlatform\Metadata\Post;
  7. use ApiPlatform\Metadata\Put;
  8. use ApiPlatform\Metadata\Get;
  9. use App\Controller\Action\ImageMediaController;
  10. use App\Controller\Action\UploadFileController;
  11. use App\Repository\MediaRepository;
  12. use App\Traits\AutoTimestampTrait;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. use Doctrine\Common\Collections\Collection;
  15. use Doctrine\DBAL\Types\Types;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use Symfony\Component\Serializer\Annotation\Groups;
  18. #[ORM\Entity(repositoryClassMediaRepository::class)]
  19. #[ApiResource(
  20.     operations: [
  21.         new GetCollection(),
  22.         new Post(
  23.             security'user.isMasterAdmin()',
  24.         ),
  25.         new Get(),
  26.         new Post(
  27.             security'user.isMasterAdmin()',
  28.             uriTemplate'upload_file',
  29.             controllerUploadFileController::class,
  30.             openapiContext: [
  31.                 'requestBody' => [
  32.                     'content' => [
  33.                         'multipart/form-data' => [
  34.                             'schema' => [
  35.                                 'type' => 'object',
  36.                                 'properties' => [
  37.                                     'type' => [
  38.                                         'type' => 'string',
  39.                                         'format' => 'string'
  40.                                     ],
  41.                                     'url' => [
  42.                                         'type' => 'string',
  43.                                         'format' => 'string'
  44.                                     ],
  45.                                     'idDoc' => [
  46.                                         'type' => 'int',
  47.                                         'format' => 'int'
  48.                                     ],
  49.                                     'illustrationsFile' => [
  50.                                         'type' => 'string',
  51.                                         'format' => 'binary'
  52.                                     ],
  53.                                     'summaryFile' => [
  54.                                         'type' => 'string',
  55.                                         'format' => 'binary'
  56.                                     ],
  57.                                 ]
  58.                             ]
  59.                         ]
  60.                     ]
  61.                 ]
  62.             ],
  63.             deserializefalse,
  64.             validatefalse,
  65.             name'_api_/upload_file'
  66.         ),
  67.         new Put(
  68.             security'user.isMasterAdmin()',
  69.         ),
  70.         new Get(
  71.             uriTemplate'/media_picture',
  72.             controllerImageMediaController::class,
  73.             readfalse,
  74.             writefalse,
  75.             name'_api_/media_picture'
  76.         ),
  77.         new Delete(
  78.             security'user.isMasterAdmin()',
  79.         ),
  80.         ],
  81. )]
  82. #[ORM\HasLifecycleCallbacks]
  83. class Media
  84. {
  85.     use AutoTimestampTrait;
  86.     #[ORM\Id]
  87.     #[ORM\GeneratedValue]
  88.     #[ORM\Column]
  89.     #[Groups(['document.get''plan.get''compliance.get''user.get'])]
  90.     private ?int $id null;
  91.     #[ORM\Column(length255)]
  92.     #[Groups(['document.get'])]
  93.     private ?string $type null;
  94.     #[ORM\Column(length255)]
  95.     #[Groups(['document.get''plan.get''compliance.get''user.get'])]
  96.     private ?string $name null;
  97.     #[ORM\ManyToOne]
  98.     private ?User $userUpload null;
  99.     #[ORM\OneToMany(mappedBy'illustrationsFile'targetEntityDocument::class)]
  100.     private Collection $illustrationsFile;
  101.     #[ORM\OneToMany(mappedBy'summaryFile'targetEntityDocument::class)]
  102.     private Collection $summaryFile;
  103.     #[ORM\Column(length255)]
  104.     #[Groups(['document.get','compliance.get''plan.get''user.get'])]
  105.     private ?string $pathName null;
  106.     #[ORM\OneToMany(mappedBy'action_plan_file'targetEntityActionPlan::class)]
  107.     private Collection $actionsPlanFile;
  108.     #[ORM\OneToMany(mappedBy'profile_picture'targetEntityUser::class)]
  109.     private Collection $profile_picture;
  110.     #[ORM\OneToMany(mappedBy'evaluation_file'targetEntityEvaluation::class)]
  111.     private Collection $evaluation_file;
  112.     public function __construct()
  113.     {
  114.         $this->illustrationsFile = new ArrayCollection();
  115.         $this->summaryFile = new ArrayCollection();
  116.         $this->actionsPlanFile = new ArrayCollection();
  117.         $this->profile_picture = new ArrayCollection();
  118.         $this->evaluation_file = new ArrayCollection();
  119.     }
  120.     public function getId(): ?int
  121.     {
  122.         return $this->id;
  123.     }
  124.     public function getType(): ?string
  125.     {
  126.         return $this->type;
  127.     }
  128.     public function setType(string $type): self
  129.     {
  130.         $this->type $type;
  131.         return $this;
  132.     }
  133.     public function getName(): ?string
  134.     {
  135.         return $this->name;
  136.     }
  137.     public function setName(string $name): self
  138.     {
  139.         $this->name $name;
  140.         return $this;
  141.     }
  142.     public function getUserUpload(): ?User
  143.     {
  144.         return $this->userUpload;
  145.     }
  146.     public function setUserUpload(?User $userUpload): self
  147.     {
  148.         $this->userUpload $userUpload;
  149.         return $this;
  150.     }
  151.     /**
  152.      * @return Collection<int, Document>
  153.      */
  154.     public function getIllustrationsFile(): Collection
  155.     {
  156.         return $this->illustrationsFile;
  157.     }
  158.     public function addIllustrationsFile(Document $document): self
  159.     {
  160.         if (!$this->illustrationsFile->contains($document)) {
  161.             $this->illustrationsFile->add($document);
  162.             $document->setIllustrationsFile($this);
  163.         }
  164.         return $this;
  165.     }
  166.     public function removeIllustrationsFile(Document $document): self
  167.     {
  168.         if ($this->documents->removeElement($document)) {
  169.             // set the owning side to null (unless already changed)
  170.             if ($document->getIllustrationsFile() === $this) {
  171.                 $document->setIllustrationsFile(null);
  172.             }
  173.         }
  174.         return $this;
  175.     }
  176.     /**
  177.      * @return Collection<int, Document>
  178.      */
  179.     public function getSummaryFile(): Collection
  180.     {
  181.         return $this->summaryFile;
  182.     }
  183.     public function addSummaryFile(Document $document): self
  184.     {
  185.         if (!$this->documents->contains($document)) {
  186.             $this->documents->add($document);
  187.             $document->setSummaryFile($this);
  188.         }
  189.         return $this;
  190.     }
  191.     public function removeSummaryFile(Document $document): self
  192.     {
  193.         if ($this->documents->removeElement($document)) {
  194.             // set the owning side to null (unless already changed)
  195.             if ($document->getSummaryFile() === $this) {
  196.                 $document->setSummaryFile(null);
  197.             }
  198.         }
  199.         return $this;
  200.     }
  201.     public function getPathName(): ?string
  202.     {
  203.         return $this->pathName;
  204.     }
  205.     public function setPathName(string $pathName): self
  206.     {
  207.         $this->pathName $pathName;
  208.         return $this;
  209.     }
  210.     /**
  211.      * @return Collection<int, ActionPlan>
  212.      */
  213.     public function getActionsPlanFile(): Collection
  214.     {
  215.         return $this->actionsPlanFile;
  216.     }
  217.     public function addActionsPlanFile(ActionPlan $actionsPlanFile): self
  218.     {
  219.         if (!$this->actionsPlanFile->contains($actionsPlanFile)) {
  220.             $this->actionsPlanFile->add($actionsPlanFile);
  221.             $actionsPlanFile->setActionPlanFile($this);
  222.         }
  223.         return $this;
  224.     }
  225.     public function removeActionsPlanFile(ActionPlan $actionsPlanFile): self
  226.     {
  227.         if ($this->actionsPlanFile->removeElement($actionsPlanFile)) {
  228.             // set the owning side to null (unless already changed)
  229.             if ($actionsPlanFile->getActionPlanFile() === $this) {
  230.                 $actionsPlanFile->setActionPlanFile(null);
  231.             }
  232.         }
  233.         return $this;
  234.     }
  235.     /**
  236.      * @return Collection<int, Evaluation>
  237.      */
  238.     public function getEvaluationFile(): Collection
  239.     {
  240.         return $this->evaluation_file;
  241.     }
  242.     public function addEvaluationFile(Evaluation $evaluationFile): self
  243.     {
  244.         if (!$this->evaluation_file->contains($evaluationFile)) {
  245.             $this->evaluation_file->add($evaluationFile);
  246.             $evaluationFile->setEvaluationFile($this);
  247.         }
  248.         return $this;
  249.     }
  250.     public function removeEvaluationFile(Evaluation $evaluationFile): self
  251.     {
  252.         if ($this->evaluation_file->removeElement($evaluationFile)) {
  253.             // set the owning side to null (unless already changed)
  254.             if ($evaluationFile->getEvaluationFile() === $this) {
  255.                 $evaluationFile->setEvaluationFile(null);
  256.             }
  257.         }
  258.         return $this;
  259.     }
  260.     /**
  261.      * @return Collection<int, User>
  262.      */
  263.     public function getProfilePicture(): Collection
  264.     {
  265.         return $this->profile_picture;
  266.     }
  267.     public function addProfilePicture(User $profilePicture): self
  268.     {
  269.         if (!$this->profile_picture->contains($profilePicture)) {
  270.             $this->profile_picture->add($profilePicture);
  271.             $profilePicture->setProfilePicture($this);
  272.         }
  273.         return $this;
  274.     }
  275.     public function removeProfilePicture(User $profilePicture): self
  276.     {
  277.         if ($this->profile_picture->removeElement($profilePicture)) {
  278.             // set the owning side to null (unless already changed)
  279.             if ($profilePicture->getProfilePicture() === $this) {
  280.                 $profilePicture->setProfilePicture(null);
  281.             }
  282.         }
  283.         return $this;
  284.     }
  285. }