File.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Core;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Entity\Organization\Organization;
  6. use App\Entity\Person\Person;
  7. use App\Repository\Core\FileRepository;
  8. use DateTime;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use JetBrains\PhpStorm\Pure;
  13. #[ApiResource(
  14. collectionOperations: [],
  15. itemOperations: [
  16. 'get',
  17. 'put'
  18. ]
  19. )]
  20. #[ORM\Entity(repositoryClass: FileRepository::class)]
  21. class File
  22. {
  23. #[ORM\Id]
  24. #[ORM\Column]
  25. #[ORM\GeneratedValue]
  26. private ?int $id = null;
  27. /**
  28. * Propriétaire du fichier
  29. *
  30. * @var Person
  31. */
  32. #[ORM\ManyToOne]
  33. private Person $person;
  34. /**
  35. * Organisation propriétaire du fichier
  36. * @var Organization
  37. */
  38. #[ORM\ManyToOne]
  39. private Organization $organization;
  40. /**
  41. * Slug du fichier (i.e. le chemin d'accès relatif)
  42. * @var string
  43. */
  44. #[ORM\Column(length: 255)]
  45. private string $slug;
  46. /**
  47. * Chemin d'accès du fichier
  48. * @var string
  49. */
  50. #[ORM\Column(length: 255)]
  51. private string $path;
  52. /**
  53. * Nom du fichier
  54. * @var string
  55. */
  56. #[ORM\Column(length: 255)]
  57. private string $name;
  58. /**
  59. * Mimetype du fichier
  60. * @var string|null
  61. */
  62. #[ORM\Column(length: 255, nullable: true)]
  63. private ?string $mimeType = null;
  64. /**
  65. * Visibilité du fichier (tout le monde, personne, l'organisation seulement...)
  66. * @var string
  67. */
  68. #[ORM\Column(length: 24, options: ['default' => 'NOBODY'])]
  69. private string $visibility = 'NOBODY';
  70. /**
  71. * Configuration particulière associée au fichier (exemple: image recadrée)
  72. * @var string|null
  73. */
  74. #[ORM\Column(type: 'text', length: 255, nullable: true)]
  75. private ?string $config;
  76. /**
  77. * Dossier contenant le fichier
  78. * @var string
  79. */
  80. #[ORM\Column(length: 24)]
  81. private string $folder;
  82. /**
  83. * Type de document (uploaded, mail, bill...etc)
  84. * @var string
  85. */
  86. #[ORM\Column(length: 50, options: ['default' => 'NONE'])]
  87. private string $type = "NONE";
  88. /**
  89. * Taille du document en octets
  90. * @var int|null
  91. */
  92. #[ORM\Column]
  93. private ?int $size;
  94. /**
  95. * 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
  96. * Les fichiers temporaires peuvent être supprimés sans risque, à l'inverse des fichiers uploadés par les
  97. * utilisateurs par exemple.
  98. *
  99. * @var boolean
  100. */
  101. #[ORM\Column(options: ['default' => false])]
  102. private bool $isTemporaryFile = false;
  103. /**
  104. * Date de création du fichier
  105. * @var DateTime
  106. */
  107. #[ORM\Column]
  108. private DateTime $createDate;
  109. /**
  110. * Id de l'access ayant créé ce fichier
  111. * @var int|null
  112. */
  113. #[ORM\Column]
  114. private ?int $createdBy;
  115. /**
  116. * Date de dernière mise à jour du fichier
  117. * @var DateTime
  118. */
  119. #[ORM\Column]
  120. private DateTime $updateDate;
  121. /**
  122. * Id de l'access ayant mis à jour ce fichier le dernier
  123. * @var int|null
  124. */
  125. #[ORM\Column]
  126. private ?int $updatedBy;
  127. // #[ORM\Column]
  128. // private ?int $eventReport_id;
  129. //
  130. // #[ORM\Column]
  131. // private ?\DateTime $availabilityDate;
  132. //
  133. // #[ORM\Column]
  134. // private ?int $documentWish_id;
  135. //
  136. // #[ORM\Column]
  137. // private ?int $onlineRegistrationSetting_id;
  138. //
  139. // #[ORM\Column]
  140. // private ?int $templateSystem_id;
  141. //
  142. // #[ORM\Column]
  143. // private ?int $work_id;
  144. #[ORM\OneToMany(mappedBy: 'image', targetEntity: Person::class, orphanRemoval: true)]
  145. private Collection $personImages;
  146. #[ORM\OneToMany(mappedBy: 'logo', targetEntity: Organization::class, orphanRemoval: true)]
  147. private Collection $organizationLogos;
  148. #[ORM\OneToMany(mappedBy: 'image', targetEntity: Organization::class, orphanRemoval: true)]
  149. private Collection $organizationImages;
  150. #[Pure] public function __construct()
  151. {
  152. $this->personImages = new ArrayCollection();
  153. $this->organizationLogos = new ArrayCollection();
  154. $this->organizationImages = new ArrayCollection();
  155. }
  156. public function getId(): ?int
  157. {
  158. return $this->id;
  159. }
  160. /**
  161. * @return Person
  162. */
  163. public function getPerson(): Person
  164. {
  165. return $this->person;
  166. }
  167. /**
  168. * @param Person $person
  169. */
  170. public function setPerson(Person $person): void
  171. {
  172. $this->person = $person;
  173. }
  174. /**
  175. * @return Organization
  176. */
  177. public function getOrganization(): Organization
  178. {
  179. return $this->organization;
  180. }
  181. /**
  182. * @param Organization $organization
  183. */
  184. public function setOrganization(Organization $organization): void
  185. {
  186. $this->organization = $organization;
  187. }
  188. public function getSlug(): string
  189. {
  190. return $this->slug;
  191. }
  192. public function setSlug(string $slug): self
  193. {
  194. $this->slug = $slug;
  195. return $this;
  196. }
  197. public function getPath(): string
  198. {
  199. return $this->path;
  200. }
  201. public function setPath(string $path): self
  202. {
  203. $this->path = $path;
  204. return $this;
  205. }
  206. public function getName(): string
  207. {
  208. return $this->name;
  209. }
  210. public function setName(string $name): self
  211. {
  212. $this->name = $name;
  213. return $this;
  214. }
  215. public function getMimeType(): ?string
  216. {
  217. return $this->mimeType;
  218. }
  219. public function setMimeType(?string $mimeType): self
  220. {
  221. $this->mimeType = $mimeType;
  222. return $this;
  223. }
  224. public function getConfig(): string
  225. {
  226. return $this->config;
  227. }
  228. public function setConfig(string $config): self
  229. {
  230. $this->config = $config;
  231. return $this;
  232. }
  233. public function getPersonImages(): Collection
  234. {
  235. return $this->personImages;
  236. }
  237. public function addPersonImage (Person $person): self
  238. {
  239. if (!$this->personImages->contains($person)) {
  240. $this->personImages[] = $person;
  241. $person->setImage($this);
  242. }
  243. return $this;
  244. }
  245. public function removePersonImage(Person $person): self
  246. {
  247. if ($this->personImages->removeElement($person)) {
  248. // set the owning side to null (unless already changed)
  249. if ($person->getImage() === $this) {
  250. $person->setImage(null);
  251. }
  252. }
  253. return $this;
  254. }
  255. /**
  256. * @return string
  257. */
  258. public function getVisibility(): string
  259. {
  260. return $this->visibility;
  261. }
  262. /**
  263. * @param string $visibility
  264. */
  265. public function setVisibility(string $visibility): void
  266. {
  267. $this->visibility = $visibility;
  268. }
  269. /**
  270. * @return string
  271. */
  272. public function getFolder(): string
  273. {
  274. return $this->folder;
  275. }
  276. /**
  277. * @param string $folder
  278. */
  279. public function setFolder(string $folder): void
  280. {
  281. $this->folder = $folder;
  282. }
  283. /**
  284. * @return string
  285. */
  286. public function getType(): string
  287. {
  288. return $this->type;
  289. }
  290. /**
  291. * @param string $type
  292. */
  293. public function setType(string $type): void
  294. {
  295. $this->type = $type;
  296. }
  297. /**
  298. * @return int|null
  299. */
  300. public function getSize(): ?int
  301. {
  302. return $this->size;
  303. }
  304. /**
  305. * @param int|null $size
  306. */
  307. public function setSize(?int $size): void
  308. {
  309. $this->size = $size;
  310. }
  311. /**
  312. * @return bool
  313. */
  314. public function getIsTemporaryFile(): bool
  315. {
  316. return $this->isTemporaryFile;
  317. }
  318. /**
  319. * @param bool $isTemporaryFile
  320. */
  321. public function setIsTemporaryFile(bool $isTemporaryFile): void
  322. {
  323. $this->isTemporaryFile = $isTemporaryFile;
  324. }
  325. /**
  326. * @return DateTime
  327. */
  328. public function getCreateDate(): DateTime
  329. {
  330. return $this->createDate;
  331. }
  332. /**
  333. * @param DateTime $createDate
  334. */
  335. public function setCreateDate(DateTime $createDate): void
  336. {
  337. $this->createDate = $createDate;
  338. }
  339. /**
  340. * @return int|null
  341. */
  342. public function getCreatedBy(): ?int
  343. {
  344. return $this->createdBy;
  345. }
  346. /**
  347. * @param int|null $createdBy
  348. */
  349. public function setCreatedBy(?int $createdBy): void
  350. {
  351. $this->createdBy = $createdBy;
  352. }
  353. /**
  354. * @return DateTime
  355. */
  356. public function getUpdateDate(): DateTime
  357. {
  358. return $this->updateDate;
  359. }
  360. /**
  361. * @param DateTime $updateDate
  362. */
  363. public function setUpdateDate(DateTime $updateDate): void
  364. {
  365. $this->updateDate = $updateDate;
  366. }
  367. /**
  368. * @return int|null
  369. */
  370. public function getUpdatedBy(): ?int
  371. {
  372. return $this->updatedBy;
  373. }
  374. /**
  375. * @param int|null $updatedBy
  376. */
  377. public function setUpdatedBy(?int $updatedBy): void
  378. {
  379. $this->updatedBy = $updatedBy;
  380. }
  381. public function getOrganizationLogos(): Collection
  382. {
  383. return $this->organizationLogos;
  384. }
  385. public function addOrganizationLogo(Organization $organization): self
  386. {
  387. if (!$this->organizationLogos->contains($organization)) {
  388. $this->organizationLogos[] = $organization;
  389. $organization->setLogo($this);
  390. }
  391. return $this;
  392. }
  393. public function removeOrganizationLogo(Organization $organization): self
  394. {
  395. if ($this->organizationLogos->removeElement($organization)) {
  396. // set the owning side to null (unless already changed)
  397. if ($organization->getLogo() === $this) {
  398. $organization->setLogo(null);
  399. }
  400. }
  401. return $this;
  402. }
  403. public function getOrganizationImages(): Collection
  404. {
  405. return $this->organizationImages;
  406. }
  407. public function addOrganizationImage(Organization $organization): self
  408. {
  409. if (!$this->organizationImages->contains($organization)) {
  410. $this->organizationImages[] = $organization;
  411. $organization->setImage($this);
  412. }
  413. return $this;
  414. }
  415. public function removeOrganizationImage(Organization $organization): self
  416. {
  417. if ($this->organizationImages->removeElement($organization)) {
  418. // set the owning side to null (unless already changed)
  419. if ($organization->getImage() === $this) {
  420. $organization->setImage(null);
  421. }
  422. }
  423. return $this;
  424. }
  425. }