Files
Phraseanet/lib/Alchemy/Phrasea/Collection/CollectionHelper.php
Benoît Burnichon 25222234f8 Issue in CollectionHelper ordering.
Also make helper class final.
2016-03-23 11:32:47 +01:00

40 lines
927 B
PHP

<?php
/**
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Collection;
use Assert\Assertion;
final class CollectionHelper
{
/**
* @param \collection[] $collections
* @return \collection[]
*/
public static function sort($collections)
{
Assertion::allIsInstanceOf($collections, \collection::class);
if ($collections instanceof \Traversable) {
$collections = iterator_to_array($collections);
}
usort($collections, function (\collection $left, \collection $right) {
if ($left->get_ord() === $right->get_ord()) {
return 0;
}
return $left->get_ord() < $right->get_ord() ? -1 : 1;
});
return $collections;
}
}