Merge branch '4.0'

This commit is contained in:
Benoît Burnichon
2016-03-22 17:45:18 +01:00
5 changed files with 43 additions and 28 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

@@ -104,7 +104,7 @@ class RecordsRequest extends ArrayCollection
/** @var \record_adapter $record */ /** @var \record_adapter $record */
foreach ($this as $record) { foreach ($this as $record) {
if (! isset($this->collections[$record->getBaseId()])) { if (! isset($this->collections[$record->getBaseId()])) {
$this->collections[$record->getBaseId()] = $record->getCollection(); $this->collections[$record->getBaseId()] = $record->get_collection();
} }
} }

View File

@@ -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')),
); );
} }

View File

@@ -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) %}

View File

@@ -16,11 +16,6 @@ use Alchemy\Phrasea\Model\Entities\OrderElement;
*/ */
class OrderTest extends \PhraseanetAuthenticatedWebTestCase class OrderTest extends \PhraseanetAuthenticatedWebTestCase
{ {
/**
* @covers Alchemy\Phrasea\Controller\Prod\Order::createOrder
* @covers Alchemy\Phrasea\Controller\Prod\Order::connect
* @covers Alchemy\Phrasea\Controller\Prod\Order::call
*/
public function testCreateOrder() public function testCreateOrder()
{ {
$app = $this->getApplication(); $app = $this->getApplication();
@@ -46,9 +41,6 @@ class OrderTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertTrue($triggered, 'Creation listener should have been triggered'); $this->assertTrue($triggered, 'Creation listener should have been triggered');
} }
/**
* @covers Alchemy\Phrasea\Controller\Prod\Order::createOrder
*/
public function testCreateOrderJson() public function testCreateOrderJson()
{ {
$app = $this->getApplication(); $app = $this->getApplication();
@@ -76,9 +68,6 @@ class OrderTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertTrue($content->success, 'Success attribute of response content should be true'); $this->assertTrue($content->success, 'Success attribute of response content should be true');
} }
/**
* @covers Alchemy\Phrasea\Controller\Prod\Order::displayOrders
*/
public function testDisplayOrders() public function testDisplayOrders()
{ {
$this->XMLHTTPRequest('POST', '/prod/order/', [ $this->XMLHTTPRequest('POST', '/prod/order/', [
@@ -91,9 +80,6 @@ class OrderTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
} }
/**
* @covers Alchemy\Phrasea\Controller\Prod\Order::displayOneOrder
*/
public function testDisplayOneOrder() public function testDisplayOneOrder()
{ {
$order = $this->createOneOrder('I need this pictures'); $order = $this->createOneOrder('I need this pictures');
@@ -102,9 +88,6 @@ class OrderTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertTrue($client->getResponse()->isOk()); $this->assertTrue($client->getResponse()->isOk());
} }
/**
* @covers Alchemy\Phrasea\Controller\Prod\Order::sendOrder
*/
public function testSendOrder() public function testSendOrder()
{ {
$order = $this->createOneOrder('I need this pictures'); $order = $this->createOneOrder('I need this pictures');
@@ -123,9 +106,6 @@ class OrderTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertTrue(strpos($url['query'], 'success=1') === 0, 'Validation of elements is not successful'); $this->assertTrue(strpos($url['query'], 'success=1') === 0, 'Validation of elements is not successful');
} }
/**
* @covers Alchemy\Phrasea\Controller\Prod\Order::sendOrder
*/
public function testSendOrderJson() public function testSendOrderJson()
{ {
$order = $this->createOneOrder('I need this pictures'); $order = $this->createOneOrder('I need this pictures');
@@ -148,9 +128,6 @@ class OrderTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertObjectHasAttribute('order_id', $content, $response->getContent()); $this->assertObjectHasAttribute('order_id', $content, $response->getContent());
} }
/**
* @covers Alchemy\Phrasea\Controller\Prod\Order::denyOrder
*/
public function testDenyOrder() public function testDenyOrder()
{ {
$order = $this->createOneOrder('I need this pictures'); $order = $this->createOneOrder('I need this pictures');
@@ -171,9 +148,6 @@ class OrderTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertTrue( ! ! $var['success']); $this->assertTrue( ! ! $var['success']);
} }
/**
* @covers Alchemy\Phrasea\Controller\Prod\Order::denyOrder
*/
public function testDenyOrderJson() public function testDenyOrderJson()
{ {
$order = $this->createOneOrder('I need this pictures'); $order = $this->createOneOrder('I need this pictures');