daily pastebin goal
73%
SHARE
TWEET

Untitled

a guest Aug 14th, 2016 433 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. class User{
  3.    
  4.     public $id;
  5.     public $username;
  6.     public $password;
  7.     public $first_name;
  8.     public $last_name;
  9.    
  10.     public static function find_all_users(){
  11.         //stavili smo iz database.php varijablu $database
  12. //       global $database;
  13. //       $result_set = $database->query("SELECT * FROM users");
  14. //       return $result_set;
  15.         //novi red zamjenjuje prethodna tri reda u suradji s find_this_query metodom i stvara
  16.         return self::find_this_query("SELECT * FROM users");
  17.     }
  18.    
  19.     public static function find_user_by_id($user_id){
  20.         //stavili smo iz database.php varijablu $database
  21.        global $database;
  22.         //donji je zamjenjen ovim ispod njega
  23.        //$result_set = $database->query("SELECT * FROM users WHERE id = $user_id LIMIT 1");
  24.         $the_result_array = self::find_this_query("SELECT * FROM users WHERE id = $user_id LIMIT 1");
  25. //       if(!empty($the_result_array)){
  26. //          
  27. //           $first_item=array_shift($the_result_array);
  28. //           return $first_item;
  29. //       }else{
  30. //           return false;
  31. //       }
  32.  
  33. //        ovo mijenja if set gore
  34.         return !empty($the_result_array) ? array_shift($the_result_array) : false ;
  35.   //       return $found_user;  
  36.     }
  37.    
  38.     //ova funkcija omogućava
  39.     public static function find_this_query($sql){
  40.        
  41.        global $database;
  42.        $result_set = $database->query($sql);
  43.        $the_object_array = array();
  44.         while($row=mysqli_fetch_array($result_set)){
  45.            
  46.             $the_object_array[]=self::instantation($row);
  47.                                      
  48.         }
  49.        return $the_object_array;
  50.     }
  51.    
  52.    
  53.    
  54.     public static function verify_user($username, $password){
  55.         global $database;
  56.        
  57.         $username = $database->escape_string($username);
  58.         $password = $database->escape_string($password);  
  59.        
  60.         $sql = "SELECT * FROM users WHERE ";
  61.         $sql .="username = '{$username}' ";
  62.         $sql .="AND password = '{$password}' ";
  63.         $sql .="LIMIT 1";
  64.        
  65.         $the_result_array = self::find_this_query($sql);
  66.         return !empty($the_result_array) ? array_shift($the_result_array) : false ;
  67.     }
  68.    
  69.     public static function instantation($the_record){
  70.        
  71.          $the_object = new self;
  72.    
  73. //         $the_object->id         = $found_user['id'];
  74. //         $the_object->username   = $found_user['username'];
  75. //         $the_object->password   = $found_user['password'];
  76. //         $the_object->first_name = $found_user['first_name'];
  77. //         $the_object->last_name  = $found_user['last_name'];
  78. //        
  79.         foreach($the_record as $the_attribute=> $value){
  80.            
  81.             if($the_object->has_the_attribute($the_attribute)){
  82.                 $the_object->$the_attribute = $value;
  83.             }
  84.            
  85.         }
  86.        
  87.          return $the_object;
  88.     }
  89.    
  90.     private function has_the_attribute($the_attribute){
  91.        
  92.         $object_properties = get_object_vars($this);
  93.         return array_key_exists($the_attribute, $object_properties);
  94.        
  95.     }
  96. }
  97.  
  98. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top