data.class.php 5.3KB

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