From 6cb5756e7dbbbd40d2fb24a3974fd13eb5777f80 Mon Sep 17 00:00:00 2001 From: Hugues Peccatte Date: Sun, 20 Apr 2014 16:04:53 +0200 Subject: [PATCH] Manage a config proporty to limit the number of items at first level in navigation panel. Signed-off-by: Hugues Peccatte --- doc/config.rst | 8 ++++ libraries/config.default.php | 7 ++++ libraries/config.values.php | 1 + libraries/config/messages.inc.php | 5 +++ libraries/config/setup.forms.php | 1 + libraries/config/user_preferences.forms.php | 1 + libraries/navigation/Nodes/Node.class.php | 42 ++++++++++++++++++++- 7 files changed, 63 insertions(+), 2 deletions(-) diff --git a/doc/config.rst b/doc/config.rst index 1a8faf021e..88ae1ed477 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -1374,6 +1374,14 @@ Cookie authentication options Navigation panel setup ---------------------- +.. config:option:: $cfg['FirstLevelNavigationItems'] + + :type: integer + :default: 25 + + The number of items that can be displayed on each page of the first level + of navigation tree. + .. config:option:: $cfg['MaxNavigationItems'] :type: integer diff --git a/libraries/config.default.php b/libraries/config.default.php index 1953cea6b6..31cd2151f5 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -847,6 +847,13 @@ $cfg['Error_Handler']['display'] = false; * Navigation panel setup */ +/** + * maximum number of items displayed on first level in navigation panel + * + * @global integer $cfg['FirstLevelNavigationItems'] + */ +$cfg['FirstLevelNavigationItems'] = 25; + /** * maximum number of items displayed in navigation panel * diff --git a/libraries/config.values.php b/libraries/config.values.php index d5b63ad45e..b8012291db 100644 --- a/libraries/config.values.php +++ b/libraries/config.values.php @@ -211,6 +211,7 @@ $cfg_db['_validators'] = array( 'CharTextareaRows' => 'validatePositiveNumber', 'ExecTimeLimit' => 'validateNonNegativeNumber', 'Export/sql_max_query_size' => 'validatePositiveNumber', + 'FirstLevelNavigationItems' => 'validatePositiveNumber', 'ForeignKeyMaxLimit' => 'validatePositiveNumber', 'Import/csv_enclosed' => array(array('validateByRegex', '/^.?$/')), 'Import/csv_escaped' => array(array('validateByRegex', '/^.$/')), diff --git a/libraries/config/messages.inc.php b/libraries/config/messages.inc.php index 2c2c5c9d4b..07f59b65ba 100644 --- a/libraries/config/messages.inc.php +++ b/libraries/config/messages.inc.php @@ -398,6 +398,11 @@ $strConfigMaxDbList_cmt = __('Users cannot set a higher value'); $strConfigMaxDbList_desc = __('Maximum number of databases displayed in database list.'); $strConfigMaxDbList_name = __('Maximum databases'); +$strConfigFirstLevelNavigationItems_desc = __( + 'The number of items that can be displayed on each page on first level of the ' + . 'navigation tree.' +); +$strConfigFirstLevelNavigationItems_name = __('Maximum items on first level'); $strConfigMaxNavigationItems_desc = __( 'The number of items that can be displayed on each page of the navigation tree.' ); diff --git a/libraries/config/setup.forms.php b/libraries/config/setup.forms.php index ddd01711af..1c612378e5 100644 --- a/libraries/config/setup.forms.php +++ b/libraries/config/setup.forms.php @@ -170,6 +170,7 @@ $forms['Navi_panel']['Navi_panel'] = array( 'NavigationLogoLink', 'NavigationLogoLinkWindow', 'NavigationTreePointerEnable', + 'FirstLevelNavigationItems', 'MaxNavigationItems', 'NavigationTreeEnableGrouping', 'NavigationTreeDisableDatabaseExpansion', diff --git a/libraries/config/user_preferences.forms.php b/libraries/config/user_preferences.forms.php index 19601c119f..51b481fa76 100644 --- a/libraries/config/user_preferences.forms.php +++ b/libraries/config/user_preferences.forms.php @@ -83,6 +83,7 @@ $forms['Navi_panel']['Navi_panel'] = array( 'NavigationLogoLink', 'NavigationLogoLinkWindow', 'NavigationTreePointerEnable', + 'FirstLevelNavigationItems', 'MaxNavigationItems', 'NavigationTreeEnableGrouping', 'NavigationTreeDisableDatabaseExpansion', diff --git a/libraries/navigation/Nodes/Node.class.php b/libraries/navigation/Nodes/Node.class.php index 5354985de1..2cfe8bc90a 100644 --- a/libraries/navigation/Nodes/Node.class.php +++ b/libraries/navigation/Nodes/Node.class.php @@ -360,11 +360,49 @@ class Node */ public function getData($type, $pos, $searchClause = '') { - $query = "SELECT `SCHEMA_NAME` "; + /*$query = "SELECT `SCHEMA_NAME` "; $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` "; $query .= $this->_getWhereClause($searchClause); $query .= "ORDER BY `SCHEMA_NAME` ASC "; - $query .= "LIMIT $pos, {$GLOBALS['cfg']['MaxNavigationItems']}"; + $query .= "LIMIT $pos, {$GLOBALS['cfg']['MaxNavigationItems']}";*/ + + $query = "SELECT `SCHEMA_NAME` "; + $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA`, "; + $query .= " ("; + $query .= " select DB_first_level "; + $query .= " from ( "; + $query .= " SELECT distinct SUBSTRING_INDEX(SCHEMA_NAME, "; + $query .= "'{$GLOBALS['cfg']['NavigationTreeDbSeparator']}', 1) "; + $query .= "DB_first_level "; + $query .= " FROM INFORMATION_SCHEMA.SCHEMATA "; + $query .= $this->_getWhereClause($searchClause); + $query .= " ) t "; + $query .= " ORDER BY DB_first_level ASC "; + $query .= " LIMIT $pos, {$GLOBALS['cfg']['FirstLevelNavigationItems']}"; + $query .= " ) t2 "; + $query .= "where 1 = locate(concat(DB_first_level, "; + $query .= "'{$GLOBALS['cfg']['NavigationTreeDbSeparator']}'), "; + $query .= "concat(SCHEMA_NAME, "; + $query .= "'{$GLOBALS['cfg']['NavigationTreeDbSeparator']}')) "; + $query .= "order by SCHEMA_NAME ASC"; + /*echo $query; + + SELECT `SCHEMA_NAME` + FROM `INFORMATION_SCHEMA`.`SCHEMATA`, + ( + select DB_first_level + from ( + SELECT distinct SUBSTRING_INDEX(SCHEMA_NAME, '_', 1) DB_first_level + FROM INFORMATION_SCHEMA.SCHEMATA + WHERE TRUE + ) t + ORDER BY DB_first_level ASC + LIMIT 0, 5 + ) t2 + where 1 = locate(concat(DB_first_level, '_'), concat(SCHEMA_NAME, '_')) + order by SCHEMA_NAME ASC + */ + return $GLOBALS['dbi']->fetchResult($query); }