mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-16 22:43:19 +00:00
Merge branch '4.0'
This commit is contained in:
@@ -1186,30 +1186,12 @@ class V1Controller extends Controller
|
|||||||
];
|
];
|
||||||
|
|
||||||
if ($request->attributes->get('_extended', false)) {
|
if ($request->attributes->get('_extended', false)) {
|
||||||
$subdefs = $caption = [];
|
$data = array_merge($data, [
|
||||||
|
'subdefs' => $this->listRecordEmbeddableMedias($request, $record),
|
||||||
foreach ($record->get_embedable_medias([], []) as $name => $media) {
|
'metadata' => $this->listRecordMetadata($record),
|
||||||
if (null !== $subdef = $this->listEmbeddableMedia($request, $record, $media)) {
|
'status' => $this->listRecordStatus($record),
|
||||||
$subdefs[] = $subdef;
|
'caption' => $this->listRecordCaption($record),
|
||||||
}
|
]);
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($record->get_caption()->get_fields() as $field) {
|
|
||||||
$caption[] = [
|
|
||||||
'meta_structure_id' => $field->get_meta_struct_id(),
|
|
||||||
'name' => $field->get_name(),
|
|
||||||
'value' => $field->get_serialized_values(';'),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$extendedData = [
|
|
||||||
'subdefs' => $subdefs,
|
|
||||||
'metadata' => $this->listRecordCaption($record->get_caption()),
|
|
||||||
'status' => $this->listRecordStatus($record),
|
|
||||||
'caption' => $caption
|
|
||||||
];
|
|
||||||
|
|
||||||
$data = array_merge($data, $extendedData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
@@ -1314,53 +1296,59 @@ class V1Controller extends Controller
|
|||||||
public function getRecordMetadataAction(Request $request, $databox_id, $record_id)
|
public function getRecordMetadataAction(Request $request, $databox_id, $record_id)
|
||||||
{
|
{
|
||||||
$record = $this->findDataboxById($databox_id)->get_record($record_id);
|
$record = $this->findDataboxById($databox_id)->get_record($record_id);
|
||||||
$ret = ["record_metadatas" => $this->listRecordCaption($record->get_caption())];
|
$ret = ["record_metadatas" => $this->listRecordMetadata($record)];
|
||||||
|
|
||||||
return Result::create($request, $ret)->createResponse();
|
return Result::create($request, $ret)->createResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List all fields about a specified caption
|
* List all fields of given record
|
||||||
*
|
|
||||||
* @param \caption_record $caption
|
|
||||||
*
|
*
|
||||||
|
* @param \record_adapter $record
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function listRecordCaption(\caption_record $caption)
|
private function listRecordMetadata(\record_adapter $record)
|
||||||
|
{
|
||||||
|
$includeBusiness = $this->getAclForUser()->can_see_business_fields($record->getDatabox());
|
||||||
|
|
||||||
|
return $this->listRecordCaptionFields($record->get_caption()->get_fields(null, $includeBusiness));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \caption_field[] $fields
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function listRecordCaptionFields($fields)
|
||||||
{
|
{
|
||||||
$ret = [];
|
$ret = [];
|
||||||
foreach ($caption->get_fields() as $field) {
|
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
$databox_field = $field->get_databox_field();
|
||||||
|
|
||||||
|
$fieldData = [
|
||||||
|
'meta_structure_id' => $field->get_meta_struct_id(),
|
||||||
|
'name' => $field->get_name(),
|
||||||
|
'labels' => [
|
||||||
|
'fr' => $databox_field->get_label('fr'),
|
||||||
|
'en' => $databox_field->get_label('en'),
|
||||||
|
'de' => $databox_field->get_label('de'),
|
||||||
|
'nl' => $databox_field->get_label('nl'),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
foreach ($field->get_values() as $value) {
|
foreach ($field->get_values() as $value) {
|
||||||
$ret[] = $this->listRecordCaptionField($value, $field);
|
$data = [
|
||||||
|
'meta_id' => $value->getId(),
|
||||||
|
'value' => $value->getValue(),
|
||||||
|
];
|
||||||
|
|
||||||
|
$ret[] = $fieldData + $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve information about a caption field
|
|
||||||
*
|
|
||||||
* @param \caption_Field_Value $value
|
|
||||||
* @param \caption_field $field
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function listRecordCaptionField(\caption_Field_Value $value, \caption_field $field)
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'meta_id' => $value->getId(),
|
|
||||||
'meta_structure_id' => $field->get_meta_struct_id(),
|
|
||||||
'name' => $field->get_name(),
|
|
||||||
'labels' => [
|
|
||||||
'fr' => $field->get_databox_field()->get_label('fr'),
|
|
||||||
'en' => $field->get_databox_field()->get_label('en'),
|
|
||||||
'de' => $field->get_databox_field()->get_label('de'),
|
|
||||||
'nl' => $field->get_databox_field()->get_label('nl'),
|
|
||||||
],
|
|
||||||
'value' => $value->getValue(),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a Response containing the record status
|
* Get a Response containing the record status
|
||||||
*
|
*
|
||||||
@@ -1524,7 +1512,7 @@ class V1Controller extends Controller
|
|||||||
$record->set_metadatas($metadata);
|
$record->set_metadatas($metadata);
|
||||||
|
|
||||||
return Result::create($request, [
|
return Result::create($request, [
|
||||||
"record_metadatas" => $this->listRecordCaption($record->get_caption()),
|
"record_metadatas" => $this->listRecordMetadata($record),
|
||||||
])->createResponse();
|
])->createResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2572,4 +2560,43 @@ class V1Controller extends Controller
|
|||||||
{
|
{
|
||||||
return $this->app['subdef.substituer'];
|
return $this->app['subdef.substituer'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
* @param \record_adapter $record
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function listRecordEmbeddableMedias(Request $request, \record_adapter $record)
|
||||||
|
{
|
||||||
|
$subdefs = [];
|
||||||
|
|
||||||
|
foreach ($record->get_embedable_medias([], []) as $name => $media) {
|
||||||
|
if (null !== $subdef = $this->listEmbeddableMedia($request, $record, $media)) {
|
||||||
|
$subdefs[] = $subdef;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $subdefs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \record_adapter $record
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function listRecordCaption(\record_adapter $record)
|
||||||
|
{
|
||||||
|
$includeBusiness = $this->getAclForUser()->can_see_business_fields($record->getDatabox());
|
||||||
|
|
||||||
|
$caption = [];
|
||||||
|
|
||||||
|
foreach ($record->get_caption()->get_fields(null, $includeBusiness) as $field) {
|
||||||
|
$caption[] = [
|
||||||
|
'meta_structure_id' => $field->get_meta_struct_id(),
|
||||||
|
'name' => $field->get_name(),
|
||||||
|
'value' => $field->get_serialized_values(';'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $caption;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,6 +15,8 @@ use Assert\Assertion;
|
|||||||
|
|
||||||
class RecordReferenceCollection implements \IteratorAggregate
|
class RecordReferenceCollection implements \IteratorAggregate
|
||||||
{
|
{
|
||||||
|
private $groups;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<int|string,array> $records
|
* @param array<int|string,array> $records
|
||||||
* @return RecordReferenceCollection
|
* @return RecordReferenceCollection
|
||||||
@@ -48,7 +50,7 @@ class RecordReferenceCollection implements \IteratorAggregate
|
|||||||
{
|
{
|
||||||
Assertion::allIsInstanceOf($references, RecordReferenceInterface::class);
|
Assertion::allIsInstanceOf($references, RecordReferenceInterface::class);
|
||||||
|
|
||||||
$this->references = $references;
|
$this->references = $references instanceof \Traversable ? iterator_to_array($references) : $references;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getIterator()
|
public function getIterator()
|
||||||
@@ -61,19 +63,29 @@ class RecordReferenceCollection implements \IteratorAggregate
|
|||||||
*/
|
*/
|
||||||
public function groupPerDataboxId()
|
public function groupPerDataboxId()
|
||||||
{
|
{
|
||||||
$groups = [];
|
if (null === $this->groups) {
|
||||||
|
$this->groups = [];
|
||||||
|
|
||||||
foreach ($this->references as $index => $reference) {
|
foreach ($this->references as $index => $reference) {
|
||||||
$databoxId = $reference->getDataboxId();
|
$databoxId = $reference->getDataboxId();
|
||||||
|
|
||||||
if (!isset($groups[$databoxId])) {
|
if (!isset($this->groups[$databoxId])) {
|
||||||
$groups[$databoxId] = [];
|
$this->groups[$databoxId] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->groups[$databoxId][$reference->getRecordId()] = $index;
|
||||||
}
|
}
|
||||||
|
|
||||||
$groups[$databoxId][$reference->getRecordId()] = $index;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $groups;
|
return $this->groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getDataboxIds()
|
||||||
|
{
|
||||||
|
return array_keys($this->groupPerDataboxId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -17,20 +17,17 @@ use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
|
|||||||
class caption_record implements caption_interface, cache_cacheableInterface
|
class caption_record implements caption_interface, cache_cacheableInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $fields;
|
protected $fields;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
protected $sbas_id;
|
protected $sbas_id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @var record_adapter
|
||||||
* @var record
|
|
||||||
*/
|
*/
|
||||||
protected $record;
|
protected $record;
|
||||||
protected $databox;
|
protected $databox;
|
||||||
|
Reference in New Issue
Block a user