@param array  $databases
@param string $sort
@param bool   $reverseSort

@return array
427345
private function sort(array $tables, $sort, $reverseSort)
    {
        switch ($sort) {
            case 'name':
                ksort($tables);
                break;

            case 'size':
                uasort(
                    $tables,
                    function ($a, $b) {
                        return $a['size'] > $b['size'];
                    }
                );
                break;

            default:
                throw new Exception\DomainException("Invalid sort option \"$sort\".");
        }

        if ($reverseSort) {
            $tables = array_reverse($tables, true);
        }

        return $tables;
    }
1032412
public function getPath( $reverseSort = false, $mainTranslation = false )
    {
        $pathArray = explode( '/', trim( $this->attribute( 'path_string' ), '/' ) );

        if ( !is_array( $pathArray ) || empty( $pathArray ) || count( $pathArray ) == 1 )
            return array();

        $pathArray = array_slice( $pathArray, 0, count( $pathArray ) - 1 );

        return self::fetchList( array( 'id' => array( $pathArray ) ),
                                null,
                                array( 'path_string' => $reverseSort != false ? 'desc' : 'asc' ),
                                $mainTranslation );
    }
424493
protected function _sort(QueryBuilder $qb, array $sorts = [])
    {
        foreach ($sorts as $field => $direction) {
            $qb->addOrderBy('e.'.$field, $direction);
        }
        return $qb;
    }
24030
protected function _sortResult(array &$result, $sort = 'asort')
    {
        // Sorting
        switch ($sort) {
            case 'asort':
                asort($result);
                break;

            case 'ksort':
                ksort($result);
                break;

            case 'natsort':
                natsort($result);
                break;

            default:
                $sort($result);
        }
    }
1244553
private function applySortStateToResult(ResultInterface $results, $activeSortId)
    {
        $sort = $this->dbAdapter->getSortTypeFromId($activeSortId);
        $sortString = new SortString($sort->getSortString());
        $results->setSort($sortString->getAsArray());

        return $results;
    }
1080534
protected function callbackSortList($a, $b, array $query)
    {
        $arg1 = isset($a[$query['sort']]) ? (string) $a[$query['sort']] : '0';
        $arg2 = isset($b[$query['sort']]) ? (string) $b[$query['sort']] : '0';

        $diff = strnatcasecmp($arg1, $arg2);
        return $query['order'] === 'asc' ? $diff : -$diff;
    }
196563
public static function get_records($filters = array(), $sort = '', $order = 'ASC', $skip = 0, $limit = 0) {
        global $DB;

        $orderby = '';
        if (!empty($sort)) {
            $orderby = $sort . ' ' . $order;
        }

        $records = $DB->get_records(static::TABLE, $filters, $orderby, '*', $skip, $limit);
        $instances = array();

        foreach ($records as $record) {
            $newrecord = new static(0, $record);
            array_push($instances, $newrecord);
        }
        return $instances;
    }
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;
  }
935321
static public function lastOne($sort=null, $query=array())
    {
        if ($sort === null) {
          $sort = array(
            'ctm' => -1
          );
        }

        $config = Conf::f('storage-mongodb-object', array());
        $db = isset($config['databases']) ? $config['databases'] : 'default';
        $db = DB::get($db);
        $collection = $db->selectCollection(static::getCollectionName());

        $obj = $collection->findOne($query, array(
          'projection' => array('_id' => 1),
          'sort' => $sort,
        ));

        if ($obj === null) {
          return null;
        }

        return new static($obj);
    }
164621
public function makeSortable($db_field = null)
    {
        // reverse sorting
        $reverse = false;
        if ($db_field[0] == '-') {
            $reverse = true;
            $db_field = substr($db_field, 1);
        }

        // used db field
        if (!$db_field) {
            $db_field = $this->last_column;
        }

        switch ((string) $this->sortby) {

            // we are already sorting by this column
            case $db_field:
                $info = array('1', $reverse ? 0 : ('-'.$db_field));
                $this->sortby_db = $db_field;
                break;

            // We are sorted reverse by this column
            case '-'.$db_field:
                $info = array('2', $reverse ? $db_field : '0');
                $this->sortby_db = '-'.$db_field;
                break;

            // we are not sorted by this column
            default:
                $info = array('0', $reverse ? ('-'.$db_field) : $db_field);
        }

        $this->columns[$db_field]['sortable'] = $info;

        return $this;
    }
441116
public function sort(Sorting $sorting)
	{
		if (is_callable($sorting->getSortCallback())) {
			call_user_func(
				$sorting->getSortCallback(),
				$this->data_source,
				$sorting->getSort()
			);

			return $this;
		}

		$sort = $sorting->getSort();

		if (!empty($sort)) {
			$this->data_source->removeClause('ORDER BY');
			$this->data_source->orderBy($sort);
		} else {
			/**
			 * Has the statement already a order by clause?
			 */
			$this->data_source->clause('ORDER BY');

			if ($this->data_source instanceof Dibi\Fluent) {
				$reflection = new \ReflectionClass('Dibi\Fluent');
			} else {
				$reflection = new \ReflectionClass('DibiFluent');
			}

			$cursor_property = $reflection->getProperty('cursor');
			$cursor_property->setAccessible(true);
			$cursor = $cursor_property->getValue($this->data_source);

			if (!$cursor) {
				$this->data_source->orderBy($this->primary_key);
			}
		}

		return $this;
	}
856797
public function queryfetch($query, $returnarray=false) {
    list($result, $numrows) = $this->query($query, true);
    
    if($result === false) {
      throw new SqlException($query, $this);
    }

    while($row = $result->fetch(PDO::FETCH_ASSOC)) {
      $rows[] = $row;
    }
    return ($returnarray) ? array($rows, $numrows, result=>$rows, numrows=>$numrows) : $rows;
  }
350057
public static <T> void sortReverse(List<T> list, Comparator<? super T> c) {
		Collections.sort(list, Collections.reverseOrder(c));
	}
149756
protected function from_db_records(array $results) {
        $entityfactory = $this->get_entity_factory();

        return array_map(function(array $result) use ($entityfactory) {
            [
                'discussion' => $discussion,
                'firstpost' => $firstpost,
                'firstpostauthor' => $firstpostauthor,
                'latestpostauthor' => $latestpostauthor,
            ] = $result;
            return $entityfactory->get_discussion_summary_from_stdclass(
                $discussion,
                $firstpost,
                $firstpostauthor,
                $latestpostauthor
            );
        }, $results);
    }
562585
public static void sortReverse(double[] keys, int[] values, int start, int end) {
    quickSortReverse(keys, values, start, end);
  }
456871
public function reverse(int $break = 0):array
    {
        if (!is_array($this->file)) {
            throw new Server500(new \ArrayObject(array("explain" =>
                "Cannot reverse file ".$this->filepath." : is not a resource.",
                "solution" =>
                    "Use your own method to reverse the resource")));
        }
        return ((($break == 0)? array_reverse($this->file) : array_reverse(array_slice($this->file, -$break))));
    }
353617
private function arrayListToStringBuilder(ArrayList $arrayList, bool $reverse = false) {
        $stringBuilder = new StringBuilder();
        if ($reverse) {
            $stack = new Stack();
            foreach ($arrayList as $item) {
                if (null !== $item) {
                    $stack->push($item);
                }
            }
            while (!$stack->isEmpty()) {
                $stringBuilder->append($stack->pop());
            }
        } else {
            $queue = new Queue();
            foreach ($arrayList as $item) {
                if (null !== $item) {
                    $queue->enqueue($item);
                }

            }
            while (!$queue->isEmpty()) {
                $stringBuilder->append($queue->dequeue());
            }
        }
        return $stringBuilder;
    }