diff --git a/lib/Alchemy/Phrasea/Twig/PhraseanetExtension.php b/lib/Alchemy/Phrasea/Twig/PhraseanetExtension.php index 56c7040c7d..aa1842ac7f 100644 --- a/lib/Alchemy/Phrasea/Twig/PhraseanetExtension.php +++ b/lib/Alchemy/Phrasea/Twig/PhraseanetExtension.php @@ -8,6 +8,7 @@ use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Model\RecordInterface; use Alchemy\Phrasea\Http\StaticFile\StaticMode; use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Flag; +use Assert\Assertion; class PhraseanetExtension extends \Twig_Extension { @@ -22,6 +23,7 @@ class PhraseanetExtension extends \Twig_Extension public function getFilters() { return array( + new \Twig_SimpleFilter('sort_collections', array($this, 'sortCollections')), ); } @@ -305,6 +307,25 @@ class PhraseanetExtension extends \Twig_Extension return $this->app['border-manager']->getCheckerFromFQCN($checkerFQCN); } + /** + * @param \collection[] $collections + * @return \collection[] + */ + public function sortCollections($collections) + { + Assertion::allIsInstanceOf($collections, 'collection'); + + if ($collections instanceof \Traversable) { + $collections = iterator_to_array($collections); + } + + usort($collections, function (\collection $left, \collection $right) { + return ($left->get_ord() < $right->get_ord()) ? -1 : (($left->get_ord() < $right->get_ord()) ? 1 : 0); + }); + + return $collections; + } + public function getName() { return 'phraseanet'; diff --git a/templates/web/admin/tree.html.twig b/templates/web/admin/tree.html.twig index a682e7eb36..259ec05c4c 100644 --- a/templates/web/admin/tree.html.twig +++ b/templates/web/admin/tree.html.twig @@ -166,7 +166,7 @@ {% endif %} - {% for collection in databox.get_collections() %} + {% for collection in databox.get_collections()|sort_collections %} {% if (collection.get_base_id() in app.getAclForUser(app.getAuthenticatedUser()).get_granted_base(['canadmin'])|keys or collection.get_base_id() in app.getAclForUser(app.getAuthenticatedUser()).get_granted_base(['manage'])|keys or collection.get_base_id() in app.getAclForUser(app.getAuthenticatedUser()).get_granted_base(['modify_struct'])|keys) %}