$data = $this->env->data();
if(parent::load($index_name, $index_value) === false) return false;
if($this->get_id()){
- if(($this->roles = $data->list_user_roles($this->get_id())) === false) return false;
+ if(($this->roles = $data->list_user_roles($this->get_id())) === false){
+ $this->roles = array();
+ }
}
return true;
}
}
function user_by_id($id){
- if(!isset($this->users)) $this->users = array();
- if(isset($this->users[$id])) return $this->users[$id];
- $sgbd = $this->sgbd();
- if(($user = $sgbd->get_data("users", $id)) !== false){
- $this->users[$id] = $user;
- if(($roles = $this->list_user_roles($user["id"])) !== false) $user["roles"] = $roles;
- else $user = false;
- }
- return $user;
+ $env = $this->env();
+ $user = $env->get_model("users");
+ if($user->load("id", $id) === false) return false;
+ return $user->get_values();
}
function user($login){
- $sgbd = $this->sgbd();
- $user = array();
- if($rst = $sgbd->open_data("users")){
- while($v_rst = $sgbd->fetch_data($rst)){
- if(isset($v_rst)){
- if(isset($v_rst["login"]) && $v_rst["login"] == $login){
- $user = $v_rst;
- break;
- }
- }
- else $user = false;
- }
- $sgbd->close_data($rst);
- if($user){
- if(($roles = $this->list_user_roles($user["id"])) !== false) $user["roles"] = $roles;
- else $user = false;
- }
- }
- else $user = false;
- if($user !== false){
- if(!isset($this->users)) $this->users = array();
- if($user) $this->users[$user["id"]] = $user;
- }
- return $user;
+ $env = $this->env();
+ $user = $env->get_model("users");
+ if($user->load("login", $login) === false) return false;
+ return $user->get_values();
}
function user_exists($login){