Prado\Data\Common\TDbCommandBuilder::applyOrdering PHP Method

applyOrdering() public method

public applyOrdering ( $sql, $ordering ) : string
return string modified SQL applied with ORDER BY.
    public function applyOrdering($sql, $ordering)
    {
        $orders = array();
        foreach ($ordering as $name => $direction) {
            $direction = strtolower($direction) == 'desc' ? 'DESC' : 'ASC';
            if (false !== strpos($name, '(') && false !== strpos($name, ')')) {
                // key is a function (bad practice, but we need to handle it)
                $key = $name;
            } else {
                // key is a column
                $key = $this->getTableInfo()->getColumn($name)->getColumnName();
            }
            $orders[] = $key . ' ' . $direction;
        }
        if (count($orders) > 0) {
            $sql .= ' ORDER BY ' . implode(', ', $orders);
        }
        return $sql;
    }