SMMP/manager/view/group/view.php

212 lines
6.5 KiB
PHP
Raw Normal View History

2016-07-12 10:06:46 +00:00
<?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 "
2016-07-12 10:06:46 +00:00
<span>
@name
<span class='rem-member' data-member='@id_machine' data-cluster='@id_machine_cluster'></span>
2016-07-12 10:06:46 +00:00
</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;
2016-07-12 10:06:46 +00:00
case 'user_cluster': return "
<article class='inline-box' id='@id_user_cluster'>
<input type='hidden' value='@class'>
2016-07-12 10:06:46 +00:00
<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>
2016-07-12 10:06:46 +00:00
<span class='link_edit' data-cluster='@id_user_cluster'>@icon_edit</span>
2016-07-12 10:06:46 +00:00
<span class='code'>
@icon_type
<span>@members</span>
2016-07-12 10:06:46 +00:00
</span>
<span class='groups'>
@icon_group
@users
<span class='add-member' data-cluster='@id_user_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 = '';
/* [1] On récupère la liste des groupes d'utilisatuers
2016-07-12 10:06:46 +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
/* (2) si erreur, on affiche l'explicitation */
if( $getAllUsers->error != ManagerError::Success )
return View::$htmlError;
2016-07-12 10:06:46 +00:00
/* (3) On enregistre le résultat */
$USERCLUSTERS = $getAllUsers->get('clusters');
2016-07-12 10:06:46 +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 */
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
]);
2016-07-12 10:06:46 +00:00
$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'),
2016-07-12 10:06:46 +00:00
$members,
[ 'id_cluster' => $cluster['id_user_cluster'] ]
2016-07-12 10:06:46 +00:00
);
/* (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');
2016-07-12 10:06:46 +00:00
}
/* (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');
}
2016-07-12 10:06:46 +00:00
/* (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' ),
2016-07-12 10:06:46 +00:00
'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' )
2016-07-12 10:06:46 +00:00
]);
return View::replaceSingle(self::template(), [ 'clusterlist' => $user_clusters.''.$machine_clusters ]);
2016-07-12 10:06:46 +00:00
}
}
?>