data.class.php 4.0KB

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