File.php 19 KB

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