SMMP/manager/view/users.php

121 lines
3.0 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace manager\view;
use \manager\View;
use \manager\ModuleRequest;
use \manager\Authentification;
use \manager\ManagerError;
class users{
public static function templateUserlist($type=null){
switch($type){
case 'cluster': return "
<span>
@name
<span class='rem-group' data-group='@id_cluster' data-user='@id_user'></span>
</span>";
break;
case 'user': return "
<article class='inline-box' id='@id_user'>
<span class='title'>@firstname @lastname <span>#@username</span></span>
<span class='link_remove' data-user='@id_user'>@icon_remove</span>
<span class='link_edit' data-user='@id_user'>@icon_edit</span>
<span class='code'>
@icon_card
<span>@code</span>
</span>
<span class='mail'>
@icon_mail
<a href='mailto:@mail'>
<span>@mail</span>
</a>
</span>
<span class='groups'>
@icon_group
@grouplist
<span class='add-group' data-user='@id_user'>+</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>";
$USERLIST = $answer->get('users');
foreach($USERLIST as $u=>$user){
$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 = [];
$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::replaceSingle(self::templateUserlist(), [ 'userlist' => $view_user ]);
}
}
?>