Sort
Specify order data should be returned in.

@param $sort_on column to sort on
@param $order Sort direction
@return Ref to self
174528
public function sort ($sort_on, $order = 'desc') {
		$queryString = '<FieldRef Name="'  .$sort_on . '" Ascending="' . $this->api->getSortFromValue($order) . '" />';
		$this->sort_caml = '<OrderBy>' . $queryString . '</OrderBy>';

		return $this;
	}
1371258
public function addSort($column, $order = self::ASC)
    {
        //argument test
        Argument::i()
            //Argument 1 must be a string
            ->test(1, 'string')
            //Argument 2 must be a string
            ->test(2, 'string');
        
        if ($order != self::DESC) {
            $order = self::ASC;
        }
        
        $this->sort[$column] = $order;
        
        return $this;
    }
108304
public function sortForumBy($sort_by_sql)
    {
        $sort_by_sql = Container::get('hooks')->fire('model.forum.sort_forum_by_start', $sort_by_sql);

        switch ($sort_by_sql) {
            case 0:
                $sort_by = 'last_post DESC';
                break;
            case 1:
                $sort_by = 'posted DESC';
                break;
            case 2:
                $sort_by = 'subject ASC';
                break;
            default:
                $sort_by = 'last_post DESC';
                break;
        }

        $sort_by = Container::get('hooks')->fire('model.forum.sort_forum_by', $sort_by);

        return $sort_by;
    }
780999
public function ksort(int $sort_flags = 0): self
    {
        $this->generatorToArray();

        \ksort($this->array, $sort_flags);

        return $this;
    }
704072
public function order_by( $cols, $order = 'asc' ) 
	{
		if ( !is_array( $cols ) ) 
		{
			$this->orders[] = array( $cols, $order ); return $this;
		}
		else
		{
			foreach( $cols as $key => $col ) 
			{
				if ( is_numeric( $key ) ) 
				{
					$this->orders[] = array( $col, $order );	
				} 
				else 
				{
					$this->orders[] = array( $key, $col );
				}
			}
		}
		
		return $this;
	}
120861
protected function sortByArray($array, $order)
    {
        $keys = array_keys($array);
        
        return array_merge(
            array_flip(
                array_intersect($order, $keys) +
                array_diff($keys, $order)
            ),
            $array
        );
    }
181569
protected function applySimpleSort(Sort $sort)
    {
        $this->query->orderBy($sort->getField(), $sort->getOrder());
    }
173308
public function addSort($column, $order = self::ASC)
    {
        if ($order != self::DESC) {
            $order = self::ASC;
        }

        $this->sort[$column] = $order;

        return $this;
    }
1042846
public function orderBy($order = null) {
		if (is_null($order)) //remove option
			return $this->discard('query.orderBy');
			
		return $this->merge(['query.orderBy' => func_get_args()]);
	}
967264
public function setOrderBy($sort, $direction = 'ASC')
    {
        $this->sort = $sort;
        $this->direction = $direction;
        return $this;
    }
370576
public function rsort(int $sort_flags = 0): self
    {
        $this->generatorToArray();

        \rsort($this->array, $sort_flags);

        return $this;
    }
816399
public function orderBy($column = '', $sort = 'desc')
    {
        $column=self::sanitize($column);
        $sort=strtoupper(self::sanitize($sort));

        /*check if the sort method passed is valid */
        if (!(hash_equals('DESC',$sort) || hash_equals('ASC',$sort))){
            static::$response["status"] = "error";
            static::$response["response"] = "The sort order in order by clause is invalid";
            static::$response['code'] = 6050;
            return static::terminate(static::$response);
        }

        if ($this->order == null) {
            $this->order = " ORDER BY $column $sort";
        } else {
            $this->order .= ", $column $sort";
        }
        return $this;
    }
1326470
public function setSort($sort)
    {
        $this->reordered = $this->sort !== $sort;
        $this->sort = $sort;

        return $this;
    }
924031
public function addSorting($sort, $order = SearchQuery::SORT_ASC)
    {
        $this->searchQuery->addSorting($sort, $order);

        return $this;
    }
750634
public function addOrderBy($sort, $order = null)
    {
        return $this->add('orderBy', $sort . ' ' . (! $order ? 'ASC' : $order), true);
    }
198242
protected function _addOrderBy($column_name, $ordering)
        {
            $column_name = $this->_quoteIdentifier($column_name);
            $this->_order_by[] = "{$column_name} {$ordering}";

            return $this;
        }
1262226
protected static function convertSort($sort)
  {
    /** @var RSort $convertedSort */
    $convertedSort = null;
    if (!empty($sort)) {
      $convertedSort = new RSort();
      $convertedSort->setField($sort->getField());
      switch ($sort->getOrder()) {
        case MSort\Order::Ascending:
          $convertedSort->setOrder(RSort\Order::Ascending);
          break;
        case MSort\Order::Descending:
          $convertedSort->setOrder(RSort\Order::Descending);
          break;
      }
    }
    return $convertedSort;
  }