data.class.php 4.6KB

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