public function orderBy($field, $direction = self::DESC) {
        if (is_array($field)) {
            foreach ($field as $key => $dir) {
                $this->orderBy($key, $dir);
            }

        } else if ($field === 'RAND') {
            $this->_orderBy[] = $this->func('RAND');

        } else if ($field instanceof Func) {
            $this->_orderBy[] = $field;

        } else {
            $direction = strtolower($direction);

            if ($direction != self::ASC && $direction != self::DESC) {
                throw new InvalidArgumentException(sprintf('Invalid order direction %s for field %s', $direction, $field));
            }

            $this->_orderBy[$field] = $direction;
        }

        return $this;
    }
public function orderBy($field, $direction = self::DESC) {
        if (is_array($field)) {
            foreach ($field as $key => $dir) {
                $this->orderBy($key, $dir);
            }

        } else if ($field === 'RAND') {
            $this->_orderBy[] = $this->func('RAND');

        } else if ($field instanceof Func) {
            $this->_orderBy[] = $field;

        } else {
            $direction = strtolower($direction);

            if ($direction != self::ASC && $direction != self::DESC) {
                throw new InvalidArgumentException(sprintf('Invalid order direction %s for field %s', $direction, $field));
            }

            $this->_orderBy[$field] = $direction;
        }

        return $this;
    }
public function orderBy ( $ field , $ direction = self :: DESC ) { if ( is_array ( $ field ) ) { foreach ( $ field as $ key => $ dir ) { $ this -> orderBy ( $ key , $ dir ) ; } } else if ( $ field === 'RAND' ) { $ this -> _orderBy [ ] = $ this -> func ( 'RAND' ) ; } else if ( $ field instanceof Func ) { $ this -> _orderBy [ ] = $ field ; } else { $ direction = strtolower ( $ direction ) ; if ( $ direction != self :: ASC && $ direction != self :: DESC ) { throw new InvalidArgumentException ( sprintf ( 'Invalid order direction %s for field %s' , $ direction , $ field ) ) ; } $ this -> _orderBy [ $ field ] = $ direction ; } return $ this ; }
Set the fields and direction to order by.

@param string|array $field
@param string $direction
@return $this
@throws \Titon\Db\Exception\InvalidArgumentException
Set the fields and direction to order by .