list_user_roles non bloquant
authordj3c1t <dj3c1t@free.fr>
Mon, 23 Dec 2013 22:01:48 +0000 (23:01 +0100)
committerdj3c1t <dj3c1t@free.fr>
Mon, 23 Dec 2013 22:01:48 +0000 (23:01 +0100)
mw/app/data/models/users.php
mw/app/data/modules/xml/mw_data_xml_users.php

index 7a310db..e9eb8ad 100644 (file)
@@ -86,7 +86,9 @@
       $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;
     }
index 67b6fe4..96dc87d 100644 (file)
     }
 
     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){