From 864474b85850d8f6bc11bbd99c5e09111bd9a458 Mon Sep 17 00:00:00 2001 From: Julius Härtl Date: Mon, 29 Jan 2018 10:07:12 +0100 Subject: Move navigation processing to the NavigationManager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/private/NavigationManager.php | 42 +++++++++++++++++++++++++++++++++++---- lib/private/legacy/app.php | 31 ++--------------------------- 2 files changed, 40 insertions(+), 33 deletions(-) diff --git a/lib/private/NavigationManager.php b/lib/private/NavigationManager.php index 31d147a3b80..36bb9b5ee19 100644 --- a/lib/private/NavigationManager.php +++ b/lib/private/NavigationManager.php @@ -115,15 +115,49 @@ class NavigationManager implements INavigationManager { } $this->closureEntries = array(); - if ($type === 'all') { - return $this->entries; + $result = $this->entries; + if ($type !== 'all') { + $result = array_filter($this->entries, function($entry) use ($type) { + return $entry['type'] === $type; + }); } - return array_filter($this->entries, function($entry) use ($type) { - return $entry['type'] === $type; + return $this->proceedNavigation($result); + } + + /** + * Sort navigation entries by order, name and set active flag + * + * @param $list + * @return mixed + */ + private function proceedNavigation($list) { + usort($list, function($a, $b) { + if (isset($a['order']) && isset($b['order'])) { + return ($a['order'] < $b['order']) ? -1 : 1; + } else if (isset($a['order']) || isset($b['order'])) { + return isset($a['order']) ? -1 : 1; + } else { + return ($a['name'] < $b['name']) ? -1 : 1; + } }); + + $activeApp = $this->getActiveEntry(); + if ($activeApp !== null) { + foreach ($list as $index => &$navEntry) { + if ($navEntry['id'] == $activeApp) { + $navEntry['active'] = true; + } else { + $navEntry['active'] = false; + } + } + unset($navEntry); + } + + return $list; } + /** * removes all the entries */ diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php index b19d63f560e..6102de73693 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -443,31 +443,6 @@ class OC_App { $appManager->disableApp($app); } - // This is private as well. It simply works, so don't ask for more details - private static function proceedNavigation($list) { - usort($list, function($a, $b) { - if (isset($a['order']) && isset($b['order'])) { - return ($a['order'] < $b['order']) ? -1 : 1; - } else if (isset($a['order']) || isset($b['order'])) { - return isset($a['order']) ? -1 : 1; - } else { - return ($a['name'] < $b['name']) ? -1 : 1; - } - }); - - $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); - foreach ($list as $index => &$navEntry) { - if ($navEntry['id'] == $activeApp) { - $navEntry['active'] = true; - } else { - $navEntry['active'] = false; - } - } - unset($navEntry); - - return $list; - } - /** * Get the path where to install apps * @@ -618,8 +593,7 @@ class OC_App { * - active: boolean, signals if the user is on this navigation entry */ public static function getNavigation() { - $entries = OC::$server->getNavigationManager()->getAll(); - return self::proceedNavigation($entries); + return OC::$server->getNavigationManager()->getAll(); } /** @@ -631,8 +605,7 @@ class OC_App { * entries are sorted by the key 'order' ascending. */ public static function getSettingsNavigation() { - $entries = OC::$server->getNavigationManager()->getAll('settings'); - return self::proceedNavigation($entries); + return OC::$server->getNavigationManager()->getAll('settings'); } /** -- cgit v1.2.3