Advertisement
Guest User

user

a guest
Sep 18th, 2018
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. <?php
  2.  
  3. class User {
  4.  
  5. public $id;
  6. public $username;
  7. public $password;
  8. public $first_name;
  9. public $last_name;
  10. public $submit;
  11.  
  12.  
  13. public static function find_all_users()
  14. {
  15. return self :: find_this_query("SELECT * FROM users");
  16. }
  17.  
  18.  
  19. public static function find_user_by_id($user_id)
  20. {
  21. global $database;
  22.  
  23. $the_result_array = self :: find_this_query("SELECT * FROM users WHERE id =$user_id LIMIT 1");
  24. if (!empty($the_result_array)) { //el face altceva aici
  25. $first_item = array_shift($the_result_array);
  26. return $first_item;
  27. } else {
  28. return false;
  29. } //pana aici
  30. }
  31.  
  32.  
  33. public static function find_this_query($sql)
  34. {
  35. global $database;
  36.  
  37. $result_set = $database->query($sql);
  38. $the_object_array = array();
  39. while ($row = mysqli_fetch_array($result_set)) {
  40. $the_object_array[] = self :: instantiation($row);
  41. }
  42. return $the_object_array;
  43. }
  44.  
  45.  
  46. public static function verify_user($username, $password)
  47. {
  48. global $database;
  49.  
  50. $username = $database->escape_string($username);
  51. $password = $database->escape_string($password);
  52. $sql = "SELECT * FROM users WHERE ";
  53. $sql .= "username = '{$username}' ";
  54. $sql .= "AND password = '{$password}' ";
  55. $sql .= "LIMIT 1";
  56.  
  57. $the_result_array = self :: find_this_query($sql);
  58. if (!empty($the_result_array)) { //el face altceva aici
  59. $first_item = array_shift($the_result_array); //luam primul item
  60. return $first_item;
  61. } else {
  62. return false;
  63. } //pana aici
  64.  
  65. }
  66.  
  67.  
  68. public static function instantiation($the_record)
  69. { //$found_user este pe pagina cu admin_content, e vorba de o variabila care lucreaza cu functia find_user_by_id
  70. $the_object = new self;
  71. foreach ($the_record as $the_attribute => $value){
  72. if ($the_object->has_the_attribute($the_attribute)) {
  73. $the_object->$the_attribute = $value;
  74. }
  75. }
  76. return $the_object;
  77.  
  78.  
  79. /* $the_object->id = $found_user['id'];
  80. $the_object->username = $found_user['username'];
  81. $the_object->password = $found_user['password'];
  82. $the_object->first_name = $found_user['first_name'];
  83. $the_object->last_name = $found_user['last_name'];
  84. return $the_object; asta era fostul the_record */
  85. }
  86.  
  87.  
  88. private function has_the_attribute($the_attribute)
  89. {
  90. $object_properties = get_object_vars($this); //functie predefinita care verifica ce att are clasa
  91. return array_key_exists($the_attribute, $object_properties); //functie predefinita care verifica daca exista key
  92. }
  93.  
  94.  
  95.  
  96.  
  97. }
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement