<?php
class ResUsers {
    public $id;
    public $name;
    public $email;
    public $password;
    public $address;
    public $role_id;
    public $photo;
    public function __construct($_id, $_name, $_email, $_password, $_address, $_role_id, $_photo) {
        $this->id = $_id;
        $this->name = $_name;
        $this->email = $_email;
        $this->password = $_password;
        $this->address = $_address;
        $this->role_id = $_role_id;
        $this->photo = $_photo;
    }
    public static function readAll() {
        global $db;
        $result = $db->query("select u.*,r.name as role from res_users u, res_roles r where u.role_id = r.id");
        return $result->fetch_all(MYSQLI_ASSOC);
    }
    public static function readById($_id) {
        global $db;
        $result = $db->query("select * from res_users where id = $_id");
        return $result->fetch_assoc();
    }
        public function update()
    {
        global $db;
        $res = $db->query("update res_users set name = '$this->name', email='$this->email', address='$this->address', role_id='$this->role_id' where id=$this->id");
 
        if ($res) {
            return "Data updated Successfully";
        } else {
            return $db->error;
        }
    }
        public static function delete($_id){
        global $db;
        $result = $db->query("delete from res_users where id = $_id");
        if($result) {
            return "Data deleted successfully!";
        }else{
            return $db->error;
        }
    }



}

?>