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,36 +388,21 @@ class MenuItem ...@@ -379,36 +388,21 @@ 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) {
$node->toggleSelected($url); if ($node->isVisible()) {
if ($node->getUrl() != "") { $node->toggleSelected($url);
// hash part isn't available on server end if ($node->getUrl() != "") {
$menuItemUrl = explode("#", $node->getUrl())[0]; // hash part isn't available on server end
$match = str_replace(array(".", "*","?"), array("\.", ".*","\?"), $menuItemUrl); $menuItemUrl = explode("#", $node->getUrl())[0];
if (preg_match("@^{$match}$@", "{$url}")) { $match = str_replace(array(".", "*","?"), array("\.", ".*","\?"), $menuItemUrl);
$node->select(); if (preg_match("@^{$match}$@", "{$url}")) {
$node->select();
}
} }
} }
} }
} }
/**
* 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;
}
/** /**
* Recursive method to retrieve a simple ordered structure of all menu items * Recursive method to retrieve a simple ordered structure of all menu items
* @return array named array containing menu items as simple objects to keep the api cleaner for our templates * @return array named array containing menu items as simple objects to keep the api cleaner for our templates
...@@ -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()) {
foreach (self::$internalClassGetterNames as $methodName => $propName) { $result[$key] = new \stdClass();
$result[$node->id]->{$propName} = $node->$methodName(); foreach (self::$internalClassGetterNames as $methodName => $propName) {
$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