src/Entity/Action.php line 23

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use App\Repository\ActionRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. use Symfony\Component\HttpFoundation\File\File;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. /**
  13. * Action.
  14. *
  15. * @ORM\Table(name="Action")
  16. *
  17. * @ORM\Entity(repositoryClass=ActionRepository::class)
  18. */
  19. class Action
  20. {
  21. /**
  22. * @var int
  23. *
  24. * @ORM\Column(name="id", type="integer")
  25. *
  26. * @ORM\Id
  27. *
  28. * @ORM\GeneratedValue(strategy="AUTO")
  29. */
  30. private $id;
  31. /**
  32. * @var string
  33. *
  34. * @ORM\Column(name="intitule", type="string", length=255, nullable=true)
  35. */
  36. private $intitule;
  37. /**
  38. * @var string
  39. *
  40. * @ORM\Column(name="referent", type="string", length=255, nullable=true)
  41. */
  42. private $referent;
  43. #[Assert\File(maxSize: '1024k', mimeTypes: ['application/pdf', 'application/x-pdf'], mimeTypesMessage: 'Please upload a valid PDF')]
  44. protected $document;
  45. /**
  46. * @var string
  47. *
  48. * @ORM\Column(name="email", type="string", length=255, nullable=true)
  49. */
  50. private $email;
  51. /**
  52. * @var string
  53. *
  54. * @ORM\Column(name="descriptif", type="text", nullable=true)
  55. */
  56. private $descriptif;
  57. /**
  58. * @var string
  59. *
  60. * @ORM\Column(name="origine", type="text", nullable=true)
  61. */
  62. private $origine;
  63. /**
  64. * @var string
  65. *
  66. * @ORM\Column(name="objectif", type="text", nullable=true)
  67. */
  68. private $objectif;
  69. /**
  70. * @var string
  71. *
  72. * @ORM\Column(name="impact", type="text", nullable=true)
  73. */
  74. private $impact;
  75. /**
  76. * @var string
  77. *
  78. * @ORM\Column(name="reussite", type="text", nullable=true)
  79. */
  80. private $reussite;
  81. /**
  82. * @var string
  83. *
  84. * @ORM\Column(name="limite", type="text", nullable=true)
  85. */
  86. private $limite;
  87. /**
  88. * @ORM\ManyToOne(targetEntity="Structure", inversedBy="actions")
  89. *
  90. * @ORM\JoinColumn(name="structure_id", referencedColumnName="id", onDelete="CASCADE")
  91. */
  92. private $structure;
  93. /**
  94. * @ORM\ManyToOne(targetEntity="ActionPublic", inversedBy="actions")
  95. *
  96. * @ORM\JoinColumn(name="action_public_id", referencedColumnName="id")
  97. */
  98. private $actionPublic;
  99. /**
  100. * @ORM\ManyToOne(targetEntity="ActionCulturelle", inversedBy="actions")
  101. *
  102. * @ORM\JoinColumn(name="action_culturelle_id", referencedColumnName="id")
  103. */
  104. private $actionCulturelle;
  105. /**
  106. * @ORM\ManyToOne(targetEntity="ActionEconomique", inversedBy="actions")
  107. *
  108. * @ORM\JoinColumn(name="action_economique_id", referencedColumnName="id")
  109. */
  110. private $actionEconomique;
  111. /**
  112. * @ORM\ManyToOne(targetEntity="ActionFamiliale", inversedBy="actions")
  113. *
  114. * @ORM\JoinColumn(name="action_familiale_id", referencedColumnName="id")
  115. */
  116. private $actionFamiliale;
  117. /**
  118. * @ORM\ManyToOne(targetEntity="ActionPolitique", inversedBy="actions")
  119. *
  120. * @ORM\JoinColumn(name="action_politique_id", referencedColumnName="id")
  121. */
  122. private $actionPolitique;
  123. /**
  124. * @ORM\ManyToMany(targetEntity="ActionTag", cascade={"persist"})
  125. *
  126. * @ORM\JoinTable(name="actions_tag")
  127. */
  128. private $actionTag;
  129. /**
  130. * @ORM\Column(type="string", length=255, nullable=true)
  131. */
  132. protected $path;
  133. /**
  134. * @Gedmo\Timestampable(on="create")
  135. *
  136. * @ORM\Column(name="created", type="datetime")
  137. */
  138. private $created;
  139. /**
  140. * @ORM\Column(name="updated", type="datetime")
  141. *
  142. * @Gedmo\Timestampable(on="update")
  143. */
  144. private $updated;
  145. /**
  146. * Get id.
  147. *
  148. * @return int
  149. */
  150. public function getId()
  151. {
  152. return $this->id;
  153. }
  154. /**
  155. * Set intitule.
  156. *
  157. * @param string $intitule
  158. */
  159. public function setIntitule($intitule): static
  160. {
  161. $this->intitule = $intitule;
  162. return $this;
  163. }
  164. /**
  165. * Get intitule.
  166. *
  167. * @return string
  168. */
  169. public function getIntitule()
  170. {
  171. return $this->intitule;
  172. }
  173. /**
  174. * Set referent.
  175. *
  176. * @param string $referent
  177. */
  178. public function setReferent($referent): static
  179. {
  180. $this->referent = $referent;
  181. return $this;
  182. }
  183. /**
  184. * Get referent.
  185. *
  186. * @return string
  187. */
  188. public function getReferent()
  189. {
  190. return $this->referent;
  191. }
  192. /**
  193. * Set document.
  194. */
  195. public function setDocument(?File $file = null): void
  196. {
  197. $this->document = $file;
  198. }
  199. /**
  200. * Get document.
  201. *
  202. * @return string
  203. */
  204. public function getDocument()
  205. {
  206. return $this->document;
  207. }
  208. /**
  209. * Set descriptif.
  210. *
  211. * @param string $descriptif
  212. */
  213. public function setDescriptif($descriptif): static
  214. {
  215. $this->descriptif = $descriptif;
  216. return $this;
  217. }
  218. /**
  219. * Get descriptif.
  220. *
  221. * @return string
  222. */
  223. public function getDescriptif()
  224. {
  225. return $this->descriptif;
  226. }
  227. /**
  228. * Set origine.
  229. *
  230. * @param string $origine
  231. */
  232. public function setOrigine($origine): static
  233. {
  234. $this->origine = $origine;
  235. return $this;
  236. }
  237. /**
  238. * Get origine.
  239. *
  240. * @return string
  241. */
  242. public function getOrigine()
  243. {
  244. return $this->origine;
  245. }
  246. /**
  247. * Set objectif.
  248. *
  249. * @param string $objectif
  250. */
  251. public function setObjectif($objectif): static
  252. {
  253. $this->objectif = $objectif;
  254. return $this;
  255. }
  256. /**
  257. * Get objectif.
  258. *
  259. * @return string
  260. */
  261. public function getObjectif()
  262. {
  263. return $this->objectif;
  264. }
  265. /**
  266. * Set impact.
  267. *
  268. * @param string $impact
  269. */
  270. public function setImpact($impact): static
  271. {
  272. $this->impact = $impact;
  273. return $this;
  274. }
  275. /**
  276. * Get impact.
  277. *
  278. * @return string
  279. */
  280. public function getImpact()
  281. {
  282. return $this->impact;
  283. }
  284. /**
  285. * Set reussite.
  286. *
  287. * @param string $reussite
  288. */
  289. public function setReussite($reussite): static
  290. {
  291. $this->reussite = $reussite;
  292. return $this;
  293. }
  294. /**
  295. * Get reussite.
  296. *
  297. * @return string
  298. */
  299. public function getReussite()
  300. {
  301. return $this->reussite;
  302. }
  303. /**
  304. * Set limite.
  305. *
  306. * @param string $limite
  307. */
  308. public function setLimite($limite): static
  309. {
  310. $this->limite = $limite;
  311. return $this;
  312. }
  313. /**
  314. * Get limite.
  315. *
  316. * @return string
  317. */
  318. public function getLimite()
  319. {
  320. return $this->limite;
  321. }
  322. /**
  323. * Constructor.
  324. */
  325. public function __construct()
  326. {
  327. $this->actionPublic = new \Doctrine\Common\Collections\ArrayCollection();
  328. $this->actionTag = new \Doctrine\Common\Collections\ArrayCollection();
  329. }
  330. /**
  331. * Add actionPublic.
  332. */
  333. public function addActionPublic(ActionPublic $actionPublic): static
  334. {
  335. $this->actionPublic[] = $actionPublic;
  336. return $this;
  337. }
  338. /**
  339. * Remove actionPublic.
  340. */
  341. public function removeActionPublic(ActionPublic $actionPublic): void
  342. {
  343. $this->actionPublic->removeElement($actionPublic);
  344. }
  345. /**
  346. * Get actionPublic.
  347. *
  348. * @return \Doctrine\Common\Collections\Collection
  349. */
  350. public function getActionPublic()
  351. {
  352. return $this->actionPublic;
  353. }
  354. /**
  355. * Set actionCulturelle.
  356. */
  357. public function setActionCulturelle(?ActionCulturelle $actionCulturelle = null): static
  358. {
  359. $this->actionCulturelle = $actionCulturelle;
  360. return $this;
  361. }
  362. /**
  363. * Get actionCulturelle.
  364. *
  365. * @return ActionCulturelle
  366. */
  367. public function getActionCulturelle()
  368. {
  369. return $this->actionCulturelle;
  370. }
  371. /**
  372. * Set actionEconomique.
  373. */
  374. public function setActionEconomique(?ActionEconomique $actionEconomique = null): static
  375. {
  376. $this->actionEconomique = $actionEconomique;
  377. return $this;
  378. }
  379. /**
  380. * Get actionEconomique.
  381. *
  382. * @return ActionEconomique
  383. */
  384. public function getActionEconomique()
  385. {
  386. return $this->actionEconomique;
  387. }
  388. /**
  389. * Set actionFamiliale.
  390. */
  391. public function setActionFamiliale(?ActionFamiliale $actionFamiliale = null): static
  392. {
  393. $this->actionFamiliale = $actionFamiliale;
  394. return $this;
  395. }
  396. /**
  397. * Get actionFamiliale.
  398. *
  399. * @return ActionFamiliale
  400. */
  401. public function getActionFamiliale()
  402. {
  403. return $this->actionFamiliale;
  404. }
  405. /**
  406. * Set actionPolitique.
  407. */
  408. public function setActionPolitique(?ActionPolitique $actionPolitique = null): static
  409. {
  410. $this->actionPolitique = $actionPolitique;
  411. return $this;
  412. }
  413. /**
  414. * Get actionPolitique.
  415. *
  416. * @return ActionPolitique
  417. */
  418. public function getActionPolitique()
  419. {
  420. return $this->actionPolitique;
  421. }
  422. /**
  423. * Add actionTag.
  424. */
  425. public function addActionTag(ActionTag $actionTag): static
  426. {
  427. $this->actionTag[] = $actionTag;
  428. return $this;
  429. }
  430. /**
  431. * Remove actionTag.
  432. */
  433. public function removeActionTag(ActionTag $actionTag): void
  434. {
  435. $this->actionTag->removeElement($actionTag);
  436. }
  437. /**
  438. * Get actionTag.
  439. *
  440. * @return \Doctrine\Common\Collections\Collection
  441. */
  442. public function getActionTag()
  443. {
  444. return $this->actionTag;
  445. }
  446. /**
  447. * Get path.
  448. *
  449. * @return string
  450. */
  451. public function getPath()
  452. {
  453. return $this->path;
  454. }
  455. /**
  456. * Set structure.
  457. */
  458. public function setStructure(?Structure $structure = null): static
  459. {
  460. $this->structure = $structure;
  461. return $this;
  462. }
  463. /**
  464. * Get structure.
  465. *
  466. * @return Structure
  467. */
  468. public function getStructure()
  469. {
  470. return $this->structure;
  471. }
  472. public function getAbsolutePath()
  473. {
  474. return null === $this->path ? null : $this->getUploadRootDir().'/'.$this->path;
  475. }
  476. public function getWebPath()
  477. {
  478. return (null === $this->path && file_exists($this->getAbsolutePath())) ? null : $this->getUploadDir().'/'.$this->path;
  479. }
  480. protected function getUploadRootDir(): string
  481. {
  482. // the absolute directory path where uploaded documents should be saved
  483. // return $basepath.$this->getUploadDir();
  484. return __DIR__.'/../../public/'.$this->getUploadDir();
  485. }
  486. protected function getUploadDir(): string
  487. {
  488. // get rid of the __DIR__ so it doesn't screw when displaying uploaded doc/image in the view.
  489. return 'uploads/actions/documents';
  490. }
  491. public function upload($basepath): void
  492. {
  493. // the file property can be empty if the field is not required
  494. if (null === $this->document) {
  495. return;
  496. }
  497. if (null === $basepath) {
  498. return;
  499. }
  500. // we use the original file name here but you should
  501. // sanitize it at least to avoid any security issues
  502. // move takes the target directory and then the target filename to move to
  503. $this->document->move($this->getUploadRootDir(), $this->document->getClientOriginalName());
  504. // set the path property to the filename where you'ved saved the file
  505. $this->path = $this->document->getClientOriginalName();
  506. // clean up the file property as you won't need it anymore
  507. $this->document = null;
  508. }
  509. public function getDocumentSize(): ?string
  510. {
  511. if (file_exists($this->getAbsolutePath())) {
  512. $bytes = filesize($this->getAbsolutePath());
  513. $human_filesize = $this->human_filesize($bytes);
  514. } else {
  515. $human_filesize = null;
  516. }
  517. return $human_filesize;
  518. }
  519. private function human_filesize(int|bool $bytes, $decimals = 2): string
  520. {
  521. $sz = 'BKMGTP';
  522. $factor = floor((strlen(strval($bytes)) - 1) / 3);
  523. return sprintf(sprintf('%%.%sf', $decimals), $bytes / 1024 ** $factor).@$sz[$factor];
  524. }
  525. public function getCreated()
  526. {
  527. return $this->created;
  528. }
  529. public function getUpdated()
  530. {
  531. return $this->updated;
  532. }
  533. /**
  534. * Set path.
  535. *
  536. * @param string $path
  537. */
  538. public function setPath($path): static
  539. {
  540. $this->path = $path;
  541. return $this;
  542. }
  543. /**
  544. * Set created.
  545. *
  546. * @param \DateTime $created
  547. */
  548. public function setCreated($created): static
  549. {
  550. $this->created = $created;
  551. return $this;
  552. }
  553. /**
  554. * Set updated.
  555. *
  556. * @param \DateTime $updated
  557. */
  558. public function setUpdated($updated): static
  559. {
  560. $this->updated = $updated;
  561. return $this;
  562. }
  563. /**
  564. * Set actionPublic.
  565. */
  566. public function setActionPublic(?ActionPublic $actionPublic = null): static
  567. {
  568. $this->actionPublic = $actionPublic;
  569. return $this;
  570. }
  571. /**
  572. * Set email.
  573. *
  574. * @param string $email
  575. */
  576. public function setEmail($email): static
  577. {
  578. $this->email = $email;
  579. return $this;
  580. }
  581. /**
  582. * Get email.
  583. *
  584. * @return string
  585. */
  586. public function getEmail()
  587. {
  588. return $this->email;
  589. }
  590. }