diff --git a/lib/Alchemy/Phrasea/Model/Entities/ElasticsearchRecord.php b/lib/Alchemy/Phrasea/Model/Entities/ElasticsearchRecord.php index 7333f8342c..bcd8ed10f8 100644 --- a/lib/Alchemy/Phrasea/Model/Entities/ElasticsearchRecord.php +++ b/lib/Alchemy/Phrasea/Model/Entities/ElasticsearchRecord.php @@ -237,10 +237,22 @@ class ElasticsearchRecord implements RecordInterface, MutableRecordInterface $this->uuid = $uuid; } - /** @return array */ - public function getCaption() + public function getCaption(array $fields = null) { - return $this->caption; + if (null === $fields) { + return $this->caption; + } + + $known = array_merge($this->caption, $this->privateCaption); + + $caption = []; + foreach ($fields as $field) { + if (isset($known[$field]) || array_key_exists($field, $known)) { + $caption[$field] = $known[$field]; + } + } + + return $caption; } public function setCaption(array $caption) diff --git a/lib/Alchemy/Phrasea/Model/RecordInterface.php b/lib/Alchemy/Phrasea/Model/RecordInterface.php index 22d5316fb3..c542b5afc3 100644 --- a/lib/Alchemy/Phrasea/Model/RecordInterface.php +++ b/lib/Alchemy/Phrasea/Model/RecordInterface.php @@ -63,7 +63,4 @@ interface RecordInterface /** @return array */ public function getCaption(); - - /** @return array */ - public function getPrivateCaption(); } diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php index 64abb667e7..877cdddbc1 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php @@ -11,6 +11,7 @@ namespace Alchemy\Phrasea\SearchEngine\Elastic; +use Alchemy\Phrasea\Exception\LogicException; use Alchemy\Phrasea\SearchEngine\Elastic\Indexer\RecordIndexer; use Alchemy\Phrasea\SearchEngine\Elastic\Indexer\TermIndexer; use Alchemy\Phrasea\SearchEngine\Elastic\RecordHelper; diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticsearchRecordHydrator.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticsearchRecordHydrator.php index a982990843..8dc8cec6e8 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticsearchRecordHydrator.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticsearchRecordHydrator.php @@ -12,7 +12,6 @@ namespace Alchemy\Phrasea\SearchEngine\Elastic; use Alchemy\Phrasea\Model\Entities\ElasticsearchRecord; -use Doctrine\Common\Collections\ArrayCollection; use igorw; class ElasticsearchRecordHydrator diff --git a/lib/Alchemy/Phrasea/Twig/PhraseanetExtension.php b/lib/Alchemy/Phrasea/Twig/PhraseanetExtension.php index f3f68d1f01..8b64321afd 100644 --- a/lib/Alchemy/Phrasea/Twig/PhraseanetExtension.php +++ b/lib/Alchemy/Phrasea/Twig/PhraseanetExtension.php @@ -41,6 +41,7 @@ class PhraseanetExtension extends \Twig_Extension new \Twig_SimpleFunction('record_flags', array($this, 'getRecordFlags')), new \Twig_SimpleFunction('border_checker_from_fqcn', array($this, 'getCheckerFromFQCN')), new \Twig_SimpleFunction('caption_field', array($this, 'getCaptionField')), + new \Twig_SimpleFunction('caption_field_order', array($this, 'getCaptionFieldOrder')), ); } @@ -69,6 +70,29 @@ class PhraseanetExtension extends \Twig_Extension return implode('; ', (array) $value); } + /** + * @param RecordInterface $record + * @param bool $businessFields + * @return array + */ + public function getCaptionFieldOrder(RecordInterface $record, $businessFields) + { + static $orders = []; + + $databoxId = $record->getDataboxId(); + $orderKey = (bool) $businessFields ? 'business' : 'public'; + + if (!isset($orders[$databoxId][$orderKey])) { + /** @var \appbox $appbox */ + $appbox = $this->app['phraseanet.appbox']; + $databox = $appbox->get_databox($databoxId); + + $orders[$databoxId] = $this->retrieveDataboxFieldOrderings($databox); + } + + return $orders[$databoxId][$orderKey]; + } + public function getRecordFlags(RecordInterface $record) { $recordStatuses = []; @@ -253,4 +277,29 @@ class PhraseanetExtension extends \Twig_Extension { return 'phraseanet'; } + + /** + * @param \databox $databox + * @return array + */ + private function retrieveDataboxFieldOrderings(\databox $databox) + { + $publicOrder = []; + $businessOrder = []; + + foreach ($databox->get_meta_structure() as $field) { + $fieldName = $field->get_name(); + + if (!$field->isBusiness()) { + $publicOrder[] = $fieldName; + } + + $businessOrder[] = $fieldName; + }; + + return [ + 'public' => $publicOrder, + 'business' => $businessOrder, + ]; + } } diff --git a/lib/classes/record/adapter.php b/lib/classes/record/adapter.php index 1230e2c347..d1c17baa27 100644 --- a/lib/classes/record/adapter.php +++ b/lib/classes/record/adapter.php @@ -677,18 +677,9 @@ class record_adapter implements RecordInterface, cache_cacheableInterface return new caption_record($this->app, $this, $this->get_databox()); } - public function getCaption() + public function getCaption(array $fields = null) { - return $this->getCaptionFieldsMap($this->get_caption()->get_fields()); - } - - public function getPrivateCaption() - { - $businessFields = array_filter($this->get_caption()->get_fields(null, true), function (caption_field $field) { - return $field->get_databox_field()->isBusiness(); - }); - - return $this->getCaptionFieldsMap($businessFields); + return $this->getCaptionFieldsMap($this->get_caption()->get_fields($fields, true)); } /** diff --git a/templates/web/common/macros.html.twig b/templates/web/common/macros.html.twig index 3587d83a42..42bd4603f2 100644 --- a/templates/web/common/macros.html.twig +++ b/templates/web/common/macros.html.twig @@ -117,21 +117,12 @@ {% endmacro %} {% macro caption(record, can_see_business, display_exif) %} - {# @todo handle business fields #} - {% for name, value in record.caption %} + {% for name, value in record.getCaption(caption_field_order(record, can_see_business)) %}
{{ name }} : {{ caption_field(record, name, value)|e|highlight }}
{% endfor %} - {% if can_see_business %} - {% for name, value in record.privateCaption %} -
- {{ name }} : - {{ caption_field(record, name, value)|e|highlight }} -
- {% endfor %} - {% endif %} {% if display_exif|default(true) and app['authentication'].user is not none and user_setting('technical_display') == 'group' %}
{% include 'common/technical_datas.html.twig' %}