Sort the items by an array of ids.

@param ArrayCollection $items
@param array           $order

@return array
769728
private function sortByArray($items, array $order)
    {
        $unordered = [];
        foreach ($items as $content) {
            $unordered[$content->getId()] = $content;
        }

        $ordered = [];
        foreach ($order as $id) {
            if (isset($unordered[$id])) {
                $ordered[] = $unordered[$id];
            }
        }

        return $ordered;
    }
1287373
protected function buildOrderJoin(string $order): array
    {
        list($column, $direction) = $this->formatOrderDirection($order);

        $lookupBuilder = $this->getLookupBuilder();

        $column = $lookupBuilder->fetchColumnName($column);
        $newOrder = $lookupBuilder->buildJoin($this, $column);
        if (false === $newOrder) {
            return [$column, $direction];
        }

        list($alias, $column) = $newOrder;

        return [
            $alias.'.'.$column,
            $direction,
        ];
    }
1210752
public function orderBy($columns, string $order = 'ASC')
	{
		$this->orderings[] =
		[
			'column' => is_array($columns) ? $columns : [$columns],
			'order'  => ($order === 'ASC' || $order === 'asc') ? 'ASC' : 'DESC',
		];

		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()]);
	}
29451
public function sort(array $ids, array $list)
    {
        $data = array();
        foreach ($ids as $key) {

            if (!isset($list[$key])) {
                return array();
            }

            $data[$key] = $list[$key]['sort'];
            foreach (array_keys($list[$key]['requires']) as $dependency) {
                if (!isset($data[$dependency])) {
                    $data[$dependency] = 0;
                }
            }
        }

        arsort($data);
        return array_keys($data);
    }
168118
public function order($items)
	{
		$this->order = [];

		if (!empty($items)) {
			$this->addOrder($items);
		}

		return $this;
	}
47144
protected function getOrderQuery( $orders = array() )
	{
		if( is_array( $orders ) && count( $orders ) )
		{
			$order = array();
			foreach( $orders as $key => $value )
				$order[] = $key.' '.$value;
			$orders = ' ORDER BY '.implode( ', ', $order );
		}
		else
			$orders = '';
		return $orders;
	}
996939
public function orderByMultiple($order = ['_position' => 'ASC', '_leftnode' => 'ASC'])
    {
        if (true === empty($order)) {
            $order = ['_position' => 'ASC', '_leftnode' => 'ASC'];
        }

        $this->resetDQLPart('orderBy');
        foreach ($order as $field => $sort) {
            $this->addOrderBy($field, $sort);
        }

        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
        );
    }
283683
public function sortByArrayKeys(array $orderBy)
    {
        $result = $this->target;

        if ($orderBy) {
            $ordered = [];

            foreach ($orderBy as $key) {
                if (array_key_exists($key, $result)) {
                    $ordered[$key] = $result[$key];
                    unset($result[$key]);
                }
            }

            $result = $ordered + $result;
        }

        return $result;
    }
1164194
public static function sortDocumentsByField($documents, $field, $order = 'ASC')
    {
        self::$orderByField = $field;
        self::$order = strtoupper($order) === 'ASC' ? 'ASC' : 'DESC';
        usort($documents, '\CloudControl\Cms\util\DocumentSorter::fieldCompare');
        if ($order === 'DESC') {
            return array_reverse($documents);
        }
        return $documents;
    }
278104
public static function order($items) {
		if (empty($items)) {
			return array();
		}

		$_items = array_combine(array_keys($items), Hash::extract($items, '{s}.weight'));
		asort($_items);

		foreach (array_keys($_items) as $key) {
			$_items[$key] = $items[$key];
		}

		return $items;
	}
158475
public function sortByArrayValues(array $orderBy)
    {
        if (!$orderBy) {
            return $this->target;
        }

        $result = [];

        foreach ($orderBy as $value) {
            if ($keys = array_keys($this->target, $value)) {
                foreach ($keys as $key) {
                    $result[$key] = $value;
                }
            }
        }

        return $result;
    }
1014189
public function andSort(Sort $sort = null) : Sort
    {
        if ($sort === null) {
            return $this;
        }
        $orders = $this->orders;
        foreach ($sort as $order) {
            $orders[] = $order;
        }
        return new Sort($orders);
    }
685056
public function order_by($criteria, $order = 'ASC')
    {
        if ( is_array($criteria) )
        {
            foreach ($criteria as $key => $value)
            {
                $this->_database->order_by($key, $value);
            }
        }
        else
        {
            $this->_database->order_by($criteria, $order);
        }
        return $this;
    }
974389
protected function sort($items, $type = self::TYPE_BOTH, $by = self::KEY_NAME, $direction = self::ASC)
    {
        $returnArray = array();
        if (count($items) > 0) {
            $tmpArray = array();
            foreach($items as $key => $value) {
                $tmpArray[$key] = $value[$by];
            }

            natcasesort($tmpArray);

            if ($direction == self::DESC) {
                $tmpArray = array_reverse($tmpArray, true);
            }

            foreach($tmpArray as $key => $value) {
                $returnArray[] = $items[$key];
            }

            // If sorting by name, lets seperate the files from the dirs.
            if ($by == self::KEY_NAME && $type == self::TYPE_BOTH) {
                $files = array();
                $dirs  = array();

                foreach ($returnArray as $value) {
                    if ($value[self::KEY_TYPE] == self::TYPE_FILE) {
                        $files[] = $value;
                    } elseif ($value[self::KEY_TYPE] == self::TYPE_DIR) {
                        $dirs[] = $value;
                    }
                }

                if ($direction == self::DESC) {
                    $returnArray = array_merge($files, $dirs);
                } else {
                    $returnArray = array_merge($dirs, $files);
                }
            }
        }
        return $returnArray;
    }
653009
public function sortCategories(array $items)
    {
        $repository = $this->getRepository();
        $em         = $this->getDoctrineHelper()->getEntityManager();

        foreach ($items as $item) {
            $parent = $repository->find($item['parent']);
            $child  = $repository->find($item['id']);
            if (null !== $child) {
                $child->setParent($parent);
                $child->setHierarchy($item['weight']);
                $em->persist($child);
            }
        }

        $em->flush();
    }