PMA\libraries\navigation\nodes\Node::getData PHP Method

getData() public method

Returns the names of children of type $type present inside this container This method is overridden by the PMA\libraries\navigation\nodes\NodeDatabase and PMA\libraries\navigation\nodes\NodeTable classes
public getData ( string $type, integer $pos, string $searchClause = '' ) : array
$type string The type of item we are looking for ('tables', 'views', etc)
$pos integer The offset of the list within the results
$searchClause string A string used to filter the results of the query
return array
    public function getData($type, $pos, $searchClause = '')
    {
        $maxItems = $GLOBALS['cfg']['FirstLevelNavigationItems'];
        if (!$GLOBALS['cfg']['NavigationTreeEnableGrouping'] || !$GLOBALS['cfg']['ShowDatabasesNavigationAsTree']) {
            if (isset($GLOBALS['cfg']['Server']['DisableIS']) && !$GLOBALS['cfg']['Server']['DisableIS']) {
                $query = "SELECT `SCHEMA_NAME` ";
                $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` ";
                $query .= $this->_getWhereClause('SCHEMA_NAME', $searchClause);
                $query .= "ORDER BY `SCHEMA_NAME` ";
                $query .= "LIMIT {$pos}, {$maxItems}";
                $retval = $GLOBALS['dbi']->fetchResult($query);
                return $retval;
            }
            if ($GLOBALS['dbs_to_test'] === false) {
                $retval = array();
                $query = "SHOW DATABASES ";
                $query .= $this->_getWhereClause('Database', $searchClause);
                $handle = $GLOBALS['dbi']->tryQuery($query);
                if ($handle === false) {
                    return $retval;
                }
                $count = 0;
                if (!$GLOBALS['dbi']->dataSeek($handle, $pos)) {
                    return $retval;
                }
                while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
                    if ($count < $maxItems) {
                        $retval[] = $arr[0];
                        $count++;
                    } else {
                        break;
                    }
                }
                return $retval;
            }
            $retval = array();
            $count = 0;
            foreach ($this->_getDatabasesToSearch($searchClause) as $db) {
                $query = "SHOW DATABASES LIKE '" . $db . "'";
                $handle = $GLOBALS['dbi']->tryQuery($query);
                if ($handle === false) {
                    continue;
                }
                while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
                    if ($this->_isHideDb($arr[0])) {
                        continue;
                    }
                    if (in_array($arr[0], $retval)) {
                        continue;
                    }
                    if ($pos <= 0 && $count < $maxItems) {
                        $retval[] = $arr[0];
                        $count++;
                    }
                    $pos--;
                }
            }
            sort($retval);
            return $retval;
        }
        $dbSeparator = $GLOBALS['cfg']['NavigationTreeDbSeparator'];
        if (isset($GLOBALS['cfg']['Server']['DisableIS']) && !$GLOBALS['cfg']['Server']['DisableIS']) {
            $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['dbi']->escapeString($dbSeparator) . "', 1) ";
            $query .= "DB_first_level ";
            $query .= "FROM INFORMATION_SCHEMA.SCHEMATA ";
            $query .= $this->_getWhereClause('SCHEMA_NAME', $searchClause);
            $query .= ") t ";
            $query .= "ORDER BY DB_first_level ASC ";
            $query .= "LIMIT {$pos}, {$maxItems}";
            $query .= ") t2 ";
            $query .= $this->_getWhereClause('SCHEMA_NAME', $searchClause);
            $query .= "AND 1 = LOCATE(CONCAT(DB_first_level, ";
            $query .= "'" . $GLOBALS['dbi']->escapeString($dbSeparator) . "'), ";
            $query .= "CONCAT(SCHEMA_NAME, ";
            $query .= "'" . $GLOBALS['dbi']->escapeString($dbSeparator) . "')) ";
            $query .= "ORDER BY SCHEMA_NAME ASC";
            $retval = $GLOBALS['dbi']->fetchResult($query);
            return $retval;
        }
        if ($GLOBALS['dbs_to_test'] === false) {
            $query = "SHOW DATABASES ";
            $query .= $this->_getWhereClause('Database', $searchClause);
            $handle = $GLOBALS['dbi']->tryQuery($query);
            $prefixes = array();
            if ($handle !== false) {
                $prefixMap = array();
                $total = $pos + $maxItems;
                while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
                    $prefix = strstr($arr[0], $dbSeparator, true);
                    if ($prefix === false) {
                        $prefix = $arr[0];
                    }
                    $prefixMap[$prefix] = 1;
                    if (sizeof($prefixMap) == $total) {
                        break;
                    }
                }
                $prefixes = array_slice(array_keys($prefixMap), $pos);
            }
            $query = "SHOW DATABASES ";
            $query .= $this->_getWhereClause('Database', $searchClause);
            $query .= "AND (";
            $subClauses = array();
            foreach ($prefixes as $prefix) {
                $subClauses[] = " LOCATE('" . $GLOBALS['dbi']->escapeString($prefix) . $dbSeparator . "', " . "CONCAT(`Database`, '" . $dbSeparator . "')) = 1 ";
            }
            $query .= implode("OR", $subClauses) . ")";
            $retval = $GLOBALS['dbi']->fetchResult($query);
            return $retval;
        }
        $retval = array();
        $prefixMap = array();
        $total = $pos + $maxItems;
        foreach ($this->_getDatabasesToSearch($searchClause) as $db) {
            $query = "SHOW DATABASES LIKE '" . $db . "'";
            $handle = $GLOBALS['dbi']->tryQuery($query);
            if ($handle === false) {
                continue;
            }
            while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
                if ($this->_isHideDb($arr[0])) {
                    continue;
                }
                $prefix = strstr($arr[0], $dbSeparator, true);
                if ($prefix === false) {
                    $prefix = $arr[0];
                }
                $prefixMap[$prefix] = 1;
                if (sizeof($prefixMap) == $total) {
                    break 2;
                }
            }
        }
        $prefixes = array_slice(array_keys($prefixMap), $pos);
        foreach ($this->_getDatabasesToSearch($searchClause) as $db) {
            $query = "SHOW DATABASES LIKE '" . $db . "'";
            $handle = $GLOBALS['dbi']->tryQuery($query);
            if ($handle === false) {
                continue;
            }
            while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
                if ($this->_isHideDb($arr[0])) {
                    continue;
                }
                if (in_array($arr[0], $retval)) {
                    continue;
                }
                foreach ($prefixes as $prefix) {
                    $starts_with = strpos($arr[0] . $dbSeparator, $prefix . $dbSeparator) === 0;
                    if ($starts_with) {
                        $retval[] = $arr[0];
                        break;
                    }
                }
            }
        }
        sort($retval);
        return $retval;
    }