Commit 4e95a064 authored by Ad Schellevis's avatar Ad Schellevis

(menu) minor performance changes

parent 902b9431
...@@ -280,6 +280,15 @@ class MenuItem ...@@ -280,6 +280,15 @@ class MenuItem
return $this->visibility; return $this->visibility;
} }
/**
* is node visible
* @return bool
*/
public function isVisible()
{
return $this->visibility != 'delete';
}
/** /**
* check if this item is selected * check if this item is selected
* @return bool is this item selected * @return bool is this item selected
...@@ -379,7 +388,8 @@ class MenuItem ...@@ -379,7 +388,8 @@ class MenuItem
public function toggleSelected($url) public function toggleSelected($url)
{ {
$this->selected = false; $this->selected = false;
foreach ($this->getFilteredChildren() as $nodeId => $node) { foreach ($this->children as $nodeId => &$node) {
if ($node->isVisible()) {
$node->toggleSelected($url); $node->toggleSelected($url);
if ($node->getUrl() != "") { if ($node->getUrl() != "") {
// hash part isn't available on server end // hash part isn't available on server end
...@@ -391,22 +401,6 @@ class MenuItem ...@@ -391,22 +401,6 @@ class MenuItem
} }
} }
} }
/**
* Menu items are pluggable and can override already existing sections.
* This function filters the available child items and only return the still existing ones.
* @return array filtered set of children
*/
private function getFilteredChildren()
{
$result = array();
foreach ($this->children as $key => $node) {
if ($node->getVisibility() != 'delete') {
$result[$key] = $node;
}
}
ksort($result);
return $result;
} }
/** /**
...@@ -417,12 +411,15 @@ class MenuItem ...@@ -417,12 +411,15 @@ class MenuItem
{ {
$result = array(); $result = array();
// sort by order/id and map getters to array items // sort by order/id and map getters to array items
foreach ($this->getFilteredChildren() as $key => $node) { foreach ($this->children as $key => &$node) {
$result[$node->id] = new \stdClass(); if ($node->isVisible()) {
$result[$key] = new \stdClass();
foreach (self::$internalClassGetterNames as $methodName => $propName) { foreach (self::$internalClassGetterNames as $methodName => $propName) {
$result[$node->id]->{$propName} = $node->$methodName(); $result[$key]->{$propName} = $node->$methodName();
} }
} }
}
ksort($result);
return $result; return $result;
} }
...@@ -434,8 +431,8 @@ class MenuItem ...@@ -434,8 +431,8 @@ class MenuItem
*/ */
public function findNodeById($id) public function findNodeById($id)
{ {
foreach ($this->getFilteredChildren() as $key => $node) { foreach ($this->children as $key => &$node) {
if (strtolower($node->getId()) == strtolower($id)) { if ($node->isVisible() && strtolower($node->getId()) == strtolower($id)) {
return $node; return $node;
} }
} }
......
Markdown is supported
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