Merge pull request #1762 from bburnichon/bug/invalid-collection-order-PHRAS-917

Added new Twig filter to sort a collection set.
This commit is contained in:
Thibaud Fabre
2016-03-17 13:33:28 +01:00
3 changed files with 42 additions and 1 deletions

View File

@@ -0,0 +1,39 @@
<?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;
class CollectionHelper
{
private function __construct()
{
}
/**
* @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) {
return ($left->get_ord() < $right->get_ord()) ? -1 : (($left->get_ord() < $right->get_ord()) ? 1 : 0);
});
return $collections;
}
}

View File

@@ -3,6 +3,7 @@
namespace Alchemy\Phrasea\Twig;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Collection\CollectionHelper;
use Alchemy\Phrasea\Model\Entities\ElasticsearchRecord;
use Alchemy\Phrasea\Model\Entities\User;
use Alchemy\Phrasea\Model\RecordInterface;
@@ -22,6 +23,7 @@ class PhraseanetExtension extends \Twig_Extension
public function getFilters()
{
return array(
new \Twig_SimpleFilter('sort_collections', array(CollectionHelper::class, 'sort')),
);
}

View File

@@ -166,7 +166,7 @@
</li>
{% 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) %}