SMMP/manager/view/users.php

140 lines
3.7 KiB
PHP
Raw Normal View History

2016-07-11 15:44:18 +00:00
<?php
namespace manager\view;
use \manager\View;
use \manager\ModuleRequest;
2016-07-11 15:44:18 +00:00
use \manager\Authentification;
use \manager\ManagerError;
class users{
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;
}
2016-07-11 15:44:18 +00:00
}
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 = '';
2016-07-11 15:44:18 +00:00
foreach($answer->get('users') as $user){
$view_cluster = '';
2016-07-11 15:44:18 +00:00
/* [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
=========================================================*/
2016-07-12 08:20:57 +00:00
$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 ]);
2016-07-11 15:44:18 +00:00
}
2016-07-11 15:44:18 +00:00
}
?>