Fix #1300 : Story editing does not work

This commit is contained in:
Romain Neutron
2013-07-11 16:17:49 +02:00
parent abf76e2643
commit 867be69b74
5 changed files with 44 additions and 13 deletions

View File

@@ -38,7 +38,7 @@ class Edit implements ControllerProviderInterface
$controllers->post('/', function(Application $app, Request $request) {
$records = RecordsRequest::fromRequest($app, $request, true, array('canmodifrecord'));
$records = RecordsRequest::fromRequest($app, $request, RecordsRequest::FLATTEN_YES_PRESERVE_STORIES, array('canmodifrecord'));
$thesaurus = $multipleDataboxes = false;
$status = $ids = $elements = $suggValues =

View File

@@ -19,11 +19,16 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class RecordsRequest extends ArrayCollection
{
protected $isSingleStory = false;
protected $received;
protected $basket;
protected $databoxes;
protected $collections;
const FLATTEN_NO = false;
const FLATTEN_YES = true;
const FLATTEN_YES_PRESERVE_STORIES = 'preserve';
/**
* Constructor
*
@@ -32,17 +37,20 @@ class RecordsRequest extends ArrayCollection
* @param Basket $basket
* @param Boolean $flatten
*/
public function __construct(array $elements, ArrayCollection $received, Basket $basket = null, $flatten = false)
public function __construct(array $elements, ArrayCollection $received, Basket $basket = null, $flatten = self::FLATTEN_NO)
{
parent::__construct($elements);
$this->received = $received;
$this->basket = $basket;
$this->isSingleStory = ($flatten !== self::FLATTEN_YES && 1 === count($this) && $this->first()->is_grouping());
if ($flatten) {
if (self::FLATTEN_NO !== $flatten) {
$to_remove = array();
foreach ($this as $key => $record) {
if ($record->is_grouping()) {
$to_remove[] = $key;
if (self::FLATTEN_YES === $flatten) {
$to_remove[] = $key;
}
foreach ($record->get_children() as $child) {
$this->set($child->get_serialize_key(), $child);
}
@@ -140,13 +148,7 @@ class RecordsRequest extends ArrayCollection
*/
public function isSingleStory()
{
if ($this->count() === 1) {
if ($this->first()->is_grouping()) {
return true;
}
}
return false;
return $this->isSingleStory;
}
/**
@@ -192,7 +194,7 @@ class RecordsRequest extends ArrayCollection
* @param array $rightsDatabox
* @return RecordsRequest
*/
public static function fromRequest(Application $app, Request $request, $flattenStories = false, array $rightsColl = array(), array $rightsDatabox = array())
public static function fromRequest(Application $app, Request $request, $flattenStories = self::FLATTEN_NO, array $rightsColl = array(), array $rightsDatabox = array())
{
$elements = $received = array();
$basket = null;

View File

@@ -139,7 +139,7 @@
</div>
</div>
<div id="EDIT_FILM2" style="left:170px;">
{{_self.HTML_Train(edit, '1')}}
{{_self.HTML_Train(recordsRequest, '1')}}
</div>
{% else %}
<div id="EDIT_FILM2" class='ui-corner-all'>

View File

@@ -18,6 +18,15 @@ class ControllerEditTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$this->assertTrue($response->isOk());
}
public function testRouteSlashWithStory()
{
self::$DI['client']->request('POST', '/prod/records/edit/', array('lst' => self::$DI['record_story_1']->get_serialize_key()));
$response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk());
}
public function testApply()
{
self::$DI['client']->request('POST', '/prod/records/edit/apply/', array('lst' => self::$DI['record_1']->get_serialize_key()));

View File

@@ -260,6 +260,26 @@ class RecordsRequestTest extends \PhraseanetPHPUnitAuthenticatedAbstract
$this->assertNotContains($story->getRecord(self::$DI['app'])->get_serialize_key(), $exploded);
}
public function testSimpleStoryFlattenAndPreserve()
{
$story = $this->getStoryWZ();
$request = new Request(array('story' => $story->getId()));
$records = RecordsRequest::fromRequest(self::$DI['app'], $request, RecordsRequest::FLATTEN_YES_PRESERVE_STORIES);
$this->assertEquals(1, count($records));
$this->assertEquals(1, count($records->received()));
$this->assertEquals(1, count($records->stories()));
$this->assertInstanceOf('\record_adapter', $records->singleStory());
$this->assertTrue($records->isSingleStory());
$this->assertCount(1, $records->databoxes());
$serialized = $records->serializedList();
$exploded = explode(';', $serialized);
$this->assertEquals($story->getRecord(self::$DI['app'])->get_serialize_key(), $serialized);
}
protected function getStoryWZ()
{
$story = new \Entities\StoryWZ();