public static function buildSortingQuery($config)
    {
        $sorting = $config->getSorting();
        $result  = '';
        $fields  = [];

        if (empty($sorting) || !\is_array($sorting)) {
            return '';
        }
        foreach ($sorting as $field => $direction) {
            // array could be a simple field list or list of field => direction combinations.
            if (!empty($direction)) {
                $direction = \strtoupper($direction);
                if (!\in_array($direction, [DCGE::MODEL_SORTING_ASC, DCGE::MODEL_SORTING_DESC])) {
                    $field     = $direction;
                    $direction = DCGE::MODEL_SORTING_ASC;
                }
            } else {
                $direction = DCGE::MODEL_SORTING_ASC;
            }

            $fields[] = $field . ' ' . $direction;
        }

        $result .= ' ORDER BY ' . \implode(', ', $fields);

        return $result;
    }