From fbefdd55564d2c14e0a4602784abcc51f0279edf Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 17 Jun 2009 06:14:36 -0700 Subject: 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 --- modules/gallery/libraries/Menu.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'modules/gallery/libraries/Menu.php') 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"; } /** -- cgit v1.2.3 From a6a9b256ae7ac686ed1f53c05275ae702fb37aad Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 17 Jun 2009 13:34:18 -0700 Subject: Correct the "inappropriate intimacy" smell that bharat's refined senses pick up --- modules/gallery/libraries/Admin_View.php | 15 +-------------- modules/gallery/libraries/Menu.php | 12 ++++++++++++ modules/gallery/libraries/Theme_View.php | 15 +-------------- 3 files changed, 14 insertions(+), 28 deletions(-) (limited to 'modules/gallery/libraries/Menu.php') diff --git a/modules/gallery/libraries/Admin_View.php b/modules/gallery/libraries/Admin_View.php index 11a96d75..7a7396eb 100644 --- a/modules/gallery/libraries/Admin_View.php +++ b/modules/gallery/libraries/Admin_View.php @@ -69,23 +69,10 @@ class Admin_View_Core extends View { } } - $this->_remove_empty_items($menu); + $menu->compact(); 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); - } - } - } - } - - /** * Print out any site wide status information. */ diff --git a/modules/gallery/libraries/Menu.php b/modules/gallery/libraries/Menu.php index 79274057..6d0881ce 100644 --- a/modules/gallery/libraries/Menu.php +++ b/modules/gallery/libraries/Menu.php @@ -146,6 +146,18 @@ class Menu_Core extends Menu_Element { } } + public function compact() { + foreach ($this->elements as $target_id => $element) { + if ($element->type == "submenu") { + if (empty($element->elements)) { + $this->remove($target_id); + } else { + $element->compact(); + } + } + } + } + public function __construct($type) { parent::__construct($type); $this->elements = array(); diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index 904a3c07..7b2ca840 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -103,25 +103,12 @@ class Theme_View_Core extends View { call_user_func_array(array($class, "site"), array(&$menu, $this)); } } - - $this->_remove_empty_items($menu); } + $menu->compact(); 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"); } -- cgit v1.2.3