lithium\data\source\MongoDb::order PHP Method

order() public method

Return formatted clause for order.
public order ( mixed $order, object $context ) : mixed
$order mixed The `order` clause to be formatted
$context object
return mixed Formatted `order` clause.
    public function order($order, $context)
    {
        if (!$order) {
            return array();
        }
        if (is_string($order)) {
            return array($order => 1);
        }
        if (!is_array($order)) {
            return array();
        }
        foreach ($order as $key => $value) {
            if (!is_string($key)) {
                unset($order[$key]);
                $order[$value] = 1;
                continue;
            }
            if (is_string($value)) {
                $order[$key] = strtolower($value) === 'asc' ? 1 : -1;
            }
        }
        return $order;
    }