mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 23:43:12 +00:00
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:
39
lib/Alchemy/Phrasea/Collection/CollectionHelper.php
Normal file
39
lib/Alchemy/Phrasea/Collection/CollectionHelper.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@@ -3,6 +3,7 @@
|
|||||||
namespace Alchemy\Phrasea\Twig;
|
namespace Alchemy\Phrasea\Twig;
|
||||||
|
|
||||||
use Alchemy\Phrasea\Application;
|
use Alchemy\Phrasea\Application;
|
||||||
|
use Alchemy\Phrasea\Collection\CollectionHelper;
|
||||||
use Alchemy\Phrasea\Model\Entities\ElasticsearchRecord;
|
use Alchemy\Phrasea\Model\Entities\ElasticsearchRecord;
|
||||||
use Alchemy\Phrasea\Model\Entities\User;
|
use Alchemy\Phrasea\Model\Entities\User;
|
||||||
use Alchemy\Phrasea\Model\RecordInterface;
|
use Alchemy\Phrasea\Model\RecordInterface;
|
||||||
@@ -22,6 +23,7 @@ class PhraseanetExtension extends \Twig_Extension
|
|||||||
public function getFilters()
|
public function getFilters()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
|
new \Twig_SimpleFilter('sort_collections', array(CollectionHelper::class, 'sort')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -166,7 +166,7 @@
|
|||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% 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
|
{% 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(['manage'])|keys
|
||||||
or collection.get_base_id() in app.getAclForUser(app.getAuthenticatedUser()).get_granted_base(['modify_struct'])|keys) %}
|
or collection.get_base_id() in app.getAclForUser(app.getAuthenticatedUser()).get_granted_base(['modify_struct'])|keys) %}
|
||||||
|
Reference in New Issue
Block a user