data.class.php 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. require_once("connector.class.php");
  3. class Data
  4. {
  5. private $identifiant;
  6. private $nom_fils;
  7. private $prenom_fils;
  8. private $ddn_fils;
  9. private $tel_mobile;
  10. private $courriel;
  11. private $date;
  12. private $ip;
  13. function __construct($email)
  14. {
  15. $bdd = new Connector();
  16. $data = $bdd->Select("*", "data", array(
  17. "where" => array(
  18. array("identifiant", "=", $email)
  19. )
  20. ))[0];
  21. if($data == NULL)
  22. {
  23. throw new Exception("Les données n'existent pas");
  24. }
  25. // Chargement des informations
  26. $this->identifiant = $email;
  27. $this->nom_fils = $data["nom_fils"];
  28. $this->prenom_fils = $data["prenom_fils"];
  29. $this->ddn_fils = $data["ddn_fils"];
  30. $this->tel_mobile = $data["tel_mobile"];
  31. $this->courriel = $data["courriel"];
  32. $this->date = $data["date"];
  33. $this->ip = $data["ip"];
  34. }
  35. /**
  36. * @return string
  37. */
  38. public function getIdentifiant()
  39. {
  40. return $this->identifiant;
  41. }
  42. /**
  43. * @return string
  44. */
  45. public function getNomFils()
  46. {
  47. return $this->nom_fils;
  48. }
  49. /**
  50. * @return string
  51. */
  52. public function getPrenomFils()
  53. {
  54. return $this->prenom_fils;
  55. }
  56. /**
  57. * @return string
  58. */
  59. public function getDdnFils()
  60. {
  61. return $this->ddn_fils;
  62. }
  63. /**
  64. * @return string
  65. */
  66. public function getTelMobile()
  67. {
  68. return $this->tel_mobile;
  69. }
  70. /**
  71. * @return string
  72. */
  73. public function getCourriel()
  74. {
  75. return $this->courriel;
  76. }
  77. /**
  78. * @return string
  79. */
  80. public function getDate()
  81. {
  82. return $this->date;
  83. }
  84. /**
  85. * @return string
  86. */
  87. public function getIp()
  88. {
  89. return $this->ip;
  90. }
  91. /**
  92. * @param string $identifiant
  93. */
  94. public function setIdentifiant($identifiant)
  95. {
  96. $this->identifiant = $identifiant;
  97. }
  98. /**
  99. * @param string $nom_fils
  100. */
  101. public function setNomFils($nom_fils)
  102. {
  103. $this->nom_fils = $nom_fils;
  104. }
  105. /**
  106. * @param string $prenom_fils
  107. */
  108. public function setPrenomFils($prenom_fils)
  109. {
  110. $this->prenom_fils = $prenom_fils;
  111. }
  112. /**
  113. * @param string $ddn_fils
  114. */
  115. public function setDdnFils($ddn_fils)
  116. {
  117. $this->ddn_fils = $ddn_fils;
  118. }
  119. /**
  120. * @param string $tel_mobile
  121. */
  122. public function setTelMobile($tel_mobile)
  123. {
  124. $this->tel_mobile = $tel_mobile;
  125. }
  126. /**
  127. * @param string $courriel
  128. */
  129. public function setCourriel($courriel)
  130. {
  131. $this->courriel = $courriel;
  132. }
  133. /**
  134. * @param string $date
  135. */
  136. public function setDate($date)
  137. {
  138. $this->date = $date;
  139. }
  140. /**
  141. * @param string $ip
  142. */
  143. public function setIp($ip)
  144. {
  145. $this->ip = $ip;
  146. }
  147. function write()
  148. {
  149. $bdd = new Connector();
  150. $data = $bdd->Select("*", "data", array(
  151. "where" => array(
  152. array("identifiant", "=", $this->identifiant)
  153. )
  154. ))[0];
  155. $attrs = get_object_vars($this);
  156. $toUpdate = array();
  157. foreach ($attrs as $key => $value) {
  158. if ($value != $data[$key]) {
  159. $toUpdate[$key] = $value;
  160. }
  161. }
  162. $bdd->Update("data", array(
  163. "set" => $toUpdate,
  164. "where" => array(array("identifiant", "=", $this->identifiant))
  165. ));
  166. }
  167. public static function extract()
  168. {
  169. $bdd = new Connector();
  170. $data = $bdd->Select("*", "data");
  171. $csv = "";
  172. // Head line
  173. $keys = array();
  174. foreach ($data[0] as $key => $value) {
  175. array_push($keys, $key);
  176. }
  177. $csv .= implode(",", $keys) . "\n";
  178. // Content
  179. foreach ($data as $student) {
  180. $csv .= implode(",", $student);
  181. $csv .= "\n";
  182. }
  183. return $csv;
  184. }
  185. public static function getAll()
  186. {
  187. $bdd = new Connector();
  188. return $bdd->Select("*", "data");
  189. }
  190. function erase()
  191. {
  192. $bdd = new Connector();
  193. $bdd->Delete("data", array(array("identifiant", "=", $this->identifiant)));
  194. }
  195. }