SMMP/manager/view/group/view.php

212 lines
6.5 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\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>@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>@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 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 != ManagerError::Success )
return View::$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 != ManagerError::Success )
return View::$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 == ManagerError::Success ) $members = $membersRes->get('members');
else $members = [];
/* (3) On crées les vues des membres (utilisateurs) */
$USERCLUSTERS[$u]['users'] = View::replaceMultiple(
self::template('user'),
$members,
[ 'id_cluster' => $cluster['id_user_cluster'] ]
);
/* (4) On ajoute les attributs utiles */
$USERCLUSTERS[$u]['members'] = (count($members)<2) ? count($members).' utilisateur' : count($members).' utilisateurs';
$USERCLUSTERS[$u]['icon_type'] = file_get_contents(__ROOT__.'/src/static/menu-side/users.svg');
}
/* (5) On crée la vue de la liste des tous les groupes d'utilisateurs */
$user_clusters = View::replaceMultiple(
self::template('user_cluster'),
$USERCLUSTERS, [
'icon_type' => file_get_contents( __ROOT__.'/src/static/menu-side/users.svg' ),
'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' )
]);
/* [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 == ManagerError::Success ) $members = $membersRes->get('members');
else $members = [];
/* (3) On crées les vues des membres (machines) */
$MACHINECLUSTERS[$u]['machines'] = View::replaceMultiple(
self::template('machine'),
$members,
[ 'id_cluster' => $cluster['id_machine_cluster'] ]
);
/* (4) On ajoute les attributs utiles */
$MACHINECLUSTERS[$u]['members'] = (count($members)<2) ? count($members).' machine' : count($members).' machines';
$MACHINECLUSTERS[$u]['icon_type'] = file_get_contents(__ROOT__.'/src/static/menu-side/machines.svg');
}
/* (5) On crée la vue de la liste des tous les groupes de machines */
$machine_clusters = View::replaceMultiple(
self::template('machine_cluster'),
$MACHINECLUSTERS, [
'icon_type' => file_get_contents( __ROOT__.'/src/static/menu-side/device.svg' ),
'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' => $user_clusters.''.$machine_clusters ]);
}
}
?>