Skip to content

Commit

Permalink
remove some duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
flack committed Apr 7, 2012
1 parent af441bb commit 0e61603
Showing 1 changed file with 9 additions and 34 deletions.
43 changes: 9 additions & 34 deletions lib/midcom/services/toolbars.php
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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)
{
Expand All @@ -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];
}

/**
Expand Down

0 comments on commit 0e61603

Please sign in to comment.