From 0e61603636e4afec491f42694deb0a66b217cfec Mon Sep 17 00:00:00 2001 From: flack Date: Sat, 7 Apr 2012 16:42:05 +0200 Subject: [PATCH] remove some duplication --- lib/midcom/services/toolbars.php | 43 +++++++------------------------- 1 file changed, 9 insertions(+), 34 deletions(-) diff --git a/lib/midcom/services/toolbars.php b/lib/midcom/services/toolbars.php index fe9825c128..fa7cb41252 100644 --- a/lib/midcom/services/toolbars.php +++ b/lib/midcom/services/toolbars.php @@ -183,17 +183,7 @@ function get_class_magic_default_privileges() */ function get_host_toolbar($context_id = null) { - if ($context_id === null) - { - $context_id = midcom_core_context::get()->id; - } - - if (! array_key_exists($context_id, $this->_toolbars)) - { - $this->_create_toolbars($context_id); - } - - return $this->_toolbars[$context_id][MIDCOM_TOOLBAR_HOST]; + return $this->_get_toolbar($context_id, MIDCOM_TOOLBAR_HOST); } /** @@ -205,17 +195,7 @@ function get_host_toolbar($context_id = null) */ function get_node_toolbar($context_id = null) { - if ($context_id === null) - { - $context_id = midcom_core_context::get()->id; - } - - if (! array_key_exists($context_id, $this->_toolbars)) - { - $this->_create_toolbars($context_id); - } - - return $this->_toolbars[$context_id][MIDCOM_TOOLBAR_NODE]; + return $this->_get_toolbar($context_id, MIDCOM_TOOLBAR_NODE); } /** @@ -227,17 +207,7 @@ function get_node_toolbar($context_id = null) */ function get_view_toolbar($context_id = null) { - if ($context_id === null) - { - $context_id = midcom_core_context::get()->id; - } - - if (! array_key_exists($context_id, $this->_toolbars)) - { - $this->_create_toolbars($context_id); - } - - return $this->_toolbars[$context_id][MIDCOM_TOOLBAR_VIEW]; + return $this->_get_toolbar($context_id, MIDCOM_TOOLBAR_VIEW); } /** @@ -248,6 +218,11 @@ function get_view_toolbar($context_id = null) * defaults to the current context. */ function get_help_toolbar($context_id = null) + { + return $this->_get_toolbar($context_id, MIDCOM_TOOLBAR_HELP); + } + + private function _get_toolbar($context_id, $identifier) { if ($context_id === null) { @@ -259,7 +234,7 @@ function get_help_toolbar($context_id = null) $this->_create_toolbars($context_id); } - return $this->_toolbars[$context_id][MIDCOM_TOOLBAR_HELP]; + return $this->_toolbars[$context_id][$identifier]; } /**