Merged feature/menuManager into dev
This commit is contained in:
commit
b4e6a6975b
|
@ -79,5 +79,6 @@
|
|||
// ));
|
||||
|
||||
// var_dump($response);
|
||||
|
||||
|
||||
?>
|
|
@ -0,0 +1,63 @@
|
|||
[
|
||||
|
||||
{ "icon": "f/svg/home/st/menu-side", "text": "Tableau de bord",
|
||||
"attributes": { "data-link": "dashboard", "class": "sep" },
|
||||
|
||||
"children": [
|
||||
{ "permissions": [], "text": "Présentation",
|
||||
"attributes": { "data-sublink": "presentation" } },
|
||||
{ "permissions": [], "text": "Actualités",
|
||||
"attributes": { "data-sublink": "posts" } }
|
||||
]
|
||||
},
|
||||
|
||||
|
||||
{ "icon": "f/svg/input/st/menu-side", "text": "Acquisition",
|
||||
"attributes": { "data-link": "input" },
|
||||
|
||||
"children": [
|
||||
{ "permissions": [], "text": "Questionnaire",
|
||||
"attributes": { "data-sublink": "survey" } },
|
||||
{ "permissions": [], "text": "Facebook",
|
||||
"attributes": { "data-sublink": "facebook" } },
|
||||
{ "permissions": [], "text": "Téléphone",
|
||||
"attributes": { "data-sublink": "phone" } },
|
||||
{ "permissions": [], "text": "Messenger",
|
||||
"attributes": { "data-sublink": "messenger" } }
|
||||
]
|
||||
},
|
||||
|
||||
|
||||
{ "icon": "f/svg/analytics/st/menu-side", "text": "Statistiques",
|
||||
"attributes": { "data-link": "analytics" },
|
||||
|
||||
"children": [
|
||||
{ "permissions": [], "text": "Extraction de données",
|
||||
"attributes": { "data-sublink": "export" } }
|
||||
]
|
||||
},
|
||||
|
||||
|
||||
{ "icon": "f/svg/charts/st/menu-side", "text": "Graphiques",
|
||||
"attributes": { "data-link": "charts" },
|
||||
|
||||
"children": [
|
||||
{ "permissions": [], "text": "Téléphone",
|
||||
"attributes": { "data-sublink": "phone" } },
|
||||
{ "permissions": [], "text": "Toutes les données",
|
||||
"attributes": { "data-sublink": "all" } }
|
||||
]
|
||||
},
|
||||
|
||||
|
||||
{ "icon": "f/svg/settings/st/menu-side", "text": "Paramètres",
|
||||
"attributes": { "data-link": "settings" },
|
||||
|
||||
"children": [
|
||||
{ "permissions": ["admin"], "text": "Gestion des tokens",
|
||||
"attributes": { "data-sublink": "tokens" } },
|
||||
{ "permissions": ["admin"], "text": "Gestion des utilisateurs",
|
||||
"attributes": { "data-sublink": "users" } }
|
||||
]
|
||||
}
|
||||
]
|
|
@ -7,6 +7,7 @@
|
|||
use \manager\ModuleRequest;
|
||||
use \manager\ManagerError;
|
||||
use \manager\Database;
|
||||
use \manager\MenuManager;
|
||||
|
||||
|
||||
|
||||
|
@ -80,8 +81,8 @@
|
|||
|
||||
/* [2] On recupere la liste des pages du site
|
||||
=========================================================*/
|
||||
$views = json_decode( ResourceDispatcher::getResource( 'f/json/views/conf', true ) );
|
||||
|
||||
$temporaryMenuInflater = new MenuManager();
|
||||
$views = $temporaryMenuInflater->getCategories();
|
||||
|
||||
|
||||
// nomPage/arg1/arg2 -> inclusion de la page
|
||||
|
|
|
@ -0,0 +1,232 @@
|
|||
<?php
|
||||
|
||||
namespace manager;
|
||||
|
||||
use \manager\ResourceDispatcher;
|
||||
|
||||
|
||||
class MenuManager{
|
||||
|
||||
// Constantes
|
||||
public static $config_path = 'f/json/menu/conf';
|
||||
|
||||
|
||||
// Attributs prives utiles (initialisation)
|
||||
private $categories; // liste des parties
|
||||
|
||||
// Contiendra les erreurs
|
||||
public $error;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* CONSTRUCTEUR D'UN MENU
|
||||
*
|
||||
*/
|
||||
public function __construct(){
|
||||
/* [0] On met a jour la configuration
|
||||
=========================================================*/
|
||||
// Categories specifiees
|
||||
$this->categories = json_decode( ResourceDispatcher::getResource(self::$config_path), true );
|
||||
|
||||
// Gestion de l'erreur de parsage
|
||||
if( $this->categories == null ){
|
||||
$this->error = ManagerError::ParsingFailed;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/* [1] Gestion du retour
|
||||
=========================================================*/
|
||||
$this->error = ManagerError::Success;
|
||||
|
||||
return true; // On retourne que tout s'est bien passe
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* CONSTRUIT LE MENU EN HTML EN FONCTION DES DROITS DE L'UTILISATEUR
|
||||
*
|
||||
* @return menu<String> Contenu HTML correspondant au droits de l'utilisateur
|
||||
*
|
||||
*/
|
||||
public function inflate(){
|
||||
/* [1] On construit le menu
|
||||
=========================================================*/
|
||||
$this->buildMenu();
|
||||
|
||||
/* [2] Initialisation du resultat
|
||||
=========================================================*/
|
||||
$render = '';
|
||||
|
||||
|
||||
/* [3] Pour chaque categorie
|
||||
=========================================================*/
|
||||
foreach($this->categories as $category){
|
||||
// On met les attributs
|
||||
$render .= '<span'.$this->parseAttributes($category['attributes']).'>';
|
||||
// On met l'icone associee
|
||||
$render .= ResourceDispatcher::getResource($category['icon']);
|
||||
// On met le texte de la categorie et on ferme la balise
|
||||
$render .= $category['text'].'</span>';
|
||||
|
||||
|
||||
// On ouvre la liste des sous-parties
|
||||
$render .= "<div class='sub'>";
|
||||
|
||||
/* [4] Pour chaque sous-partie
|
||||
=========================================================*/
|
||||
foreach($category['children'] as $children){
|
||||
// On met les attributs
|
||||
$render .= '<span'.$this->parseAttributes($children['attributes']).'>';
|
||||
// On met le texte et on ferme la balise
|
||||
$render .= $children['text'].'</span>';
|
||||
}
|
||||
|
||||
// On ferme la liste des sous-parties
|
||||
$render .= "</div>";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $render;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getCategories(){
|
||||
/* [1] On construit le menu
|
||||
=========================================================*/
|
||||
$this->buildMenu();
|
||||
|
||||
/* [2] On recupere la liste des categories
|
||||
=========================================================*/
|
||||
$views = array();
|
||||
|
||||
foreach($this->categories as $category)
|
||||
array_push($views, $category['attributes']['data-link']);
|
||||
|
||||
|
||||
/* [3] On retourne la liste des categories
|
||||
=========================================================*/
|
||||
return $views;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* VERIFIE TOUTES LES PERMISSIONS ET MET A JOUR LES CATEGORIES AVEC LES PARTIES QUE L'ON PEUT ACCEDER UNIQUEMENT
|
||||
*
|
||||
*/
|
||||
public function buildMenu(){
|
||||
/* [0] Initialisation du menu qui va etre retourne (vide)
|
||||
=========================================================*/
|
||||
$menu = array();
|
||||
|
||||
/* [1] Pour chaque categorie
|
||||
=========================================================*/
|
||||
foreach($this->categories as $a=>$category){
|
||||
// Contiendra les sous-parties dont on a acces
|
||||
$access_children = array();
|
||||
|
||||
/* [2] Pour chaque sous-partie
|
||||
=========================================================*/
|
||||
foreach($category['children'] as $b=>$children){
|
||||
/* (1) On verifie les permissions */
|
||||
$canView = $this->checkPermissions($children['permissions']);
|
||||
|
||||
/* (2) Si on a l'acces, ajout au tableau */
|
||||
if( $canView )
|
||||
array_push($access_children, $children);
|
||||
}
|
||||
|
||||
/* (3) Si liste des sous-parties n'est pas vide */
|
||||
if( count($access_children) > 0 ){
|
||||
|
||||
/* (4) On recupere la categorie parente */
|
||||
$defaultCategory = $this->categories[$a];
|
||||
|
||||
/* (5) Mais on met que les enfants qu'on a recupere (dont on a acces) */
|
||||
$defaultCategory['children'] = $access_children;
|
||||
|
||||
|
||||
/* (6) On ajoute la categorie au menu */
|
||||
array_push($menu, $defaultCategory);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* [3] On met a jour le menu
|
||||
=========================================================*/
|
||||
$this->categories = $menu;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* VERIFIE LES PERMISSIONS DE L'UTILISATEUR PARMI UN TABLEAU DE PERMISSIONS
|
||||
*
|
||||
* @permissions<Array> Liste des permissions
|
||||
*
|
||||
* @return permission<bool> Retourne VRAI si on a la permission
|
||||
*
|
||||
*/
|
||||
private function checkPermissions($permissions){
|
||||
/* [1] Si aucune permission specifiee
|
||||
=========================================================*/
|
||||
// Si aucune permission specifiee, on a l'acces
|
||||
if( count($permissions) == 0 ) return true;
|
||||
|
||||
/* [2] On verifie pour chaque permission
|
||||
=========================================================*/
|
||||
foreach($permissions as $permission){
|
||||
// Si on a la permission qu'on verifie, on a l'acces
|
||||
if( permission($permission) ) return true;
|
||||
}
|
||||
|
||||
/* [3] Gestion du retour si aucune permission => FAUX
|
||||
=========================================================*/
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* PARSE UNE LISTE D'ATTRIBUTS AU FORMAT HTML
|
||||
*
|
||||
* @attr<Array> Tableau associatif representant 'nomAttribut'=>'valAttribut'
|
||||
*
|
||||
* @return HTML<String> Renvoie les attributs au format HTML
|
||||
*
|
||||
*/
|
||||
private function parseAttributes($attr){
|
||||
/* [1] On initialise le resultat
|
||||
=========================================================*/
|
||||
$render = ' ';
|
||||
|
||||
/* [2] Ecriture de tous les attributs
|
||||
=========================================================*/
|
||||
foreach($attr as $name=>$value)
|
||||
$render .= $name."='".$value."' ";
|
||||
|
||||
/* [3] Retour du resultat
|
||||
=========================================================*/
|
||||
return $render;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
35
view.php
35
view.php
|
@ -1,4 +1,5 @@
|
|||
<?php use \manager\ResourceDispatcher; ?>
|
||||
<?php use \manager\ResourceDispatcher;
|
||||
use \manager\MenuManager; ?>
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
|
@ -86,34 +87,10 @@
|
|||
|
||||
<!-- MENU DE LA PAGE -->
|
||||
<nav id='MENU-SIDE'>
|
||||
<span data-link='dashboard' class='sep'><?= ResourceDispatcher::getResource('f/svg/home/st/menu-side'); ?>Tableau de bord</span>
|
||||
<div class='sub'>
|
||||
<span data-sublink='presentation'>Presentation</span>
|
||||
<span data-sublink='posts'>Actualités</span>
|
||||
</div>
|
||||
|
||||
<span data-link='input' ><?= ResourceDispatcher::getResource('f/svg/input/st/menu-side'); ?>Acquisition</span>
|
||||
<div class='sub'>
|
||||
<span data-sublink='survey'>Questionnaire</span>
|
||||
<span data-sublink='facebook'>Facebook</span>
|
||||
<span data-sublink='telephone'>Journal telephonique</span>
|
||||
</div>
|
||||
|
||||
<span data-link='analytics' ><?= ResourceDispatcher::getResource('f/svg/analytics/st/menu-side'); ?>Statistiques</span>
|
||||
<span data-link='charts' class='sep'><?= ResourceDispatcher::getResource('f/svg/charts/st/menu-side'); ?>Visualisation</span>
|
||||
<div class='sub'>
|
||||
<span data-sublink='network'>Reseau</span>
|
||||
</div>
|
||||
|
||||
<?php if( permission('admin') ){ ?>
|
||||
|
||||
<span data-link='settings' ><?= ResourceDispatcher::getResource('f/svg/settings/st/menu-side' ); ?>Paramètres</span>
|
||||
<div class='sub'>
|
||||
<span data-sublink='tokens'>Gestion des tokens</span>
|
||||
<span data-sublink='users'>Gestion des utilisateurs</span>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php
|
||||
$menuInflater = new MenuManager();
|
||||
echo $menuInflater->inflate();
|
||||
?>
|
||||
</nav>
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue