Back to PhocaGalleryOrdering class

Method getOrderingString

public static
getOrderingString
(mixed $ordering, mixed $type = 1)

Method getOrderingString - Source code

/*
 * Set Ordering String if Ordering is defined in Parameters
 * 2 ... category
 * 1 ... image
 */
public static function getOrderingString($ordering, $type = 1)
{
    $oO = array();
    // Default
    $oO['column'] = 'ordering';
    $oO['sort'] = 'ASC';
    switch ($type) {
        case 2:
            $oO['pref'] = $prefId = 'cc';
            break;
        default:
            $oO['pref'] = $prefId = 'a';
            break;
    }
    switch ((int) $ordering) {
        case 2:
            $oO['column'] = 'ordering';
            $oO['sort'] = 'DESC';
            break;
        case 3:
            $oO['column'] = 'title';
            $oO['sort'] = 'ASC';
            break;
        case 4:
            $oO['column'] = 'title';
            $oO['sort'] = 'DESC';
            break;
        case 5:
            $oO['column'] = 'date';
            $oO['sort'] = 'ASC';
            break;
        case 6:
            $oO['column'] = 'date';
            $oO['sort'] = 'DESC';
            break;
        case 7:
            $oO['column'] = 'id';
            $oO['sort'] = 'ASC';
            break;
        case 8:
            $oO['column'] = 'id';
            $oO['sort'] = 'DESC';
            break;
        // Random will be used e.g. ORDER BY RAND()
        /* if ($imageOrdering == 9) {
        					$imageOrdering = ' ORDER BY RAND()';
        				} else {
        					$imageOrdering = ' ORDER BY '.PhocaGalleryOrdering::getOrderingString($image_ordering);
        				}
        			*/
        case 9:
            $oO['column'] = '';
            $oO['sort'] = '';
            $oO['output'] = ' ORDER BY RAND()';
            return $oO;
            //$orderingOutput = '';
            break;
        // Is not ordered by recursive function needs not to be used
        case 10:
            $oO['column'] = '';
            $oO['sort'] = '';
            $oO['output'] = '';
            return $oO;
            break;
        case 11:
            $oO['column'] = 'count';
            $oO['sort'] = 'ASC';
            $oO['pref'] = 'r';
            break;
        case 12:
            $oO['column'] = 'count';
            $oO['sort'] = 'DESC';
            $oO['pref'] = 'r';
            break;
        case 13:
            $oO['column'] = 'average';
            $oO['sort'] = 'ASC';
            $oO['pref'] = 'r';
            break;
        case 14:
            $oO['column'] = 'average';
            $oO['sort'] = 'DESC';
            $oO['pref'] = 'r';
            break;
        case 15:
            $oO['column'] = 'hits';
            $oO['sort'] = 'ASC';
            break;
        case 16:
            $oO['column'] = 'hits';
            $oO['sort'] = 'DESC';
            break;
        case 1:
        default:
            $oO['column'] = 'ordering';
            $oO['sort'] = 'ASC';
            break;
    }
    if ($oO['pref'] == 'r') {
        $oO['output'] = ' ORDER BY ' . $oO['pref'] . '.' . $oO['column'] . ' ' . $oO['sort'] . ', ' . $prefId . '.id ' . $oO['sort'];
    } else {
        $oO['output'] = ' ORDER BY ' . $oO['pref'] . '.' . $oO['column'] . ' ' . $oO['sort'];
    }
    return $oO;
}