2016-07-12 10:06:46 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
2016-10-18 14:03:03 +00:00
|
|
|
|
namespace viewer\view\group;
|
|
|
|
|
use \viewer\core\Viewer;
|
|
|
|
|
use \api\core\ModuleRequest;
|
|
|
|
|
use \api\core\Authentification;
|
2016-10-18 17:09:47 +00:00
|
|
|
|
use \error\core\Error;
|
2016-07-12 10:06:46 +00:00
|
|
|
|
|
2016-08-06 09:32:50 +00:00
|
|
|
|
class group_view{
|
2016-07-12 10:06:46 +00:00
|
|
|
|
|
|
|
|
|
public static function template($type=null){
|
|
|
|
|
|
|
|
|
|
switch($type){
|
2016-07-18 14:46:06 +00:00
|
|
|
|
case 'machine': return "
|
2016-07-12 10:06:46 +00:00
|
|
|
|
<span>
|
|
|
|
|
@name
|
2016-07-20 15:33:38 +00:00
|
|
|
|
<span class='rem-member' data-member='@id_machine' data-cluster='@id_cluster'></span>
|
2016-07-12 10:06:46 +00:00
|
|
|
|
</span>";
|
|
|
|
|
break;
|
2016-07-18 14:46:06 +00:00
|
|
|
|
case 'user': return "
|
|
|
|
|
<span>
|
|
|
|
|
@username
|
2016-07-20 15:33:38 +00:00
|
|
|
|
<span class='rem-member' data-member='@id_user' data-cluster='@id_cluster'></span>
|
2016-07-18 14:46:06 +00:00
|
|
|
|
</span>";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'machine_cluster': return "
|
2016-07-20 15:33:38 +00:00
|
|
|
|
<article class='inline-box' id='@id_cluster'>
|
2016-07-18 14:46:06 +00:00
|
|
|
|
|
2016-07-20 15:33:38 +00:00
|
|
|
|
<span class='title' style='color: ".$_SESSION['WAREHOUSE']['theme']."'>@name</span>
|
|
|
|
|
<span class='link_remove' data-cluster='@id_cluster'>@icon_remove</span>
|
2016-07-18 14:46:06 +00:00
|
|
|
|
|
2016-07-20 15:33:38 +00:00
|
|
|
|
<span class='link_edit' data-cluster='@id_cluster'>@icon_edit</span>
|
2016-07-18 14:46:06 +00:00
|
|
|
|
|
|
|
|
|
<span class='code'>
|
|
|
|
|
@icon_type
|
2016-07-20 14:50:41 +00:00
|
|
|
|
<span>@members</span>
|
2016-07-18 14:46:06 +00:00
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
<span class='groups'>
|
|
|
|
|
@icon_group
|
|
|
|
|
@machines
|
2016-07-20 15:33:38 +00:00
|
|
|
|
<span class='add-member' data-cluster='@id_cluster'>+</span>
|
2016-07-18 14:46:06 +00:00
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
</article>";
|
|
|
|
|
break;
|
2016-07-12 10:06:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-07-18 14:46:06 +00:00
|
|
|
|
case 'user_cluster': return "
|
2016-07-20 15:33:38 +00:00
|
|
|
|
<article class='inline-box' id='@id_cluster'>
|
2016-07-12 10:06:46 +00:00
|
|
|
|
|
2016-07-20 15:33:38 +00:00
|
|
|
|
<span class='title' style='color: ".$_SESSION['WAREHOUSE']['theme']."'>@name</span>
|
|
|
|
|
<span class='link_remove' data-cluster='@id_cluster'>@icon_remove</span>
|
2016-07-12 10:06:46 +00:00
|
|
|
|
|
2016-07-20 15:33:38 +00:00
|
|
|
|
<span class='link_edit' data-cluster='@id_cluster'>@icon_edit</span>
|
2016-07-12 10:06:46 +00:00
|
|
|
|
|
|
|
|
|
<span class='code'>
|
|
|
|
|
@icon_type
|
2016-07-20 14:50:41 +00:00
|
|
|
|
<span>@members</span>
|
2016-07-12 10:06:46 +00:00
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
<span class='groups'>
|
|
|
|
|
@icon_group
|
2016-07-18 14:46:06 +00:00
|
|
|
|
@users
|
2016-07-20 15:33:38 +00:00
|
|
|
|
<span class='add-member' data-cluster='@id_cluster'>+</span>
|
2016-07-12 10:06:46 +00:00
|
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
</article>";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default: return "
|
|
|
|
|
<input type='text' class='searchbar' placeholder='Recherche'>
|
|
|
|
|
@clusterlist";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function view($params){
|
|
|
|
|
$view = '';
|
|
|
|
|
|
2016-07-20 14:50:41 +00:00
|
|
|
|
/* [1] On récupère la liste des groupes d'utilisatuers
|
2016-07-12 10:06:46 +00:00
|
|
|
|
=========================================================*/
|
2016-07-20 14:50:41 +00:00
|
|
|
|
/* (1) On récupère les groupes */
|
|
|
|
|
$getAllUsersReq = new ModuleRequest('clusterDefault/getAll', ['class' => 0]);
|
|
|
|
|
$getAllUsers = $getAllUsersReq->dispatch();
|
2016-07-12 10:06:46 +00:00
|
|
|
|
|
2016-07-20 14:50:41 +00:00
|
|
|
|
/* (2) si erreur, on affiche l'explicitation */
|
2016-10-18 17:09:47 +00:00
|
|
|
|
if( $getAllUsers->error != Error::Success )
|
2016-10-18 14:03:03 +00:00
|
|
|
|
return Viewer::$htmlError;
|
2016-07-12 10:06:46 +00:00
|
|
|
|
|
2016-07-20 14:50:41 +00:00
|
|
|
|
/* (3) On enregistre le résultat */
|
|
|
|
|
$USERCLUSTERS = $getAllUsers->get('clusters');
|
2016-07-12 10:06:46 +00:00
|
|
|
|
|
|
|
|
|
|
2016-07-20 14:50:41 +00:00
|
|
|
|
|
|
|
|
|
/* [2] On récupère la liste des groupes de machines
|
|
|
|
|
=========================================================*/
|
|
|
|
|
/* (1) On récupère les groupes */
|
|
|
|
|
$getAllMachinesReq = new ModuleRequest('clusterDefault/getAll', ['class' => 1]);
|
|
|
|
|
$getAllMachines = $getAllMachinesReq->dispatch();
|
|
|
|
|
|
|
|
|
|
/* (2) si erreur, on affiche l'explicitation */
|
2016-10-18 17:09:47 +00:00
|
|
|
|
if( $getAllMachines->error != Error::Success )
|
2016-10-18 14:03:03 +00:00
|
|
|
|
return Viewer::$htmlError;
|
2016-07-20 14:50:41 +00:00
|
|
|
|
|
|
|
|
|
/* (3) On enregistre le résultat */
|
|
|
|
|
$MACHINECLUSTERS = $getAllMachines->get('clusters');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] On crée la vue avec les groupes d'utilisateurs
|
|
|
|
|
=========================================================*/
|
|
|
|
|
foreach($USERCLUSTERS as $u=>$cluster){
|
|
|
|
|
/* (1) On récupère les members */
|
|
|
|
|
$membersReq = new ModuleRequest('clusterDefault/getMembers', [
|
|
|
|
|
'id_cluster' => $cluster['id_user_cluster'],
|
|
|
|
|
'class' => 0
|
|
|
|
|
]);
|
2016-07-12 10:06:46 +00:00
|
|
|
|
$membersRes = $membersReq->dispatch();
|
|
|
|
|
|
|
|
|
|
/* (2) Gestion si erreur */
|
2016-10-18 17:09:47 +00:00
|
|
|
|
if( $membersRes->error == Error::Success ) $members = $membersRes->get('members');
|
2016-07-12 10:06:46 +00:00
|
|
|
|
else $members = [];
|
|
|
|
|
|
2016-07-20 14:50:41 +00:00
|
|
|
|
/* (3) On crées les vues des membres (utilisateurs) */
|
2016-10-18 14:03:03 +00:00
|
|
|
|
$USERCLUSTERS[$u]['users'] = Viewer::replaceMultiple(
|
2016-07-20 14:50:41 +00:00
|
|
|
|
self::template('user'),
|
2016-07-12 10:06:46 +00:00
|
|
|
|
$members,
|
2016-07-20 15:33:38 +00:00
|
|
|
|
[ 'id_cluster' => 'u'.$cluster['id_user_cluster'] ]
|
2016-07-12 10:06:46 +00:00
|
|
|
|
);
|
|
|
|
|
|
2016-07-20 14:50:41 +00:00
|
|
|
|
/* (4) On ajoute les attributs utiles */
|
2016-07-20 15:33:38 +00:00
|
|
|
|
$USERCLUSTERS[$u]['id_cluster'] = 'u'.$cluster['id_user_cluster'];
|
|
|
|
|
$USERCLUSTERS[$u]['members'] = (count($members)<2) ? count($members).' utilisateur' : count($members).' utilisateurs';
|
2016-10-18 14:03:03 +00:00
|
|
|
|
$USERCLUSTERS[$u]['icon_type'] = file_get_contents(__PUBLIC__.'/src/static/menu-side/users.svg');
|
2016-07-12 10:06:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-20 14:50:41 +00:00
|
|
|
|
/* (5) On crée la vue de la liste des tous les groupes d'utilisateurs */
|
2016-10-18 14:03:03 +00:00
|
|
|
|
$user_clusters = Viewer::replaceMultiple(
|
2016-07-20 14:50:41 +00:00
|
|
|
|
self::template('user_cluster'),
|
|
|
|
|
$USERCLUSTERS, [
|
2016-10-18 14:03:03 +00:00
|
|
|
|
'icon_type' => file_get_contents( __PUBLIC__.'/src/static/menu-side/users.svg' ),
|
|
|
|
|
'icon_remove' => file_get_contents( __PUBLIC__.'/src/static/sub-menu-side/remove.svg' ),
|
|
|
|
|
'icon_group' => file_get_contents( __PUBLIC__.'/src/static/container/group.svg' ),
|
|
|
|
|
'icon_edit' => file_get_contents( __PUBLIC__.'/src/static/sub-menu-side/edit.svg' )
|
2016-07-20 14:50:41 +00:00
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [4] On crée la vue avec les groupes de machines
|
|
|
|
|
=========================================================*/
|
|
|
|
|
foreach($MACHINECLUSTERS as $u=>$cluster){
|
|
|
|
|
/* (1) On récupère les members */
|
|
|
|
|
$membersReq = new ModuleRequest('clusterDefault/getMembers', [
|
|
|
|
|
'id_cluster' => $cluster['id_machine_cluster'],
|
|
|
|
|
'class' => 1
|
|
|
|
|
]);
|
|
|
|
|
$membersRes = $membersReq->dispatch();
|
|
|
|
|
|
|
|
|
|
/* (2) Gestion si erreur */
|
2016-10-18 17:09:47 +00:00
|
|
|
|
if( $membersRes->error == Error::Success ) $members = $membersRes->get('members');
|
2016-07-20 14:50:41 +00:00
|
|
|
|
else $members = [];
|
|
|
|
|
|
|
|
|
|
/* (3) On crées les vues des membres (machines) */
|
2016-10-18 14:03:03 +00:00
|
|
|
|
$MACHINECLUSTERS[$u]['machines'] = Viewer::replaceMultiple(
|
2016-07-20 14:50:41 +00:00
|
|
|
|
self::template('machine'),
|
|
|
|
|
$members,
|
2016-07-20 15:33:38 +00:00
|
|
|
|
[ 'id_cluster' => 'm'.$cluster['id_machine_cluster'] ]
|
2016-07-20 14:50:41 +00:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/* (4) On ajoute les attributs utiles */
|
2016-07-20 15:33:38 +00:00
|
|
|
|
$MACHINECLUSTERS[$u]['id_cluster'] = 'm'.$cluster['id_machine_cluster'];
|
|
|
|
|
$MACHINECLUSTERS[$u]['members'] = (count($members)<2) ? count($members).' machine' : count($members).' machines';
|
2016-10-18 14:03:03 +00:00
|
|
|
|
$MACHINECLUSTERS[$u]['icon_type'] = file_get_contents(__PUBLIC__.'/src/static/menu-side/machines.svg');
|
2016-07-20 14:50:41 +00:00
|
|
|
|
}
|
2016-07-12 10:06:46 +00:00
|
|
|
|
|
2016-07-20 14:50:41 +00:00
|
|
|
|
/* (5) On crée la vue de la liste des tous les groupes de machines */
|
2016-10-18 14:03:03 +00:00
|
|
|
|
$machine_clusters = Viewer::replaceMultiple(
|
2016-07-20 14:50:41 +00:00
|
|
|
|
self::template('machine_cluster'),
|
|
|
|
|
$MACHINECLUSTERS, [
|
2016-10-18 14:03:03 +00:00
|
|
|
|
'icon_type' => file_get_contents( __PUBLIC__.'/src/static/menu-side/device.svg' ),
|
|
|
|
|
'icon_remove' => file_get_contents( __PUBLIC__.'/src/static/sub-menu-side/remove.svg' ),
|
|
|
|
|
'icon_group' => file_get_contents( __PUBLIC__.'/src/static/container/group.svg' ),
|
|
|
|
|
'icon_edit' => file_get_contents( __PUBLIC__.'/src/static/sub-menu-side/edit.svg' )
|
2016-07-12 10:06:46 +00:00
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-18 14:03:03 +00:00
|
|
|
|
return Viewer::replaceSingle(self::template(), [ 'clusterlist' => $user_clusters.''.$machine_clusters ]);
|
2016-07-12 10:06:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
?>
|