From e3013c580108e6b0cc332ba14976f3ffb4b7b274 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Fri, 20 Sep 2013 17:34:33 +0200 Subject: [PATCH] Add Navigation class to server container --- lib/app.php | 31 ++++++--------- lib/navigationmanager.php | 63 +++++++++++++++++++++++++++++++ lib/public/inavigationmanager.php | 27 +++++++++++++ lib/public/iservercontainer.php | 5 +++ lib/server.php | 10 +++++ 5 files changed, 117 insertions(+), 19 deletions(-) create mode 100644 lib/navigationmanager.php create mode 100644 lib/public/inavigationmanager.php diff --git a/lib/app.php b/lib/app.php index d98af2dc29..0ab1ee57f6 100644 --- a/lib/app.php +++ b/lib/app.php @@ -27,8 +27,6 @@ * upgrading and removing apps. */ class OC_App{ - static private $activeapp = ''; - static private $navigation = array(); static private $settingsForms = array(); static private $adminForms = array(); static private $personalForms = array(); @@ -271,7 +269,7 @@ class OC_App{ /** * @brief adds an entry to the navigation - * @param string $data array containing the data + * @param array $data array containing the data * @return bool * * This function adds a new entry to the navigation visible to users. $data @@ -287,11 +285,7 @@ class OC_App{ * the navigation. Lower values come first. */ public static function addNavigationEntry( $data ) { - $data['active']=false; - if(!isset($data['icon'])) { - $data['icon']=''; - } - OC_App::$navigation[] = $data; + OC::$server->getNavigationManager()->add($data); return true; } @@ -305,9 +299,7 @@ class OC_App{ * highlighting the current position of the user. */ public static function setActiveNavigationEntry( $id ) { - // load all the apps, to make sure we have all the navigation entries - self::loadApps(); - self::$activeapp = $id; + OC::$server->getNavigationManager()->setActiveEntry($id); return true; } @@ -315,15 +307,14 @@ class OC_App{ * @brief Get the navigation entries for the $app * @param string $app app * @return array of the $data added with addNavigationEntry + * + * Warning: destroys the existing entries */ public static function getAppNavigationEntries($app) { if(is_file(self::getAppPath($app).'/appinfo/app.php')) { - $save = self::$navigation; - self::$navigation = array(); + OC::$server->getNavigationManager()->clear(); require $app.'/appinfo/app.php'; - $app_entries = self::$navigation; - self::$navigation = $save; - return $app_entries; + return OC::$server->getNavigationManager()->getAll(); } return array(); } @@ -336,7 +327,7 @@ class OC_App{ * setActiveNavigationEntry */ public static function getActiveNavigationEntry() { - return self::$activeapp; + return OC::$server->getNavigationManager()->getActiveEntry(); } /** @@ -419,8 +410,9 @@ class OC_App{ // This is private as well. It simply works, so don't ask for more details private static function proceedNavigation( $list ) { + $activeapp = OC::$server->getNavigationManager()->getActiveEntry(); foreach( $list as &$naventry ) { - if( $naventry['id'] == self::$activeapp ) { + if( $naventry['id'] == $activeapp ) { $naventry['active'] = true; } else{ @@ -572,7 +564,8 @@ class OC_App{ * - active: boolean, signals if the user is on this navigation entry */ public static function getNavigation() { - $navigation = self::proceedNavigation( self::$navigation ); + $entries = OC::$server->getNavigationManager()->getAll(); + $navigation = self::proceedNavigation( $entries ); return $navigation; } diff --git a/lib/navigationmanager.php b/lib/navigationmanager.php new file mode 100644 index 0000000000..f032afd1fc --- /dev/null +++ b/lib/navigationmanager.php @@ -0,0 +1,63 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + * + */ + +namespace OC; + +/** + * Manages the owncloud navigation + */ +class NavigationManager { + protected $entries = array(); + + /** + * Creates a new navigation entry + * @param array $entry containing: id, name, order, icon and href key + */ + public function add(array $entry) { + $entry['active'] = false; + if(!isset($entry['icon'])) { + $entry['icon'] = ''; + } + $this->entries[] = $entry; + } + + /** + * @brief returns all the added Menu entries + * @return array of the added entries + */ + public function getAll() { + return $this->entries; + } + + /** + * @brief removes all the entries + */ + public function clear() { + $this->entries = array(); + } + + /** + * Sets the current navigation entry of the currently running app + * @param string $id of the app entry to activate (from added $entry) + */ + public function setActiveEntry($id) { + $this->activeEntry = $id; + } + + /** + * @brief gets the active Menu entry + * @return string id or empty string + * + * This function returns the id of the active navigation entry (set by + * setActiveEntry + */ + public function getActiveEntry() { + return $this->activeEntry; + } +} diff --git a/lib/public/inavigationmanager.php b/lib/public/inavigationmanager.php new file mode 100644 index 0000000000..21744dd1c2 --- /dev/null +++ b/lib/public/inavigationmanager.php @@ -0,0 +1,27 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + * + */ + +namespace OCP; + +/** + * Manages the owncloud navigation + */ +interface INavigationManager { + /** + * Creates a new navigation entry + * @param array $entry containing: id, name, order, icon and href key + */ + public function add(array $entry); + + /** + * Sets the current navigation entry of the currently running app + * @param string $appId id of the app entry to activate (from added $entry) + */ + public function setActiveEntry($appId); +} \ No newline at end of file diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index 5481cd6ce6..ebcc0fe4cd 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -69,6 +69,11 @@ interface IServerContainer { */ function getUserSession(); + /** + * @return \OCP\INavigationManager + */ + function getNavigationManager(); + /** * Returns an ICache instance * diff --git a/lib/server.php b/lib/server.php index a5288fa148..13bda2dc30 100644 --- a/lib/server.php +++ b/lib/server.php @@ -97,6 +97,9 @@ class Server extends SimpleContainer implements IServerContainer { }); return $userSession; }); + $this->registerService('NavigationManager', function($c) { + return new \OC\NavigationManager(); + }); $this->registerService('UserCache', function($c) { return new UserCache(); }); @@ -152,6 +155,13 @@ class Server extends SimpleContainer implements IServerContainer { return $this->query('UserSession'); } + /** + * @return \OC\NavigationManager + */ + function getNavigationManager() { + return $this->query('NavigationManager'); + } + /** * Returns an ICache instance *