src/Entity/Media.php line 87

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