148 lines
4.0 KiB
PHP
148 lines
4.0 KiB
PHP
<?php
|
||
|
||
namespace manager\view\group;
|
||
use \manager\View;
|
||
use \manager\ModuleRequest;
|
||
use \manager\Authentification;
|
||
use \manager\ManagerError;
|
||
|
||
class view{
|
||
|
||
public static function template($type=null){
|
||
|
||
switch($type){
|
||
case 'machine': return "
|
||
<span>
|
||
@name
|
||
<span class='rem-member' data-member='@id_machine' data-cluster='@id_machine_cluster'></span>
|
||
</span>";
|
||
break;
|
||
case 'user': return "
|
||
<span>
|
||
@username
|
||
<span class='rem-member' data-member='@id_user' data-cluster='@id_user_cluster'></span>
|
||
</span>";
|
||
break;
|
||
|
||
|
||
|
||
case 'machine_cluster': return "
|
||
<article class='inline-box' id='@id_machine_cluster'>
|
||
<input type='hidden' value='@class'>
|
||
|
||
<span class='title' style='color: ".$_SESSION['WAREHOUSE']['theme']."'>@name <span>#@name</span></span>
|
||
<span class='link_remove' data-cluster='@id_machine_cluster'>@icon_remove</span>
|
||
|
||
<span class='link_edit' data-cluster='@id_machine_cluster'>@icon_edit</span>
|
||
|
||
<span class='code'>
|
||
@icon_type
|
||
<span>machines (@nb_members)</span>
|
||
</span>
|
||
|
||
<span class='groups'>
|
||
@icon_group
|
||
@machines
|
||
<span class='add-member' data-cluster='@id_machine_cluster'>+</span>
|
||
</span>
|
||
|
||
</article>";
|
||
break;
|
||
|
||
|
||
|
||
case 'user_cluster': return "
|
||
<article class='inline-box' id='@id_user_cluster'>
|
||
<input type='hidden' value='@class'>
|
||
|
||
<span class='title' style='color: ".$_SESSION['WAREHOUSE']['theme']."'>@name <span>#@name</span></span>
|
||
<span class='link_remove' data-cluster='@id_user_cluster'>@icon_remove</span>
|
||
|
||
<span class='link_edit' data-cluster='@id_user_cluster'>@icon_edit</span>
|
||
|
||
<span class='code'>
|
||
@icon_type
|
||
<span>utilisateurs (@nb_members)</span>
|
||
</span>
|
||
|
||
<span class='groups'>
|
||
@icon_group
|
||
@users
|
||
<span class='add-member' data-cluster='@id_user_cluster'>+</span>
|
||
</span>
|
||
|
||
</article>";
|
||
break;
|
||
|
||
|
||
default: return "
|
||
<input type='text' class='searchbar' placeholder='Recherche'>
|
||
@clusterlist";
|
||
break;
|
||
|
||
}
|
||
}
|
||
|
||
public static function view($params){
|
||
$view = '';
|
||
|
||
/* [1] On récupère la liste des utilisateurs
|
||
=========================================================*/
|
||
$request = new ModuleRequest('clusterDefault/getAll'); // On utilise la methode 'getAll' du module 'clusterDefault'
|
||
$answer = $request->dispatch(); // On recupere la reponse
|
||
|
||
// si erreur, on affiche l'explicitation
|
||
if( $answer->error != ManagerError::Success )
|
||
return View::$htmlError;
|
||
|
||
$CLUSTERLIST = $answer->get('clusters');
|
||
|
||
|
||
foreach($CLUSTERLIST as $u=>$cluster){
|
||
$membersReq = new ModuleRequest('clusterDefault/getMembers', [ 'id_cluster' => $cluster['id_cluster'] ]);
|
||
$membersRes = $membersReq->dispatch();
|
||
|
||
/* (2) Gestion si erreur */
|
||
if( $membersRes->error == ManagerError::Success ) $members = $membersRes->get('members');
|
||
else $members = [];
|
||
|
||
$CLUSTERLIST[$u]['members'] = View::replaceMultiple(
|
||
self::template('member'),
|
||
$members,
|
||
[ 'id_cluster' => $cluster['id_cluster'] ]
|
||
);
|
||
|
||
|
||
$CLUSTERLIST[$u]['class'] = (isset($cluster['id_user_cluster'])) ? 0 : 1;
|
||
$CLUSTERLIST[$u]['nb_members'] = (count($members)<2) ? count($members).' membre' : count($members).'membres';
|
||
$CLUSTERLIST[$u]['icon_type'] = ($cluster['class']==0) ? file_get_contents( __ROOT__.'/src/static/menu-side/users.svg' ) : file_get_contents( __ROOT__.'/src/static/menu-side/device.svg' );
|
||
}
|
||
|
||
|
||
$view_cluster = View::replaceMultiple(
|
||
self::template('cluster'),
|
||
$CLUSTERLIST, [
|
||
'icon_remove' => file_get_contents( __ROOT__.'/src/static/sub-menu-side/remove.svg' ),
|
||
'icon_group' => file_get_contents( __ROOT__.'/src/static/container/group.svg' ),
|
||
'icon_edit' => file_get_contents( __ROOT__.'/src/static/sub-menu-side/edit.svg' )
|
||
]);
|
||
|
||
|
||
|
||
|
||
|
||
return View::replaceSingle(self::template(), [ 'clusterlist' => $view_cluster ]);
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
?>
|