/*
$order array of the fields and the order
307
public function selectAll($where=false, $order=false, $limit=false) {
        $clause = false;
        $values = array();
        if ( is_array($where) ) {
            $retval = self::extractWhere($where, $clause, $values);
            if ( is_string($retval) ) throw new \Exception($val);
        }
        $orderby = '';
        if ( is_string($order) ) {
            $orderby = self::extractOrder($order);
            if ( $orderby === false ) throw new \Exception('Invalid Order value');
        }

        $sql = "SELECT KVS.id AS id, json_body, KVS.created_at, KVS.updated_at
            FROM $this->KVS_TABLE AS KVS
            WHERE $this->KVS_FK_NAME = :foreign_key";
        if ( $clause ) $sql .= ' AND '.$clause;
        if ( $orderby ) $sql .= ' '.$orderby;
        $values[':foreign_key'] = $this->KVS_FK;
        $rows = $this->PDOX->allRowsDie($sql, $values);
        return $rows;
    }
351908
protected function sort()
    {
        $orderBy = $this->orderBy;
        $sortBy  = $this->sortBy;

        if ($orderBy=='')
            return false;
        usort($this->documents, function($a, $b) use ($orderBy, $sortBy) {
            $propA = $a->field($orderBy);
            $propB = $b->field($orderBy);
            if (strnatcasecmp($propB, $propA) == strnatcasecmp($propA, $propB)) {
                return 0;
            }
            if ($sortBy == 'DESC')
                return (strnatcasecmp($propB, $propA) < strnatcasecmp($propA, $propB)) ? -1 : 1;
            else
                return (strnatcasecmp($propA, $propB) < strnatcasecmp($propB, $propA)) ? -1 : 1;
        });
    }
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;
	}
1273286
public static function getOrder($sort, $allowField, $mapped = [], $defaultOrder = '')
    {
        $order = $defaultOrder;
        if ($sort) {
            $orders = [];
            $sortData = json_decode($sort, true);
            foreach ($sortData as $item) {
                if (!empty($item) && isset($item['property']) && isset($item['direction'])) {
                    $fieldName = $item['property'];
                    if (isset($mapped[$fieldName])) {
                        $fieldName = $mapped[$fieldName];
                    }
                    if (in_array($fieldName, $allowField)) {
                        $order = $fieldName;
                        if ('DESC' == $item['direction']) {
                            $order .= ' DESC';
                        } else {
                            $order .= ' ASC';
                        }
                        $orders[] = $order;
                    }
                }
            }
            if ($orders) {
                $order = join(',', $orders);
            }
        }

        return $order;
    }
1111687
protected function buildOrder()
    {
        $result = '';

        $orders = (array) $this->getOrder();
        foreach ($orders as $field => $direction) {
            if ($result != '') {
                $result.=',';
            }
            $result.=$field.' '.($direction === SORT_DESC ? 'DESC' : 'ASC');
        }
        if ($result != '') {
            $result = 'ORDER BY '.$result;
        }

        return $result;
    }
211760
private function getOrderNormalizer()
    {
        return function(Options $options, $order) {
            foreach ($order as $field => $sort) {
                if (!is_string($sort) || !is_string($field) || !in_array(strtolower($sort), ['asc', 'desc'])) {
                    throw new Exception(
                        'Order value should be an array of string (["field" => $key]), got '.gettype($sort)
                    );
                }
            }

            return $order;
        };
    }
25319
private function sortValues($values)
    {
        if (!($this->orderField && \is_array($this->{$this->orderField}))) {
            return $values;
        }
        /** @var array $orderValues */
        $orderValues = $this->{$this->orderField};
        $result      = [];
        foreach ($orderValues as $i) {
            if (isset($values[$i])) {
                $result[$i] = $values[$i];
                unset($values[$i]);
            }
        }
        if (!empty($values)) {
            foreach ($values as $k => $v) {
                $result[$k] = $v;
            }
        }
        return $result;
    }
1447
public function order($fields)
    {
        $data = $this->get();

        // prepare arguments for array_multisort()
        $args = [];
        foreach ($fields as list($field, $desc)) {
            $args[] = array_column($data, $field);
            $args[] = $desc ? SORT_DESC : SORT_ASC;
            //$args[] = SORT_STRING; // SORT_STRING | SORT_NUMERIC | SORT_REGULAR
        }
        $args[] = &$data;

        // call sorting
        call_user_func_array('array_multisort', $args);

        // put data back in generator
        $this->generator = new \ArrayIterator(array_pop($args));

        return $this;
    }
310443
function (sort) {
            var ret = {};
            sort = sort || [];
            for (var i = 0; i < sort.length; i++) {
                var sortElement = sort[i];
                ret[sortElement.field] = sortElement.direction;
            }
            return ret;
        }
1066165
function orderColumns() {
        var keyTotals = filenames.reduce(reduceFilenamesToKeyTotal, {});
        return sort(keyTotals);

        function reduceFilenamesToKeyTotal(reduced, filename) {
          var item = json[filename];
          return Object.keys(item)
            .reduce(reducePropToLength.bind(item), reduced);
        }
      }
1305031
public function order($field, $desc = false)
    {
        if(count($this->models) > 0) {
            $instance = $this->reflection->newInstance();
            $string = $instance->isString($field);
            usort($this->models, function ($a, $b) use ($field, $string) {
                if($string) {
                    return strcmp($a[$field], $b[$field]);
                }
                return $a[$field] - $b[$field];
            });
            if ($desc) {
                $this->models = array_reverse($this->models);
            }
        }
        return $this;
    }
592084
public function orderBy($fields = array())
		{
			foreach ($fields as $col => $val) {
				if ($val == -1 or $val === false or strtolower($val) == 'desc') {
					$this->sorts[$col] = -1;
				} else {
					$this->sorts[$col] = 1;
				}
			}

			return $this;
		}
1178959
function orderByParam(query) {
  const value = query[orderedBy];

  switch (value) {
  case orderByKey:
    return;

  case orderByValue:
    return '$value';

  case orderByPriority:
    return '$priority';

  default:
    return value;
  }
}
1365373
protected function order()
    {
        foreach ($this->orderBy as $orderBy) {
            if (count($orderBy) == 1) {
                $this->model = $this->model->orderBy($orderBy);
            }

            // field and direction
            if (count($orderBy) == 2) {
                $this->model = $this->model->orderBy($orderBy[0], $orderBy[1]);
            }
        }
    }
143785
def order(self, last):
        ''''''
        desc = last.desc
        field = last.name
        nested = last.nested
        nested_args = []
        while nested:
            meta = nested.model._meta
            nested_args.extend((self.backend.basekey(meta), nested.name))
            last = nested
            nested = nested.nested
        method = 'ALPHA' if last.field.internal_type == 'text' else ''
        if field == last.model._meta.pkname():
            field = ''
        return {'field': field,
                'method': method,
                'desc': desc,
                'nested': nested_args}
1282819
public function sortPrimaryKeys(array $order = null)
    {
        if (!$order) {
            ksort($this->values);

            return;
        }

        $orderedKeys = array_intersect_key(array_flip($order), $this->values);

        $this->values = array_replace($orderedKeys, $this->values);
    }
1036272
function orderObject (unordered) {
  const ordered = {}
  if (typeof unordered !== 'object' || unordered == null || Array.isArray(unordered)) return unordered
  Object.keys(unordered).sort().forEach(function (key) {
    ordered[key] = ((typeof unordered[key] === 'object') && !Array.isArray(unordered[key])) ? orderObject(unordered[key]) : unordered[key]
  })
  return ordered
}