Gestion View de la liste des utilisateurs
This commit is contained in:
parent
221cc7ddcb
commit
cb9cd475c6
|
@ -2,23 +2,137 @@
|
|||
|
||||
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 "<span class='a'>@var1</span>";
|
||||
public static function templateUserlist($type=null){
|
||||
|
||||
switch($type){
|
||||
case 'cluster': return "
|
||||
<span>
|
||||
@cluster_name
|
||||
<span class='rem-group' data-group='@cluster_id' data-user='@user_id'></span>
|
||||
</span>";
|
||||
break;
|
||||
|
||||
|
||||
|
||||
case 'user': return "
|
||||
<article class='inline-box' id='@user_id'>
|
||||
|
||||
<span class='title'>@user_firstname @user_lastname <span>#@user_username</span></span>
|
||||
<span class='link_remove' data-user='@user_id'>@icon_remove</span>
|
||||
|
||||
<span class='link_edit' data-user='@user_id'>@icon_edit</span>
|
||||
|
||||
<span class='code'>
|
||||
@icon_card
|
||||
<span>@user_code</span>
|
||||
</span>
|
||||
|
||||
<span class='mail'>
|
||||
@icon_mail
|
||||
|
||||
<a href='mailto:@user_mail'>
|
||||
<span>@user_mail</span>
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<span class='groups'>
|
||||
@icon_group
|
||||
@grouplist
|
||||
<span class='add-group' data-user='@user_id'>+</span>
|
||||
</span>
|
||||
|
||||
</article>";
|
||||
break;
|
||||
|
||||
|
||||
default: return "
|
||||
<input type='text' class='searchbar' placeholder='Recherche'>
|
||||
@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 "<span class='error'>Une erreur est survenue, veuilez contacter le webmaster si cette erreur persiste.</span>";
|
||||
|
||||
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static function aaa($params){
|
||||
return View::replace(self::template(), $params);
|
||||
return View::replace(self::templateUserlist(), [ 'userlist' => $view_user ]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -330,7 +330,7 @@
|
|||
}//createWarehouse();
|
||||
|
||||
debug();
|
||||
$myView = new View('users.aaa', ['var1'=>'coucou']);
|
||||
$myView = new View('users.userlist', []);
|
||||
$myView->view();
|
||||
|
||||
|
||||
|
|
|
@ -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 "<section data-sublink='view' class='list'>";
|
||||
// echo 'Liste des utilisateurs: <br>';
|
||||
|
||||
// si erreur, on affiche l'explicitation
|
||||
if( $answer->error != ManagerError::Success ){
|
||||
var_dump( ManagerError::explicit($answer->error) );
|
||||
|
||||
echo "<span class='error'>Une erreur est survenue, veuilez contacter le webmaster si cette erreur persiste.</span>";
|
||||
}
|
||||
|
||||
// Si aucune erreur, on affiche les resultats
|
||||
else{
|
||||
|
||||
// Barre de recherche
|
||||
echo "<input type='text' class='searchbar' placeholder='Recherche'>";
|
||||
|
||||
// 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 "<article class='inline-box' id='".$user['id_user']."'>";
|
||||
|
||||
// Prenom Nom
|
||||
echo "<span class='title'>".$user['firstname']." ".$user['lastname']." <span>#".$user['username']."</span></span>";
|
||||
|
||||
|
||||
|
||||
// Icone vers la suppression
|
||||
echo "<span class='link_remove' data-user='".$user['id_user']."'>";
|
||||
echo file_get_contents( __ROOT__.'/src/static/sub-menu-side/remove.svg' );
|
||||
echo "</span>";
|
||||
|
||||
// Icone vers la modification
|
||||
echo "<span class='link_edit' data-user='".$user['id_user']."'>";
|
||||
echo file_get_contents( __ROOT__.'/src/static/sub-menu-side/edit.svg' );
|
||||
echo "</span>";
|
||||
|
||||
|
||||
|
||||
// Code RFID
|
||||
echo "<span class='code'>";
|
||||
echo file_get_contents( __ROOT__.'/src/static/container/card.svg' );
|
||||
|
||||
echo "<span>";
|
||||
echo $user['code'];
|
||||
echo "</span>";
|
||||
echo"</span>";
|
||||
|
||||
// Adresse email
|
||||
echo "<span class='mail'>";
|
||||
echo file_get_contents( __ROOT__.'/src/static/container/mail.svg' );
|
||||
|
||||
echo "<a href='mailto:".$user['mail']."'><span>";
|
||||
echo $user['mail'];
|
||||
echo "</span></a>";
|
||||
echo"</span>";
|
||||
|
||||
// Groupes de l'utilisateur
|
||||
echo "<span class='groups'>";
|
||||
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 "<span>".$cluster['name']."<span class='rem-group' data-group='".$cluster['id_cluster']."' data-user='".$user['id_user']."'></span></span>";
|
||||
|
||||
echo "<span class='add-group' data-user='".$user['id_user']."'>+</span>";
|
||||
echo"</span>";
|
||||
|
||||
|
||||
echo "</article>";
|
||||
}
|
||||
|
||||
}
|
||||
$userlist = new View('users.userlist');
|
||||
$userlist->view();
|
||||
|
||||
echo '</section>';
|
||||
|
||||
|
|
Loading…
Reference in New Issue