SMMP/manager/view/group/userChoice.php

105 lines
2.7 KiB
PHP
Raw Normal View History

2016-07-12 15:40:40 +00:00
<?php
namespace manager\view\group;
use \manager\View;
use \manager\ModuleRequest;
use \manager\Authentification;
use \manager\ManagerError;
class userChoice{
public static function template($type=null){
switch($type){
case 'userlist': return "
<div>
<span>@username</span>
<span>@firstname @lastname</span>
<span>@code</span>
<span>
2016-07-12 15:40:40 +00:00
<input type='checkbox' value='@id_user' data-name='members' id='checkbox_@id_user' @already_in>
<label for='checkbox_@id_user'></label>
2016-07-12 15:40:40 +00:00
</span>
2016-07-12 15:40:40 +00:00
</div>
2016-07-12 15:40:40 +00:00
";
break;
default: return "
<article class='check-table'>
2016-07-12 15:40:40 +00:00
@userlist
</article>";
2016-07-12 15:40:40 +00:00
break;
}
}
public static function view($params){
// On vérifie les paramètres
if( !isset($params['id_cluster']) && !is_number($params['id_cluster']) )
return "<span class='error'>Une erreur est survenue, veuilez contacter le webmaster si cette erreur persiste.</span>";
$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');
/* [2] On récupère la liste des membres
=========================================================*/
$get_members = new ModuleRequest('clusterDefault/getMembers', [
'id_cluster' => $params['id_cluster']
]);
$members_response = $get_members->dispatch();
// On récupère la liste des UID uniquement
$members_id = [];
foreach($members_response->get('members') as $member)
$members_id[] = $member['id_member'];
foreach($USERLIST as $u=>$user)
$USERLIST[$u]['already_in'] = in_array($user['id_user'], $members_id) ? 'checked' : '';
$view_user = View::replaceMultiple(
self::template('userlist'),
$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::template(), [ 'userlist' => $view_user ]);
}
}
?>