mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
api stories add cover source
This commit is contained in:
@@ -2588,8 +2588,18 @@ class V1Controller extends Controller
|
|||||||
foreach ($recordsData as $data) {
|
foreach ($recordsData as $data) {
|
||||||
$records[] = $this->addOrDelStoryRecord($story, $data, $action);
|
$records[] = $this->addOrDelStoryRecord($story, $data, $action);
|
||||||
if($action === 'ADD' && !$cover_set && isset($data->{'use_as_cover'}) && $data->{'use_as_cover'} === true) {
|
if($action === 'ADD' && !$cover_set && isset($data->{'use_as_cover'}) && $data->{'use_as_cover'} === true) {
|
||||||
|
$coverSource = [];
|
||||||
|
|
||||||
|
if (isset($data->{'thumbnail_cover_source'})) {
|
||||||
|
$coverSource['thumbnail_cover_source'] = $data->{'thumbnail_cover_source'};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($data->{'preview_cover_source'})) {
|
||||||
|
$coverSource['preview_cover_source'] = $data->{'preview_cover_source'};
|
||||||
|
}
|
||||||
|
|
||||||
// because we can try many records as cover source, we let it fail
|
// because we can try many records as cover source, we let it fail
|
||||||
$cover_set = ($this->setStoryCover($story, $data->{'record_id'}, true) !== false);
|
$cover_set = ($this->setStoryCover($story, $data->{'record_id'}, true, $coverSource) !== false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2643,14 +2653,26 @@ class V1Controller extends Controller
|
|||||||
|
|
||||||
$story = new \record_adapter($this->app, $databox_id, $story_id);
|
$story = new \record_adapter($this->app, $databox_id, $story_id);
|
||||||
|
|
||||||
|
$coverSource = [];
|
||||||
|
|
||||||
|
if (isset($data->{'thumbnail_cover_source'})) {
|
||||||
|
$coverSource['thumbnail_cover_source'] = $data->{'thumbnail_cover_source'};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($data->{'preview_cover_source'})) {
|
||||||
|
$coverSource['preview_cover_source'] = $data->{'preview_cover_source'};
|
||||||
|
}
|
||||||
|
|
||||||
// we do NOT let "setStoryCover()" fail : pass false as last arg
|
// we do NOT let "setStoryCover()" fail : pass false as last arg
|
||||||
$record_key = $this->setStoryCover($story, $data->{'record_id'}, false);
|
$record_key = $this->setStoryCover($story, $data->{'record_id'}, false, $coverSource);
|
||||||
|
|
||||||
return Result::create($request, array($record_key))->createResponse();
|
return Result::create($request, array($record_key))->createResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setStoryCover(\record_adapter $story, $record_id, $can_fail=false)
|
protected function setStoryCover(\record_adapter $story, $record_id, $can_fail=false, $coverSource = [])
|
||||||
{
|
{
|
||||||
|
$coverSource = array_merge(['thumbnail_cover_source' => 'thumbnail', 'preview_cover_source' => 'preview'], $coverSource);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$record = new \record_adapter($this->app, $story->getDataboxId(), $record_id);
|
$record = new \record_adapter($this->app, $story->getDataboxId(), $record_id);
|
||||||
} catch (\Exception_Record_AdapterNotFound $e) {
|
} catch (\Exception_Record_AdapterNotFound $e) {
|
||||||
@@ -2671,9 +2693,12 @@ class V1Controller extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($record->get_subdefs() as $name => $value) {
|
foreach ($record->get_subdefs() as $name => $value) {
|
||||||
if (!in_array($name, array('thumbnail', 'preview'))) {
|
if (!($key = array_search($name, $coverSource))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$name = ($key == 'thumbnail_cover_source') ? 'thumbnail': 'preview';
|
||||||
|
|
||||||
$media = $this->app->getMediaFromUri($value->getRealPath());
|
$media = $this->app->getMediaFromUri($value->getRealPath());
|
||||||
$this->getSubdefSubstituer()->substituteSubdef($story, $name, $media); // name = thumbnail | preview
|
$this->getSubdefSubstituer()->substituteSubdef($story, $name, $media); // name = thumbnail | preview
|
||||||
$this->getDataboxLogger($story->getDatabox())->log(
|
$this->getDataboxLogger($story->getDatabox())->log(
|
||||||
|
Reference in New Issue
Block a user