summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-06-17 21:14:36 +0800
committer <unostar@danalan.info>2009-06-18 16:29:39 +0800
commite2863cf1c568b2e88d6c08fa67800a13cd4bd067 (patch)
tree881e8b1cc11ea270c6bab079697697fe2d46dd7e
parent753ce3e02596c9dc1bc072707c214197088b4611 (diff)
Fix for ticket #366
1) Stored the menu element type in the menu element 2) Scanned the menu before display removing any empty sub menus. Went with the removal approach because there will more users than developers Signed-off-by: <unostar@danalan.info>
-rw-r--r--modules/gallery/libraries/Menu.php19
-rw-r--r--modules/gallery/libraries/Theme_View.php14
2 files changed, 26 insertions, 7 deletions
diff --git a/modules/gallery/libraries/Menu.php b/modules/gallery/libraries/Menu.php
index 83bd1616..79274057 100644
--- a/modules/gallery/libraries/Menu.php
+++ b/modules/gallery/libraries/Menu.php
@@ -23,6 +23,11 @@ class Menu_Element {
public $css_id;
public $css_class;
public $id;
+ public $type;
+
+ public function __construct($type) {
+ $this->type = $type;
+ }
/**
* Set the id
@@ -125,26 +130,26 @@ class Menu_Core extends Menu_Element {
public static function factory($type) {
switch($type) {
case "link":
- return new Menu_Element_Link();
+ return new Menu_Element_Link($type);
case "dialog":
- return new Menu_Element_Dialog();
+ return new Menu_Element_Dialog($type);
case "root":
- $menu = new Menu();
- $menu->is_root = true;
- return $menu;
+ return new Menu("root");
case "submenu":
- return new Menu();
+ return new Menu("submenu");
default:
throw Exception("@todo UNKNOWN_MENU_TYPE");
}
}
- public function __construct() {
+ public function __construct($type) {
+ parent::__construct($type);
$this->elements = array();
+ $this->is_root = $type == "root";
}
/**
diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php
index 31c2faa7..904a3c07 100644
--- a/modules/gallery/libraries/Theme_View.php
+++ b/modules/gallery/libraries/Theme_View.php
@@ -103,11 +103,25 @@ class Theme_View_Core extends View {
call_user_func_array(array($class, "site"), array(&$menu, $this));
}
}
+
+ $this->_remove_empty_items($menu);
}
print $menu;
}
+ private function _remove_empty_items($menu) {
+ foreach ($menu->elements as $target_id => $element) {
+ if ($element->type == "submenu") {
+ if (empty($element->elements)) {
+ $menu->remove($target_id);
+ } else {
+ $this->_remove_empty_items($element);
+ }
+ }
+ }
+ }
+
public function album_menu() {
$this->_menu("album");
}