mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-24 10:23:17 +00:00
Added new Twig filter to sort a collection set.
Only currently used in admin/tree.html.twig but could be used in collection rights.
This commit is contained in:
@@ -8,6 +8,7 @@ use Alchemy\Phrasea\Model\Entities\User;
|
|||||||
use Alchemy\Phrasea\Model\RecordInterface;
|
use Alchemy\Phrasea\Model\RecordInterface;
|
||||||
use Alchemy\Phrasea\Http\StaticFile\StaticMode;
|
use Alchemy\Phrasea\Http\StaticFile\StaticMode;
|
||||||
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Flag;
|
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Flag;
|
||||||
|
use Assert\Assertion;
|
||||||
|
|
||||||
class PhraseanetExtension extends \Twig_Extension
|
class PhraseanetExtension extends \Twig_Extension
|
||||||
{
|
{
|
||||||
@@ -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($this, 'sortCollections')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,6 +307,25 @@ class PhraseanetExtension extends \Twig_Extension
|
|||||||
return $this->app['border-manager']->getCheckerFromFQCN($checkerFQCN);
|
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()
|
public function getName()
|
||||||
{
|
{
|
||||||
return 'phraseanet';
|
return 'phraseanet';
|
||||||
|
|||||||
@@ -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