ArticleAuthor::ProcessListOrder PHP Method

ProcessListOrder() private static method

Processes an order directive coming from template tags.
private static ProcessListOrder ( array $p_order ) : array
$p_order array The array of order directives
return array The array containing processed values of the condition
    private static function ProcessListOrder(array $p_order)
    {
        $order = array();
        if (empty($p_order)) {
            $p_order = array(array('field' => 'default', 'dir' => 'asc'));
        }
        foreach ($p_order as $orderDesc) {
            $dbField = null;
            $field = $orderDesc['field'];
            $direction = $orderDesc['dir'];
            switch (strtolower($field)) {
                case 'default':
                    $dbField = '`order`';
                    break;
                case 'byfirstname':
                    $dbField = 'first_name';
                    break;
                case 'bylastname':
                    $dbField = 'last_name';
                    break;
            }
            if (!is_null($dbField)) {
                $direction = !empty($direction) ? $direction : 'asc';
                $order[] = array('field' => $dbField, 'dir' => $direction);
            }
        }
        return $order;
    }