File.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. <?php
  2. declare (strict_types=1);
  3. namespace App\Entity\Core;
  4. use ApiPlatform\Metadata\Put;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\ApiResource;
  7. use App\Entity\AccessWish\DocumentWish;
  8. use App\Entity\Booking\Event;
  9. use App\Entity\Booking\EventReport;
  10. use App\Entity\Booking\Work;
  11. use App\Entity\Message\TemplateSystem;
  12. use App\Entity\Organization\Activity;
  13. use App\Entity\Organization\OnlineRegistrationSettings;
  14. use App\Entity\Organization\Organization;
  15. use App\Entity\Person\Person;
  16. use App\Enum\Core\FileHostEnum;
  17. use App\Repository\Core\FileRepository;
  18. use App\Entity\Organization\Parameters;
  19. use DateTime;
  20. //use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
  21. use Doctrine\Common\Collections\ArrayCollection;
  22. use Doctrine\Common\Collections\Collection;
  23. use Doctrine\ORM\Mapping as ORM;
  24. use JetBrains\PhpStorm\Pure;
  25. use Symfony\Component\Serializer\Annotation\Groups;
  26. use Symfony\Component\Validator\Constraints as Assert;
  27. use App\Enum\Core\FileStatusEnum;
  28. #[ApiResource(
  29. operations: [
  30. new Get(),
  31. new Put()
  32. ]
  33. )]
  34. //#[Auditable]
  35. #[ORM\Entity(repositoryClass: FileRepository::class)]
  36. class File
  37. {
  38. #[ORM\Id]
  39. #[ORM\Column]
  40. #[ORM\GeneratedValue]
  41. private ?int $id = null;
  42. /**
  43. * Propriétaire du fichier
  44. *
  45. * @var Person|null
  46. */
  47. #[ORM\ManyToOne(inversedBy: 'files')]
  48. #[ORM\JoinColumn(name: 'person_id', referencedColumnName: 'id')]
  49. private ?Person $person;
  50. /**
  51. * Organisation propriétaire du fichier
  52. * @var Organization|null
  53. */
  54. #[ORM\ManyToOne(inversedBy: 'files')]
  55. #[ORM\JoinColumn(name: 'organization_id', referencedColumnName: 'id')]
  56. private ?Organization $organization;
  57. /**
  58. * Slug du fichier (i.e. le chemin d'accès relatif)
  59. * @var string|null
  60. */
  61. #[ORM\Column(length: 255)]
  62. private ?string $slug = null;
  63. /**
  64. * Chemin d'accès du fichier
  65. * @var string|null
  66. */
  67. #[ORM\Column(length: 255)]
  68. private ?string $path = null;
  69. /**
  70. * Nom du fichier
  71. * @var string
  72. */
  73. #[ORM\Column(length: 255)]
  74. private string $name;
  75. /**
  76. * Mimetype du fichier
  77. * @var string|null
  78. */
  79. #[ORM\Column(length: 255, nullable: true)]
  80. private ?string $mimeType = null;
  81. /**
  82. * Visibilité du fichier (tout le monde, personne, l'organisation seulement...)
  83. * @var string
  84. */
  85. #[ORM\Column(length: 24, options: ['default' => 'NOBODY'])]
  86. private string $visibility = 'NOBODY';
  87. /**
  88. * Configuration particulière associée au fichier (exemple: image recadrée)
  89. * @var string|null
  90. */
  91. #[ORM\Column(type: 'text', length: 255, nullable: true)]
  92. private ?string $config;
  93. /**
  94. * Type de document (uploaded, mail, bill...etc)
  95. * @var string
  96. */
  97. #[ORM\Column(length: 50, options: ['default' => 'NONE'])]
  98. private string $type = "NONE";
  99. /**
  100. * Taille du document en octets
  101. * @var int|null
  102. */
  103. #[ORM\Column]
  104. private ?int $size;
  105. /**
  106. * Un fichier est temporaire par exemple s'il a été généré et est stocké pour être téléchargé dans la foulée
  107. * Les fichiers temporaires peuvent être supprimés sans risque, à l'inverse des fichiers uploadés par les
  108. * utilisateurs par exemple.
  109. *
  110. * @var boolean
  111. */
  112. #[ORM\Column(options: ['default' => false])]
  113. private bool $isTemporaryFile = false;
  114. /**
  115. * Date de création du fichier
  116. * @var DateTime
  117. */
  118. #[ORM\Column]
  119. private DateTime $createDate;
  120. /**
  121. * Id de l'access ayant créé ce fichier
  122. * @var int|null
  123. */
  124. #[ORM\Column]
  125. private ?int $createdBy;
  126. /**
  127. * Date de dernière mise à jour du fichier
  128. * @var DateTime
  129. */
  130. #[ORM\Column]
  131. private DateTime $updateDate;
  132. /**
  133. * Id de l'access ayant mis à jour ce fichier le dernier
  134. * @var int|null
  135. */
  136. #[ORM\Column]
  137. private ?int $updatedBy;
  138. /**
  139. * Statut du fichier (en cours de génération, prêt, supprimé, etc.)
  140. * @var string | null
  141. */
  142. #[ORM\Column(length: 50)]
  143. #[Assert\Choice(callback: [FileStatusEnum::class, 'toArray'])]
  144. private ?string $status = null;
  145. /**
  146. * Serveur sur lequel le fichier est physiquement stocké
  147. * @var string | null
  148. */
  149. #[ORM\Column(length: 5)]
  150. #[Assert\Choice(callback: [FileHostEnum::class, 'toArray'])]
  151. private ?string $host = 'ap2i';
  152. // #[ORM\Column]
  153. // private ?int $eventReport_id;
  154. //
  155. // #[ORM\Column]
  156. // private ?\DateTime $availabilityDate;
  157. //
  158. // #[ORM\Column]
  159. // private ?int $documentWish_id;
  160. //
  161. // #[ORM\Column]
  162. // private ?int $onlineRegistrationSetting_id;
  163. //
  164. // #[ORM\Column]
  165. // private ?int $templateSystem_id;
  166. //
  167. // #[ORM\Column]
  168. // private ?int $work_id;
  169. #[ORM\ManyToMany(targetEntity: Person::class, inversedBy: 'personFiles')]
  170. #[Groups(['file_person'])]
  171. private Collection $accessPersons;
  172. #[ORM\OneToMany(mappedBy: 'image', targetEntity: Person::class, orphanRemoval: true)]
  173. private Collection $personImages;
  174. #[ORM\OneToMany(mappedBy: 'logo', targetEntity: Organization::class, orphanRemoval: true)]
  175. private Collection $organizationLogos;
  176. #[ORM\OneToMany(mappedBy: 'image', targetEntity: Organization::class, orphanRemoval: true)]
  177. private Collection $organizationImages;
  178. #[ORM\OneToOne(mappedBy: "qrCode", targetEntity: Parameters::class, fetch: 'EAGER')]
  179. private Parameters $qrCode;
  180. #[ORM\OneToMany(mappedBy: 'image', targetEntity: Event::class)]
  181. private Collection $events;
  182. #[ORM\OneToMany(mappedBy: 'logo', targetEntity: Activity::class)]
  183. private Collection $activityLogos;
  184. #[ORM\OneToMany(mappedBy: 'imageActivity', targetEntity: Activity::class)]
  185. private Collection $activityImages;
  186. #[ORM\ManyToOne(inversedBy: 'files')]
  187. #[ORM\JoinColumn(onDelete: 'CASCADE')]
  188. private EventReport $eventReport;
  189. #[ORM\ManyToOne(cascade: ['persist'], inversedBy: 'files')]
  190. #[ORM\JoinColumn(onDelete: 'CASCADE')]
  191. private DocumentWish $documentWish;
  192. #[ORM\ManyToOne(cascade: ['persist'], inversedBy: 'introductionFiles')]
  193. #[ORM\JoinColumn(onDelete: 'CASCADE')]
  194. private OnlineRegistrationSettings $onlineRegistrationSetting;
  195. #[ORM\ManyToOne(cascade: ['persist'], inversedBy: 'introductionFilesNewEnrolments')]
  196. #[ORM\JoinColumn(onDelete: 'CASCADE')]
  197. private OnlineRegistrationSettings $onlineRegistrationSettingNewEnrolments;
  198. #[ORM\ManyToOne(cascade: ['persist'], inversedBy: 'files')]
  199. #[ORM\JoinColumn(onDelete: 'CASCADE')]
  200. private Work $work;
  201. #[ORM\ManyToOne(cascade: ['persist'], inversedBy: 'files')]
  202. #[ORM\JoinColumn(onDelete: 'CASCADE')]
  203. private TemplateSystem $templateSystem;
  204. #[Pure]
  205. public function __construct()
  206. {
  207. $this->personImages = new ArrayCollection();
  208. $this->organizationLogos = new ArrayCollection();
  209. $this->organizationImages = new ArrayCollection();
  210. $this->accessPersons = new ArrayCollection();
  211. $this->events = new ArrayCollection();
  212. $this->activityLogos = new ArrayCollection();
  213. $this->activityImages = new ArrayCollection();
  214. }
  215. public function getId(): ?int
  216. {
  217. return $this->id;
  218. }
  219. /**
  220. * @return Person|null
  221. */
  222. public function getPerson(): ?Person
  223. {
  224. return $this->person;
  225. }
  226. /**
  227. * @param Person|null $person
  228. * @return File
  229. */
  230. public function setPerson(?Person $person): File
  231. {
  232. $this->person = $person;
  233. return $this;
  234. }
  235. /**
  236. * @return Organization|null
  237. */
  238. public function getOrganization(): ?Organization
  239. {
  240. return $this->organization;
  241. }
  242. /**
  243. * @param Organization|null $organization
  244. * @return File
  245. */
  246. public function setOrganization(?Organization $organization): File
  247. {
  248. $this->organization = $organization;
  249. return $this;
  250. }
  251. public function getSlug(): ?string
  252. {
  253. return $this->slug;
  254. }
  255. public function setSlug(?string $slug): self
  256. {
  257. $this->slug = $slug;
  258. return $this;
  259. }
  260. public function getPath(): ?string
  261. {
  262. return $this->path;
  263. }
  264. public function setPath(?string $path): self
  265. {
  266. $this->path = $path;
  267. return $this;
  268. }
  269. public function getName(): string
  270. {
  271. return $this->name;
  272. }
  273. public function setName(string $name): self
  274. {
  275. $this->name = $name;
  276. return $this;
  277. }
  278. public function getMimeType(): ?string
  279. {
  280. return $this->mimeType;
  281. }
  282. public function setMimeType(?string $mimeType): self
  283. {
  284. $this->mimeType = $mimeType;
  285. return $this;
  286. }
  287. public function getConfig(): string
  288. {
  289. return $this->config;
  290. }
  291. public function setConfig(string $config): self
  292. {
  293. $this->config = $config;
  294. return $this;
  295. }
  296. public function getPersonImages(): Collection
  297. {
  298. return $this->personImages;
  299. }
  300. public function addPersonImage(Person $person): self
  301. {
  302. if (!$this->personImages->contains($person)) {
  303. $this->personImages[] = $person;
  304. $person->setImage($this);
  305. }
  306. return $this;
  307. }
  308. public function removePersonImage(Person $person): self
  309. {
  310. // set the owning side to null (unless already changed)
  311. if ($this->personImages->removeElement($person) && $person->getImage() === $this) {
  312. $person->setImage(null);
  313. }
  314. return $this;
  315. }
  316. /**
  317. * @return string
  318. */
  319. public function getVisibility(): string
  320. {
  321. return $this->visibility;
  322. }
  323. /**
  324. * @param string $visibility
  325. * @return File
  326. */
  327. public function setVisibility(string $visibility): File
  328. {
  329. $this->visibility = $visibility;
  330. return $this;
  331. }
  332. /**
  333. * @return string
  334. */
  335. public function getType(): string
  336. {
  337. return $this->type;
  338. }
  339. /**
  340. * @param string $type
  341. * @return File
  342. */
  343. public function setType(string $type): File
  344. {
  345. $this->type = $type;
  346. return $this;
  347. }
  348. /**
  349. * @return int|null
  350. */
  351. public function getSize(): ?int
  352. {
  353. return $this->size;
  354. }
  355. /**
  356. * @param int|null $size
  357. * @return File
  358. */
  359. public function setSize(?int $size): File
  360. {
  361. $this->size = $size;
  362. return $this;
  363. }
  364. /**
  365. * @return bool
  366. */
  367. public function getIsTemporaryFile(): bool
  368. {
  369. return $this->isTemporaryFile;
  370. }
  371. /**
  372. * @param bool $isTemporaryFile
  373. * @return File
  374. */
  375. public function setIsTemporaryFile(bool $isTemporaryFile): File
  376. {
  377. $this->isTemporaryFile = $isTemporaryFile;
  378. return $this;
  379. }
  380. /**
  381. * @return DateTime
  382. */
  383. public function getCreateDate(): DateTime
  384. {
  385. return $this->createDate;
  386. }
  387. /**
  388. * @param DateTime $createDate
  389. * @return File
  390. */
  391. public function setCreateDate(DateTime $createDate): File
  392. {
  393. $this->createDate = $createDate;
  394. return $this;
  395. }
  396. /**
  397. * @return int|null
  398. */
  399. public function getCreatedBy(): ?int
  400. {
  401. return $this->createdBy;
  402. }
  403. /**
  404. * @param int|null $createdBy
  405. * @return File
  406. */
  407. public function setCreatedBy(?int $createdBy): File
  408. {
  409. $this->createdBy = $createdBy;
  410. return $this;
  411. }
  412. /**
  413. * @return DateTime
  414. */
  415. public function getUpdateDate(): DateTime
  416. {
  417. return $this->updateDate;
  418. }
  419. /**
  420. * @param DateTime $updateDate
  421. * @return File
  422. */
  423. public function setUpdateDate(DateTime $updateDate): File
  424. {
  425. $this->updateDate = $updateDate;
  426. return $this;
  427. }
  428. /**
  429. * @return int|null
  430. */
  431. public function getUpdatedBy(): ?int
  432. {
  433. return $this->updatedBy;
  434. }
  435. /**
  436. * @param int|null $updatedBy
  437. * @return File
  438. */
  439. public function setUpdatedBy(?int $updatedBy): File
  440. {
  441. $this->updatedBy = $updatedBy;
  442. return $this;
  443. }
  444. /**
  445. * @return string|null
  446. */
  447. public function getStatus(): ?string
  448. {
  449. return $this->status;
  450. }
  451. /**
  452. * @param string|null $status
  453. * @return File
  454. */
  455. public function setStatus(?string $status): File
  456. {
  457. $this->status = $status;
  458. return $this;
  459. }
  460. /**
  461. * @return string|null
  462. */
  463. public function getHost(): ?string
  464. {
  465. return $this->host;
  466. }
  467. /**
  468. * @param string|null $host
  469. */
  470. public function setHost(?string $host): void
  471. {
  472. $this->host = $host;
  473. }
  474. public function getOrganizationLogos(): Collection
  475. {
  476. return $this->organizationLogos;
  477. }
  478. public function addOrganizationLogo(Organization $organization): self
  479. {
  480. if (!$this->organizationLogos->contains($organization)) {
  481. $this->organizationLogos[] = $organization;
  482. $organization->setLogo($this);
  483. }
  484. return $this;
  485. }
  486. public function removeOrganizationLogo(Organization $organization): self
  487. {
  488. // set the owning side to null (unless already changed)
  489. if ($this->organizationLogos->removeElement($organization) && $organization->getLogo() === $this) {
  490. $organization->setLogo(null);
  491. }
  492. return $this;
  493. }
  494. public function getOrganizationImages(): Collection
  495. {
  496. return $this->organizationImages;
  497. }
  498. public function addOrganizationImage(Organization $organization): self
  499. {
  500. if (!$this->organizationImages->contains($organization)) {
  501. $this->organizationImages[] = $organization;
  502. $organization->setImage($this);
  503. }
  504. return $this;
  505. }
  506. public function removeOrganizationImage(Organization $organization): self
  507. {
  508. // set the owning side to null (unless already changed)
  509. if ($this->organizationImages->removeElement($organization) && $organization->getImage() === $this) {
  510. $organization->setImage(null);
  511. }
  512. return $this;
  513. }
  514. public function getQrCode(): Parameters
  515. {
  516. return $this->qrCode;
  517. }
  518. public function setQrCode(Parameters $qrCode): self
  519. {
  520. $this->qrCode = $qrCode;
  521. return $this;
  522. }
  523. /**
  524. * @return Collection<int, Person>
  525. */
  526. public function getAccessPersons(): Collection
  527. {
  528. return $this->accessPersons;
  529. }
  530. public function addAccessPerson(Person $accessPerson): self
  531. {
  532. if (!$this->accessPersons->contains($accessPerson)) {
  533. $this->accessPersons[] = $accessPerson;
  534. }
  535. return $this;
  536. }
  537. public function removeAccessPerson(Person $accessPerson): self
  538. {
  539. $this->accessPersons->removeElement($accessPerson);
  540. return $this;
  541. }
  542. /**
  543. * @return Collection<int, Event>
  544. */
  545. public function getEvents(): Collection
  546. {
  547. return $this->events;
  548. }
  549. public function addEvent(Event $event): self
  550. {
  551. if (!$this->events->contains($event)) {
  552. $this->events[] = $event;
  553. $event->setImage($this);
  554. }
  555. return $this;
  556. }
  557. public function removeEvent(Event $event): self
  558. {
  559. // set the owning side to null (unless already changed)
  560. if ($this->events->removeElement($event) && $event->getImage() === $this) {
  561. $event->setImage(null);
  562. }
  563. return $this;
  564. }
  565. /**
  566. * @return Collection<int, Activity>
  567. */
  568. public function getActivityLogos(): Collection
  569. {
  570. return $this->activityLogos;
  571. }
  572. public function addActivityLogo(Activity $activityLogo): self
  573. {
  574. if (!$this->activityLogos->contains($activityLogo)) {
  575. $this->activityLogos[] = $activityLogo;
  576. $activityLogo->setLogo($this);
  577. }
  578. return $this;
  579. }
  580. public function removeActivityLogo(Activity $activityLogo): self
  581. {
  582. // set the owning side to null (unless already changed)
  583. if ($this->activityLogos->removeElement($activityLogo) && $activityLogo->getLogo() === $this) {
  584. $activityLogo->setLogo(null);
  585. }
  586. return $this;
  587. }
  588. /**
  589. * @return Collection<int, Activity>
  590. */
  591. public function getActivityImages(): Collection
  592. {
  593. return $this->activityImages;
  594. }
  595. public function addActivityImage(Activity $activityImage): self
  596. {
  597. if (!$this->activityImages->contains($activityImage)) {
  598. $this->activityImages[] = $activityImage;
  599. $activityImage->setImageActivity($this);
  600. }
  601. return $this;
  602. }
  603. public function removeActivityImage(Activity $activityImage): self
  604. {
  605. // set the owning side to null (unless already changed)
  606. if ($this->activityImages->removeElement($activityImage) && $activityImage->getImageActivity() === $this) {
  607. $activityImage->setImageActivity(null);
  608. }
  609. return $this;
  610. }
  611. public function getEventReport(): ?EventReport
  612. {
  613. return $this->eventReport;
  614. }
  615. public function setEventReport(?EventReport $eventReport): self
  616. {
  617. $this->eventReport = $eventReport;
  618. return $this;
  619. }
  620. public function getDocumentWish(): ?DocumentWish
  621. {
  622. return $this->documentWish;
  623. }
  624. public function setDocumentWish(?DocumentWish $documentWish): self
  625. {
  626. $this->documentWish = $documentWish;
  627. return $this;
  628. }
  629. public function getOnlineRegistrationSetting(): ?OnlineRegistrationSettings
  630. {
  631. return $this->onlineRegistrationSetting;
  632. }
  633. public function setOnlineRegistrationSetting(?OnlineRegistrationSettings $onlineRegistrationSetting): self
  634. {
  635. $this->onlineRegistrationSetting = $onlineRegistrationSetting;
  636. return $this;
  637. }
  638. public function getOnlineRegistrationSettingNewEnrolments(): ?OnlineRegistrationSettings
  639. {
  640. return $this->onlineRegistrationSettingNewEnrolments;
  641. }
  642. public function setOnlineRegistrationSettingNewEnrolments(?OnlineRegistrationSettings $onlineRegistrationSettingNewEnrolments): self
  643. {
  644. $this->onlineRegistrationSettingNewEnrolments = $onlineRegistrationSettingNewEnrolments;
  645. return $this;
  646. }
  647. public function getWork(): ?Work
  648. {
  649. return $this->work;
  650. }
  651. public function setWork(?Work $work): self
  652. {
  653. $this->work = $work;
  654. return $this;
  655. }
  656. public function getTemplateSystem(): ?TemplateSystem
  657. {
  658. return $this->templateSystem;
  659. }
  660. public function setTemplateSystem(?TemplateSystem $templateSystem): self
  661. {
  662. $this->templateSystem = $templateSystem;
  663. return $this;
  664. }
  665. }