src/Entity/Adminmailing.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. * Adminmailing
  8. *
  9. * @ORM\Table(name="adminmailing", options={"collate"="latin1_general_ci","charset"="latin1"})
  10. * @ORM\Entity(repositoryClass="App\Repository\AdminmailingRepository")
  11. */
  12. class Adminmailing {
  13. /**
  14. * @var integer
  15. *
  16. * @ORM\Column(name="id", type="integer", nullable=false)
  17. * @ORM\Id
  18. * @ORM\GeneratedValue(strategy="IDENTITY")
  19. */
  20. private $id;
  21. /**
  22. * @var \DateTime
  23. *
  24. * @ORM\Column(name="datefr", type="datetime", nullable=false)
  25. */
  26. private $datefr;
  27. /**
  28. * @var string
  29. *
  30. * @ORM\Column(name="titre", type="string", length=250, nullable=false)
  31. */
  32. private $titre;
  33. /**
  34. * @var string
  35. *
  36. * @ORM\Column(name="type", type="string", length=50, nullable=false)
  37. */
  38. private $type;
  39. /**
  40. * @var string
  41. *
  42. * @ORM\Column(name="destinataires", type="text", nullable=false)
  43. */
  44. private $destinataires;
  45. /**
  46. * @var UploadedFile
  47. *
  48. * @ORM\Column(name="document", type="string", length=250, nullable=true)
  49. * @Assert\File(maxSize="6000000")
  50. */
  51. private $document;
  52. /**
  53. * @var string
  54. *
  55. * @ORM\Column(name="description", type="text", nullable=false)
  56. */
  57. private $description;
  58. /**
  59. * @var boolean
  60. *
  61. * @ORM\Column(name="etat", type="boolean", nullable=false)
  62. */
  63. private $etat;
  64. public function __construct() {
  65. $this->datefr = new \DateTime("now");
  66. $this->type = 'fax';
  67. $this->etat = false;
  68. }
  69. /**
  70. * Get id
  71. *
  72. * @return integer
  73. */
  74. public function getId() {
  75. return $this->id;
  76. }
  77. /**
  78. * Set datefr
  79. *
  80. * @param \DateTime $datefr
  81. * @return Adminmailing
  82. */
  83. public function setDatefr($datefr) {
  84. $this->datefr = $datefr;
  85. return $this;
  86. }
  87. /**
  88. * Get datefr
  89. *
  90. * @return \DateTime
  91. */
  92. public function getDatefr() {
  93. return $this->datefr;
  94. }
  95. /**
  96. * Set titre
  97. *
  98. * @param string $titre
  99. * @return Adminmailing
  100. */
  101. public function setTitre($titre) {
  102. $this->titre = $titre;
  103. return $this;
  104. }
  105. /**
  106. * Get titre
  107. *
  108. * @return string
  109. */
  110. public function getTitre() {
  111. return $this->titre;
  112. }
  113. /**
  114. * Set type
  115. *
  116. * @param string $type
  117. * @return Adminmailing
  118. */
  119. public function setType($type) {
  120. $this->type = $type;
  121. return $this;
  122. }
  123. /**
  124. * Get type
  125. *
  126. * @return string
  127. */
  128. public function getType() {
  129. return $this->type;
  130. }
  131. /**
  132. * Set destinataires
  133. *
  134. * @param string $destinataires
  135. * @return Adminmailing
  136. */
  137. public function setDestinataires($destinataires) {
  138. $this->destinataires = $destinataires;
  139. return $this;
  140. }
  141. /**
  142. * Get destinataires
  143. *
  144. * @return string
  145. */
  146. public function getDestinataires() {
  147. return $this->destinataires;
  148. }
  149. /**
  150. * Set document
  151. *
  152. * @param string $document
  153. * @return Adminmailing
  154. */
  155. public function setDocument($document) {
  156. $this->document = $document;
  157. return $this;
  158. }
  159. /**
  160. * Get document
  161. *
  162. * @return string
  163. */
  164. public function getDocument() {
  165. return $this->document;
  166. }
  167. /**
  168. * Set description
  169. *
  170. * @param string $description
  171. * @return Adminmailing
  172. */
  173. public function setDescription($description) {
  174. $this->description = $description;
  175. return $this;
  176. }
  177. /**
  178. * Get description
  179. *
  180. * @return string
  181. */
  182. public function getDescription() {
  183. return $this->description;
  184. }
  185. /**
  186. * Set etat
  187. *
  188. * @param boolean $etat
  189. * @return Adminmailing
  190. */
  191. public function setEtat($etat) {
  192. $this->etat = $etat;
  193. return $this;
  194. }
  195. /**
  196. * Get etat
  197. *
  198. * @return boolean
  199. */
  200. public function getEtat() {
  201. return $this->etat;
  202. }
  203. /**
  204. * Get nbDestinataires
  205. *
  206. * @return integer
  207. */
  208. public function getNbDestinataires() {
  209. return count(explode('|', $this->destinataires));
  210. }
  211. protected function getUploadRootDir() {
  212. return __DIR__ . '/../../../../public/documents';
  213. }
  214. protected function getUploadDir() {
  215. // on se débarrasse de « __DIR__ » afin de ne pas avoir de problème lorsqu'on affiche
  216. // le document/image dans la vue.
  217. return 'documents/fax';
  218. }
  219. /**
  220. * @return UploadedFile
  221. */
  222. public function upload() {
  223. // utilisez le nom de fichier original ici mais
  224. // vous devriez « l'assainir » pour au moins éviter
  225. // quelconques problèmes de sécurité
  226. // la méthode « move » prend comme arguments le répertoire cible et
  227. // le nom de fichier cible où le fichier doit être déplacé
  228. $name = str_replace(" ", "_", $this->document->getClientOriginalName());
  229. $this->document->move($this->getUploadRootDir(), $name);
  230. // définit la propriété « path » comme étant le nom de fichier où vous
  231. // avez stocké le fichier
  232. $this->document = $name;
  233. }
  234. }