From cb9cd475c6c34423195127ec6bd9d9b2c45f5a86 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 11 Jul 2016 18:14:18 +0200 Subject: [PATCH] Gestion View de la liste des utilisateurs --- manager/view/users.php | 126 +++++++++++++++++++++++++++++++++++++++-- test/automate.php | 2 +- view/users.php | 87 +--------------------------- 3 files changed, 124 insertions(+), 91 deletions(-) diff --git a/manager/view/users.php b/manager/view/users.php index a9c0b4d..e62b9ef 100644 --- a/manager/view/users.php +++ b/manager/view/users.php @@ -2,22 +2,136 @@ namespace manager\view; use \manager\View; - use \manager\sessionManager; + use \manager\ModuleRequest; use \manager\Authentification; use \manager\ManagerError; class users{ - public static function template(){ - return "@var1"; + public static function templateUserlist($type=null){ + + switch($type){ + case 'cluster': return " + + @cluster_name + + "; + break; + + + + case 'user': return " +
+ + @user_firstname @user_lastname #@user_username + @icon_remove + + @icon_edit + + + @icon_card + @user_code + + + + @icon_mail + + + @user_mail + + + + + @icon_group + @grouplist + + + + +
"; + break; + + + default: return " + + @userlist"; + break; + + } + } + + public static function userlist($params){ + $view = ''; + + /* [1] On récupère la liste des utilisateurs + =========================================================*/ + $request = new ModuleRequest('userDefault/getAll'); // On utilise la methode 'getAll' du module 'userDefault' + $answer = $request->dispatch(); // On recupere la reponse + + // si erreur, on affiche l'explicitation + if( $answer->error != ManagerError::Success ) + return "Une erreur est survenue, veuilez contacter le webmaster si cette erreur persiste."; + + + + $view_user = ''; + + foreach($answer->get('users') as $user){ + $view_cluster = ''; + + + + /* [2] On ajoute les données de ses groupes + =========================================================*/ + /* (1) On récupère les groupes de la machine */ + $clustersReq = new ModuleRequest('userDefault/getClusters', [ 'id_user' => $user['id_user'] ]); + $clustersRes = $clustersReq->dispatch(); + + /* (2) Gestion si erreur */ + if( $clustersRes->error == ManagerError::Success ) $clusters = $clustersRes->get('clusters'); + else $clusters = []; + + /* (3) On crée la vue */ + foreach($clusters as $cluster){ + $view_cluster .= View::replace(self::templateUserlist('cluster'),[ + 'cluster_id' => $cluster['id_cluster'], + 'user_id' => $user['id_user'] + ]); + } + + + + /* [3] On ajoute les données utilisateurs + =========================================================*/ + $view_user .= View::replace(self::templateUserlist('user'),[ + 'user_id' => $user['id_user'], + 'user_username' => $user['username'], + 'user_firstname' => $user['firstname'], + 'user_lastname' => $user['lastname'], + 'user_code' => $user['code'], + 'user_mail' => $user['mail'], + 'icon_remove' => file_get_contents( __ROOT__.'/src/static/sub-menu-side/remove.svg' ), + 'icon_edit' => file_get_contents( __ROOT__.'/src/static/sub-menu-side/edit.svg' ), + 'icon_card' => file_get_contents( __ROOT__.'/src/static/container/card.svg' ), + 'icon_mail' => file_get_contents( __ROOT__.'/src/static/container/mail.svg' ), + 'icon_group' => file_get_contents( __ROOT__.'/src/static/container/group.svg' ), + 'grouplist' => $view_cluster + ]); + + $view .= $view_user; + } + + + + + return View::replace(self::templateUserlist(), [ 'userlist' => $view_user ]); } - public static function aaa($params){ - return View::replace(self::template(), $params); - } + + + } diff --git a/test/automate.php b/test/automate.php index d1950d3..8ea00eb 100755 --- a/test/automate.php +++ b/test/automate.php @@ -330,7 +330,7 @@ }//createWarehouse(); debug(); - $myView = new View('users.aaa', ['var1'=>'coucou']); + $myView = new View('users.userlist', []); $myView->view(); diff --git a/view/users.php b/view/users.php index cae2f9e..dd2b011 100755 --- a/view/users.php +++ b/view/users.php @@ -2,6 +2,7 @@ require_once __ROOT__.'/manager/autoloader.php'; use \manager\ModuleRequest; use \manager\ManagerError; + use \manager\View; use \manager\Repo; ?> @@ -50,92 +51,10 @@ /* [1] VIEW -> Liste des utilisateurs =========================================================*/ - $request = new ModuleRequest('userDefault/getAll'); // On utilise la methode 'getAll' du module 'userDefault' - $answer = $request->dispatch(); // On recupere la reponse - echo "
"; - // echo 'Liste des utilisateurs:
'; - // si erreur, on affiche l'explicitation - if( $answer->error != ManagerError::Success ){ - var_dump( ManagerError::explicit($answer->error) ); - - echo "Une erreur est survenue, veuilez contacter le webmaster si cette erreur persiste."; - } - - // Si aucune erreur, on affiche les resultats - else{ - - // Barre de recherche - echo ""; - - // Liste des utilisateurs - foreach( $answer->get('users') as $user){ - - /* (1) On récupère les groupes de la machine */ - $clustersReq = new ModuleRequest('userDefault/getClusters', [ - 'id_user' => $user['id_user'] - ]); - $clustersRes = $clustersReq->dispatch(); - - /* (2) Gestion si erreur */ - if( $clustersRes->error == ManagerError::Success ) $clusters = $clustersRes->get('clusters'); - else $clusters = []; - - echo "
"; - - // Prenom Nom - echo "".$user['firstname']." ".$user['lastname']." #".$user['username'].""; - - - - // Icone vers la suppression - echo ""; - echo file_get_contents( __ROOT__.'/src/static/sub-menu-side/remove.svg' ); - echo ""; - - // Icone vers la modification - echo ""; - echo file_get_contents( __ROOT__.'/src/static/sub-menu-side/edit.svg' ); - echo ""; - - - - // Code RFID - echo ""; - echo file_get_contents( __ROOT__.'/src/static/container/card.svg' ); - - echo ""; - echo $user['code']; - echo ""; - echo""; - - // Adresse email - echo ""; - echo file_get_contents( __ROOT__.'/src/static/container/mail.svg' ); - - echo ""; - echo $user['mail']; - echo ""; - echo""; - - // Groupes de l'utilisateur - echo ""; - echo file_get_contents( __ROOT__.'/src/static/container/group.svg' ); - - if( $clusters != false ) - foreach($clusters as $cluster) - if( $cluster['name'] != $user['username'] ) // Si c'est le groupe personnel, on ne l'affiche pas - echo "".$cluster['name'].""; - - echo "+"; - echo""; - - - echo "
"; - } - - } + $userlist = new View('users.userlist'); + $userlist->view(); echo '
';