Skip to content

Commit

Permalink
Moved database pagination to the NavigationTree class
Browse files Browse the repository at this point in the history
  • Loading branch information
roccivic committed Oct 30, 2012
1 parent c1ea4f0 commit e0451d9
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 57 deletions.
53 changes: 4 additions & 49 deletions libraries/navigation/Navigation.class.php
Expand Up @@ -41,12 +41,6 @@
*/
class PMA_Navigation
{
/**
* @var int Position in the list of databases,
* used for pagination
*/
private $_pos;

/**
* Initialises the class, handles incoming requests
* and fires up rendering of the output
Expand All @@ -55,37 +49,11 @@ class PMA_Navigation
*/
public function __construct()
{
$GLOBALS['token'] = $_SESSION[' PMA_token '];

if (isset($_REQUEST['pos'])) {
$this->_pos = (int) $_REQUEST['pos'];
}
if (! isset($this->_pos)) {
$this->_pos = $this->_getNavigationDbPos();
if (empty($GLOBALS['token'])) {
$GLOBALS['token'] = $_SESSION[' PMA_token '];
}
}

/**
* Returns the database position for the page selector
*
* @return int
*/
private function _getNavigationDbPos()
{
$query = "SELECT (COUNT(`SCHEMA_NAME`) DIV %d) * %d ";
$query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` ";
$query .= "WHERE `SCHEMA_NAME` < '%s' ";
$query .= "ORDER BY `SCHEMA_NAME` ASC";
return PMA_DBI_fetch_value(
sprintf(
$query,
(int)$GLOBALS['cfg']['MaxNavigationItems'],
(int)$GLOBALS['cfg']['MaxNavigationItems'],
PMA_CommonFunctions::getInstance()->sqlAddSlashes($GLOBALS['db'])
)
);
}

/**
* Renders the navigation tree, or part of it
*
Expand All @@ -99,25 +67,11 @@ public function getDisplay()
$header = new PMA_NavigationHeader();
$retval = $header->getDisplay();
}
$tree = new PMA_NavigationTree($this->_pos);
$tree = new PMA_NavigationTree();
if (! PMA_Response::getInstance()->isAjax()
|| ! empty($_REQUEST['full'])
|| ! empty($_REQUEST['reload'])
) {
$_url_params = array('server' => $GLOBALS['server']);
$num_db = PMA_DBI_fetch_value(
"SELECT COUNT(*) FROM `INFORMATION_SCHEMA`.`SCHEMATA`"
);
$retval .= PMA_commonFunctions::getInstance()->getListNavigator(
$num_db,
$this->_pos,
$_url_params,
'navigation.php',
'frame_navigation',
$GLOBALS['cfg']['MaxNavigationItems'],
'pos',
array('dbselector')
);
$treeRender = $tree->renderState();
} else {
$treeRender = $tree->renderPath();
Expand All @@ -132,6 +86,7 @@ public function getDisplay()
}

if (! PMA_Response::getInstance()->isAjax()) {
// closes the tags that were opened by the navigation header
$retval .= '</div>';
$retval .= '</div>';
$retval .= '</div>';
Expand Down
50 changes: 44 additions & 6 deletions libraries/navigation/NavigationTree.class.php
Expand Up @@ -77,17 +77,19 @@ class PMA_NavigationTree
/**
* Initialises the class
*
* @param int $pos Position in the list of databases,
* used for pagination
*
* @return void
*/
public function __construct($pos)
public function __construct()
{
$this->_commonFunctions = PMA_commonFunctions::getInstance();

// Save the position at which we are in the database list
$this->_pos = $pos;
if (isset($_REQUEST['pos'])) {
$this->_pos = (int) $_REQUEST['pos'];
}
if (! isset($this->_pos)) {
$this->_pos = $this->_getNavigationDbPos();
}
// Get the active node
if (isset($_REQUEST['aPath'])) {
$this->_aPath[0] = $this->_parsePath($_REQUEST['aPath']);
Expand Down Expand Up @@ -137,6 +139,31 @@ public function __construct($pos)
}
}

/**
* Returns the database position for the page selector
*
* @return int
*/
private function _getNavigationDbPos()
{
$retval = 0;
if (! empty($GLOBALS['db'])) {
$query = "SELECT (COUNT(`SCHEMA_NAME`) DIV %d) * %d ";
$query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` ";
$query .= "WHERE `SCHEMA_NAME` < '%s' ";
$query .= "ORDER BY `SCHEMA_NAME` ASC";
$retval = PMA_DBI_fetch_value(
sprintf(
$query,
(int)$GLOBALS['cfg']['MaxNavigationItems'],
(int)$GLOBALS['cfg']['MaxNavigationItems'],
PMA_CommonFunctions::getInstance()->sqlAddSlashes($GLOBALS['db'])
)
);
}
return $retval;
}

/**
* Converts an encoded path to a node in string format to an array
*
Expand Down Expand Up @@ -526,8 +553,19 @@ public function renderState()
if ($node === false) {
$retval = false;
} else {
$retval .= PMA_commonFunctions::getInstance()->getListNavigator(
$this->_tree->getPresence(),
$this->_pos,
array('server' => $GLOBALS['server']),
'navigation.php',
'frame_navigation',
$GLOBALS['cfg']['MaxNavigationItems'],
'pos',
array('dbselector')
);

$this->groupTree();
$retval = $this->_commonFunctions->getImage(
$retval .= $this->_commonFunctions->getImage(
'ajax_clock_small.gif',
__('Loading'),
array('style' => 'visibility: hidden;', 'class' => 'throbber')
Expand Down
12 changes: 10 additions & 2 deletions libraries/navigation/Nodes/Node.class.php
Expand Up @@ -385,9 +385,17 @@ public function getComment()
*
* @return int
*/
public function getPresence($type, $searchClause = '')
public function getPresence($type = '', $searchClause = '')
{
return 0;
if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
$query = "SELECT COUNT(*) ";
$query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` ";
$retval = (int)PMA_DBI_fetch_value($query);
} else {
$query = "SHOW DATABASES ";
$retval = PMA_DBI_num_rows(PMA_DBI_try_query($query));
}
return $retval;
}
}
?>

0 comments on commit e0451d9

Please sign in to comment.