SMMP/build/viewer/view/group/group_view.php

212 lines
6.5 KiB
PHP
Executable File
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 viewer\view\group;
use \viewer\core\Viewer;
use \api\core\ModuleRequest;
use \api\core\Authentification;
use \error\core\Error;
class group_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_cluster'></span>
</span>";
break;
case 'user': return "
<span>
@username
<span class='rem-member' data-member='@id_user' data-cluster='@id_cluster'></span>
</span>";
break;
case 'machine_cluster': return "
<article class='inline-box' id='@id_cluster'>
<span class='title' style='color: ".$_SESSION['WAREHOUSE']['theme']."'>@name</span>
<span class='link_remove' data-cluster='@id_cluster'>@icon_remove</span>
<span class='link_edit' data-cluster='@id_cluster'>@icon_edit</span>
<span class='code'>
@icon_type
<span>@members</span>
</span>
<span class='groups'>
@icon_group
@machines
<span class='add-member' data-cluster='@id_cluster'>+</span>
</span>
</article>";
break;
case 'user_cluster': return "
<article class='inline-box' id='@id_cluster'>
<span class='title' style='color: ".$_SESSION['WAREHOUSE']['theme']."'>@name</span>
<span class='link_remove' data-cluster='@id_cluster'>@icon_remove</span>
<span class='link_edit' data-cluster='@id_cluster'>@icon_edit</span>
<span class='code'>
@icon_type
<span>@members</span>
</span>
<span class='groups'>
@icon_group
@users
<span class='add-member' data-cluster='@id_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 groupes d'utilisatuers
=========================================================*/
/* (1) On récupère les groupes */
$getAllUsersReq = new ModuleRequest('clusterDefault/getAll', ['class' => 0]);
$getAllUsers = $getAllUsersReq->dispatch();
/* (2) si erreur, on affiche l'explicitation */
if( $getAllUsers->error != Error::Success )
return Viewer::$htmlError;
/* (3) On enregistre le résultat */
$USERCLUSTERS = $getAllUsers->get('clusters');
/* [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 */
if( $getAllMachines->error != Error::Success )
return Viewer::$htmlError;
/* (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
]);
$membersRes = $membersReq->dispatch();
/* (2) Gestion si erreur */
if( $membersRes->error == Error::Success ) $members = $membersRes->get('members');
else $members = [];
/* (3) On crées les vues des membres (utilisateurs) */
$USERCLUSTERS[$u]['users'] = Viewer::replaceMultiple(
self::template('user'),
$members,
[ 'id_cluster' => 'u'.$cluster['id_user_cluster'] ]
);
/* (4) On ajoute les attributs utiles */
$USERCLUSTERS[$u]['id_cluster'] = 'u'.$cluster['id_user_cluster'];
$USERCLUSTERS[$u]['members'] = (count($members)<2) ? count($members).' utilisateur' : count($members).' utilisateurs';
$USERCLUSTERS[$u]['icon_type'] = file_get_contents(__PUBLIC__.'/src/static/menu-side/users.svg');
}
/* (5) On crée la vue de la liste des tous les groupes d'utilisateurs */
$user_clusters = Viewer::replaceMultiple(
self::template('user_cluster'),
$USERCLUSTERS, [
'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' )
]);
/* [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 */
if( $membersRes->error == Error::Success ) $members = $membersRes->get('members');
else $members = [];
/* (3) On crées les vues des membres (machines) */
$MACHINECLUSTERS[$u]['machines'] = Viewer::replaceMultiple(
self::template('machine'),
$members,
[ 'id_cluster' => 'm'.$cluster['id_machine_cluster'] ]
);
/* (4) On ajoute les attributs utiles */
$MACHINECLUSTERS[$u]['id_cluster'] = 'm'.$cluster['id_machine_cluster'];
$MACHINECLUSTERS[$u]['members'] = (count($members)<2) ? count($members).' machine' : count($members).' machines';
$MACHINECLUSTERS[$u]['icon_type'] = file_get_contents(__PUBLIC__.'/src/static/menu-side/machines.svg');
}
/* (5) On crée la vue de la liste des tous les groupes de machines */
$machine_clusters = Viewer::replaceMultiple(
self::template('machine_cluster'),
$MACHINECLUSTERS, [
'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' )
]);
return Viewer::replaceSingle(self::template(), [ 'clusterlist' => $user_clusters.''.$machine_clusters ]);
}
}
?>