src/Entity/FournisseurClientdocument.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\HttpFoundation\File\UploadedFile;
  5. use Symfony\Component\Validator\Constraints as Assert;
  6. /**
  7. * FournisseurClientdocument
  8. *
  9. * @ORM\Table(name="founisseurclientdocument", options={"collate"="latin1_general_ci","charset"="latin1"})
  10. * @ORM\Entity(repositoryClass="App\Repository\FournisseurClientdocumentRepository")
  11. */
  12. class FournisseurClientdocument
  13. {
  14. /**
  15. * @var integer
  16. *
  17. * @ORM\Column(name="id", type="integer", nullable=false)
  18. * @ORM\Id
  19. * @ORM\GeneratedValue(strategy="IDENTITY")
  20. */
  21. private $id;
  22. /**
  23. * @ORM\ManyToOne(targetEntity="App\Entity\Clientrelation",inversedBy="documents", cascade={"persist"})
  24. * @ORM\JoinColumn(nullable=false)
  25. */
  26. private $idrelation;
  27. /**
  28. * @var integer
  29. *
  30. * @ORM\Column(name="date", type="integer", nullable=false)
  31. */
  32. private $date;
  33. /**
  34. * @var \DateTime
  35. *
  36. * @ORM\Column(name="datefr", type="datetime", nullable=false)
  37. */
  38. private $datefr;
  39. /**
  40. * @var string
  41. *
  42. * @ORM\Column(name="nom", type="string", length=150, nullable=false)
  43. */
  44. private $nom;
  45. /**
  46. * @var string
  47. *
  48. * @ORM\Column(name="fichier", type="string", length=150, nullable=false)
  49. * @Assert\File(maxSize="6000000")
  50. */
  51. private $fichier;
  52. /**
  53. * @var boolean
  54. *
  55. * @ORM\Column(name="clientall", type="boolean", nullable=false)
  56. */
  57. private $clientall;
  58. /**
  59. * @var boolean
  60. *
  61. * @ORM\Column(name="etat", type="boolean", nullable=false)
  62. */
  63. private $etat;
  64. public function __construct()
  65. {
  66. $this->etat = true;
  67. $this->clientall = false;
  68. $this->date = time();
  69. $this->datefr = new \DateTime('now');
  70. }
  71. /**
  72. * Get id
  73. *
  74. * @return integer
  75. */
  76. public function getId()
  77. {
  78. return $this->id;
  79. }
  80. /**
  81. * Set date
  82. *
  83. * @param integer $date
  84. * @return FournisseurClientdocument
  85. */
  86. public function setDate($date)
  87. {
  88. $this->date = $date;
  89. return $this;
  90. }
  91. /**
  92. * Get date
  93. *
  94. * @return integer
  95. */
  96. public function getDate()
  97. {
  98. return $this->date;
  99. }
  100. /**
  101. * Set datefr
  102. *
  103. * @param \DateTime $datefr
  104. * @return FournisseurClientdocument
  105. */
  106. public function setDatefr($datefr)
  107. {
  108. $this->datefr = $datefr;
  109. return $this;
  110. }
  111. /**
  112. * Get datefr
  113. *
  114. * @return \DateTime
  115. */
  116. public function getDatefr()
  117. {
  118. return $this->datefr;
  119. }
  120. /**
  121. * @param string $nom
  122. * @return $this
  123. */
  124. public function setNom($nom)
  125. {
  126. $this->nom = $nom;
  127. return $this;
  128. }
  129. /**
  130. * Get nom
  131. *
  132. * @return string
  133. */
  134. public function getNom()
  135. {
  136. return $this->nom;
  137. }
  138. /**
  139. * @param mixed $fichier
  140. */
  141. public function setFichier($fichier)
  142. {
  143. if ($fichier instanceof UploadedFile) {
  144. $this->fichier = $fichier;
  145. } else {
  146. throw new \InvalidArgumentException('Expected instance of UploadedFile');
  147. }
  148. return $this;
  149. }
  150. /**
  151. * Get fichier
  152. *
  153. * @return string
  154. */
  155. public function getFichier()
  156. {
  157. return $this->fichier;
  158. }
  159. /**
  160. * @param mixed $clientall
  161. * @return $this
  162. */
  163. public function setClientall($clientall)
  164. {
  165. $this->clientall = $clientall;
  166. return $this;
  167. }
  168. /**
  169. * Get clientall
  170. *
  171. * @return boolean
  172. */
  173. public function getClientall()
  174. {
  175. return $this->clientall;
  176. }
  177. /**
  178. * Set etat
  179. *
  180. * @param boolean $etat
  181. * @return FournisseurClientdocument
  182. */
  183. public function setEtat($etat)
  184. {
  185. $this->etat = $etat;
  186. return $this;
  187. }
  188. /**
  189. * Get etat
  190. *
  191. * @return boolean
  192. */
  193. public function getEtat()
  194. {
  195. return $this->etat;
  196. }
  197. protected function getUploadRootDir()
  198. {
  199. // le chemin absolu du répertoire où les documents uploadés doivent être sauvegardés
  200. return realpath(__DIR__ . '/../../') . '/public/' . $this->getUploadDir();
  201. }
  202. protected function getUploadDir()
  203. {
  204. // on se débarrasse de « __DIR__ » afin de ne pas avoir de problème lorsqu'on affiche
  205. // le document/image dans la vue.
  206. return 'documents';
  207. }
  208. /**
  209. * @var UploadedFile|string
  210. */
  211. public function upload($id_client)
  212. {
  213. if ($this->fichier instanceof UploadedFile) {
  214. $name = "C" . $id_client . "-" . str_replace(" ", "_", $this->fichier->getClientOriginalName());
  215. $this->fichier->move($this->getUploadRootDir(), $name);
  216. // Define the new file path
  217. $this->fichier = $name;
  218. } else {
  219. // Handle the case where $this->fichier is not an UploadedFile instance
  220. throw new \Exception('Fichier must be an instance of UploadedFile');
  221. }
  222. }
  223. /**
  224. * @return mixed
  225. */
  226. public function getIdrelation()
  227. {
  228. return $this->idrelation;
  229. }
  230. /**
  231. * @param mixed $idrelation
  232. */
  233. public function setIdrelation($idrelation): void
  234. {
  235. $this->idrelation = $idrelation;
  236. }
  237. }