Commit 75572ae3 authored by Cédric Houbart's avatar Cédric Houbart
Browse files

Menu sections

parent 4b780f6e
......@@ -36,23 +36,62 @@ class MenuEntry {
public function getAction() { return $this->action; }
}
class MenuSection {
private $nameDomain;
private $name;
private $entries;
public function __construct($name, $domain = NULL) {
$this->name = $name;
$this->nameDomain = $domain;
$this->entries = array();
}
public function addEntry($menuEntry) {
$this->entries[] = $menuEntry;
}
public function getName() { return $this->name; }
public function getNameDomain() { return $this->nameDomain; }
public function getEntries() { return $this->entries; }
}
class Menu {
private $entries;
private $sections;
public function __construct() {
$this->entries = array();
$this->entries[] = new MenuEntry("Home", "home");
$this->sections = array();
$this->addSection("general", "General");
$entry = new MenuEntry("Home", "home");
$this->addEntry("general", $entry);
}
public function addSection($id, $name, $nameDomain = NULL) {
if (!isset($this->sections[$id])) {
$this->sections[$id] = new MenuSection($name, $nameDomain);
return TRUE;
}
return FALSE;
}
public function addEntry($sectionId, $entry) {
if (isset($this->sections[$sectionId])) {
$this->sections[$sectionId]->addEntry($entry);
return TRUE;
}
return FALSE;
}
public function register_module_entry($module_name, $name, $action) {
$this->entries[] = new MenuEntry($name,
get_module_action($module_name, $action),
public function registerModuleEntry($sectionId, $module_name, $name,
$action) {
$entry = new MenuEntry($name, get_module_action($module_name, $action),
$module_name);
return $this->addEntry($sectionId, $entry);
}
public function get_entries() {
return $this->entries;
public function getSections() {
return $this->sections;
}
}
......
......@@ -22,9 +22,10 @@ namespace BaseProducts;
function init() {
global $MENU;
$MENU->register_module_entry(PLUGIN_NAME, "Taxes", "taxes");
$MENU->register_module_entry(PLUGIN_NAME, "Categories", "categories");
$MENU->register_module_entry(PLUGIN_NAME, "Products", "products");
$MENU->addSection("catalog", "Catalog", PLUGIN_NAME);
$MENU->registerModuleEntry("catalog", PLUGIN_NAME, "Taxes", "taxes");
$MENU->registerModuleEntry("catalog", PLUGIN_NAME, "Categories", "categories");
$MENU->registerModuleEntry("catalog", PLUGIN_NAME, "Products", "products");
\Pasteque\register_i18n(PLUGIN_NAME);
}
\Pasteque\hook("module_load", __NAMESPACE__ . "\init");
......
{
"Catalog": "Catalog",
"Products": "Products",
"Add a product": "Add a product",
"No product found": "No product found",
......
{
"Catalog": "Catalogue",
"Products": "Produits",
"Add a product": "Ajouter un produit",
"No product found": "Aucun produit trouvé",
......
......@@ -22,7 +22,8 @@ namespace BaseUsers;
function init() {
global $MENU;
$MENU->register_module_entry(PLUGIN_NAME, "Users", "users");
$MENU->addSection("admin", "Administration", PLUGIN_NAME);
$MENU->registerModuleEntry("admin", PLUGIN_NAME, "Users", "users");
\Pasteque\register_i18n(PLUGIN_NAME);
}
\Pasteque\hook("module_load", __NAMESPACE__ . "\init");
......
{
"Administration": "Administration",
"Products": "Products",
"Add a product": "Add a product",
"No product found": "No product found",
......
{
"Administration": "Administration",
"Products": "Produits",
"Add a product": "Ajouter un produit",
"No product found": "Aucun produit trouvé",
......
......@@ -52,14 +52,19 @@ function tpl_404() {
function tpl_menu() {
global $MENU;
$entries = $MENU->get_entries();
$sections = $MENU->getSections();
echo "<div id=\"menu-container\">\n";
echo "\t<img src=\"" . get_template_url() . "img/logo.png" . "\" />\n";
echo "\t<ul class=\"menu\">\n";
foreach ($entries as $entry) {
echo "\t\t<li><a href=\"" . get_url_action($entry->getAction()) . "\">" . __($entry->getName(), $entry->getNameDomain()) . "</a></li>\n";
foreach ($sections as $section) {
echo("\t<div class=\"section-title\">" . \i18n($section->getName(), $section->getNameDomain()) . "</div>\n");
echo "\t<ul class=\"menu\">\n";
$entries = $section->getEntries();
foreach ($entries as $entry) {
echo "\t\t<li><a href=\"" . get_url_action($entry->getAction()) . "\">" . \i18n($entry->getName(), $entry->getNameDomain()) . "</a></li>\n";
}
echo "\t</ul>\n";
}
echo "</div>";
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment