PMA\libraries\DisplayResults::_isInSorted PHP Method

_isInSorted() private method

Check whether the column is sorted
See also: _getTableHeaders()
private _isInSorted ( array $sort_expression, array $sort_expression_nodirection, string $sort_tbl, string $name_to_use_in_sort ) : boolean
$sort_expression array sort expression
$sort_expression_nodirection array sort expression without direction
$sort_tbl string the table name
$name_to_use_in_sort string the sorting column name
return boolean $is_in_sort the column sorted or not
    private function _isInSorted($sort_expression, $sort_expression_nodirection, $sort_tbl, $name_to_use_in_sort)
    {
        $index_in_expression = 0;
        foreach ($sort_expression_nodirection as $index => $clause) {
            if (mb_strpos($clause, '.') !== false) {
                $fragments = explode('.', $clause);
                $clause2 = $fragments[0] . "." . str_replace('`', '', $fragments[1]);
            } else {
                $clause2 = $sort_tbl . str_replace('`', '', $clause);
            }
            if ($clause2 === $sort_tbl . $name_to_use_in_sort) {
                $index_in_expression = $index;
                break;
            }
        }
        if (empty($sort_expression[$index_in_expression])) {
            $is_in_sort = false;
        } else {
            // Field name may be preceded by a space, or any number
            // of characters followed by a dot (tablename.fieldname)
            // so do a direct comparison for the sort expression;
            // this avoids problems with queries like
            // "SELECT id, count(id)..." and clicking to sort
            // on id or on count(id).
            // Another query to test this:
            // SELECT p.*, FROM_UNIXTIME(p.temps) FROM mytable AS p
            // (and try clicking on each column's header twice)
            $noSortTable = empty($sort_tbl) || mb_strpos($sort_expression_nodirection[$index_in_expression], $sort_tbl) === false;
            $noOpenParenthesis = mb_strpos($sort_expression_nodirection[$index_in_expression], '(') === false;
            if (!empty($sort_tbl) && $noSortTable && $noOpenParenthesis) {
                $new_sort_expression_nodirection = $sort_tbl . $sort_expression_nodirection[$index_in_expression];
            } else {
                $new_sort_expression_nodirection = $sort_expression_nodirection[$index_in_expression];
            }
            //Back quotes are removed in next comparison, so remove them from value
            //to compare.
            $name_to_use_in_sort = str_replace('`', '', $name_to_use_in_sort);
            $is_in_sort = false;
            $sort_name = str_replace('`', '', $sort_tbl) . $name_to_use_in_sort;
            if ($sort_name == str_replace('`', '', $new_sort_expression_nodirection) || $sort_name == str_replace('`', '', $sort_expression_nodirection[$index_in_expression])) {
                $is_in_sort = true;
            }
        }
        return $is_in_sort;
    }
DisplayResults