From 469648cdaae760d0cce8f6cb9b4e469462ca87c7 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 12 Jul 2016 10:40:51 +0200 Subject: [PATCH] =?UTF-8?q?Enrichissement=20\manager\View=20+=20vue=20list?= =?UTF-8?q?e=20utilisateurs=20termin=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manager/View.php | 36 +++++++++++-------- manager/view/users.php | 79 ++++++++++++++++-------------------------- 2 files changed, 51 insertions(+), 64 deletions(-) diff --git a/manager/View.php b/manager/View.php index 722da75..f90466a 100644 --- a/manager/View.php +++ b/manager/View.php @@ -124,21 +124,15 @@ /* APPLIQUE UN REMPLACEMENT SIMPLE * * @template Contenu HTML du templace - * @content Variables à insérer + * @singles Variables à insérer * * @return result Retourne le templace rempli * */ - public static function replace($template, $content){ + public static function replaceSingle($template, $singles){ - /* [1] On trie le tableau du plus long au plus court - =========================================================*/ - // usort($content, ['\manager\View', 'length_sort']); - // $content = array_reverse($content); - - /* [2] On applique chaque remplacement - =========================================================*/ - foreach($content as $k=>$v){ + /* On applique chaque remplacement */ + foreach($singles as $k=>$v){ /* Tant qu'il y a, on remplace */ if( strpos($template, '@'.$k) !== false ) @@ -151,13 +145,25 @@ - private static function length_sort($A, $B){ - $lenA = strlen($A); - $lenB = strlen($B); - if( $lenA == $lenB ) return strcmp($A, $B); + /* APPLIQUE UN REMPLACEMENT MULTIPLE + * + * @template Contenu HTML du templace + * @multiples Tableau de Singles + * @singles Variables statiques supplémentaires + * + * @return result Retourne le templace rempli + * + */ + public static function replaceMultiple($template, $multiples, $singles=[]){ - return ($lenA < $lenB) ? -1 : 1; + $view = ''; + + /* On applique chaque remplacement */ + foreach($multiples as $multiple) + $view .= self::replaceSingle($template, array_merge($multiple, $singles)); + + return $view; } diff --git a/manager/view/users.php b/manager/view/users.php index 65757e9..df510f9 100644 --- a/manager/view/users.php +++ b/manager/view/users.php @@ -13,38 +13,38 @@ switch($type){ case 'cluster': return " - @cluster_name - + @name + "; break; case 'user': return " -
+
- @user_firstname @user_lastname #@user_username - @icon_remove + @firstname @lastname #@username + @icon_remove - @icon_edit + @icon_edit @icon_card - @user_code + @code @icon_mail - - @user_mail + + @mail @icon_group @grouplist - + + +
"; @@ -71,18 +71,10 @@ if( $answer->error != ManagerError::Success ) return "Une erreur est survenue, veuilez contacter le webmaster si cette erreur persiste."; + $USERLIST = $answer->get('users'); - $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 */ + foreach($USERLIST as $u=>$user){ $clustersReq = new ModuleRequest('userDefault/getClusters', [ 'id_user' => $user['id_user'] ]); $clustersRes = $clustersReq->dispatch(); @@ -90,40 +82,29 @@ 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; + $USERLIST[$u]['grouplist'] = View::replaceMultiple( + self::templateUserlist('cluster'), + $clusters, + [ 'id_user' => $user['id_user'] ] + ); } + $view_user = View::replaceMultiple( + self::templateUserlist('user'), + $USERLIST, [ + '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' ), + ]); - return View::replace(self::templateUserlist(), [ 'userlist' => $view_user ]); + + + + return View::replaceSingle(self::templateUserlist(), [ 'userlist' => $view_user ]); }