src/Budkit/Datastore/Activerecord.php
final public function orderBy($orderby, $direction = '')
    {
        if (strtolower($direction) == 'random') {
            $orderby = ''; // Random results want or don't need a field name
            $direction = $this->_randomKeyword;
        } elseif (trim($direction) != '') {
            $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' ' . $direction : ' ASC';
        }


        if (strpos($orderby, ',') !== FALSE) {
            $temp = array();
            foreach (explode(',', $orderby) as $part) {
                $part = trim($part);
                if (!in_array($part, $this->arrayAliasedTables)) {
                    $part = $this->identifiers(trim($part));
                }
                $temp[] = $part;
            }

            $orderby = implode(', ', $temp);
        } else if ($direction != $this->_randomKeyword) {
            $orderby = $this->identifiers($orderby);
        }

        $orderbyStatement = $orderby . $direction;

        $this->arrayOrderBy[] = $orderbyStatement;
        if ($this->arrayCaching === TRUE) {
            $this->arrayCacheOrderBy[] = $orderbyStatement;
            $this->arrayCacheExists[] = 'orderby';
        }

        return $this;
    }
final public function orderBy($orderby, $direction = '')
    {
        if (strtolower($direction) == 'random') {
            $orderby = ''; // Random results want or don't need a field name
            $direction = $this->_randomKeyword;
        } elseif (trim($direction) != '') {
            $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' ' . $direction : ' ASC';
        }


        if (strpos($orderby, ',') !== FALSE) {
            $temp = array();
            foreach (explode(',', $orderby) as $part) {
                $part = trim($part);
                if (!in_array($part, $this->arrayAliasedTables)) {
                    $part = $this->identifiers(trim($part));
                }
                $temp[] = $part;
            }

            $orderby = implode(', ', $temp);
        } else if ($direction != $this->_randomKeyword) {
            $orderby = $this->identifiers($orderby);
        }

        $orderbyStatement = $orderby . $direction;

        $this->arrayOrderBy[] = $orderbyStatement;
        if ($this->arrayCaching === TRUE) {
            $this->arrayCacheOrderBy[] = $orderbyStatement;
            $this->arrayCacheExists[] = 'orderby';
        }

        return $this;
    }
final public function orderBy ( $ orderby , $ direction = '' ) { if ( strtolower ( $ direction ) == 'random' ) { $ orderby = '' ; // Random results want or don't need a field name $ direction = $ this -> _randomKeyword ; } elseif ( trim ( $ direction ) != '' ) { $ direction = ( in_array ( strtoupper ( trim ( $ direction ) ) , array ( 'ASC' , 'DESC' ) , TRUE ) ) ? ' ' . $ direction : ' ASC' ; } if ( strpos ( $ orderby , ',' ) !== FALSE ) { $ temp = array ( ) ; foreach ( explode ( ',' , $ orderby ) as $ part ) { $ part = trim ( $ part ) ; if ( ! in_array ( $ part , $ this -> arrayAliasedTables ) ) { $ part = $ this -> identifiers ( trim ( $ part ) ) ; } $ temp [ ] = $ part ; } $ orderby = implode ( ', ' , $ temp ) ; } else if ( $ direction != $ this -> _randomKeyword ) { $ orderby = $ this -> identifiers ( $ orderby ) ; } $ orderbyStatement = $ orderby . $ direction ; $ this -> arrayOrderBy [ ] = $ orderbyStatement ; if ( $ this -> arrayCaching === TRUE ) { $ this -> arrayCacheOrderBy [ ] = $ orderbyStatement ; $ this -> arrayCacheExists [ ] = 'orderby' ; } return $ this ; }
Adds the ORDER BY clause to the query statement

@param string $orderby
@param string $direction
@return ActiveRecord
Adds the ORDER BY clause to the query statement