data.class.php 4.2KB

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