diff --git a/lib/Alchemy/Phrasea/Model/Entities/ElasticsearchRecord.php b/lib/Alchemy/Phrasea/Model/Entities/ElasticsearchRecord.php index 6733c89c8d..bcd8ed10f8 100644 --- a/lib/Alchemy/Phrasea/Model/Entities/ElasticsearchRecord.php +++ b/lib/Alchemy/Phrasea/Model/Entities/ElasticsearchRecord.php @@ -36,6 +36,7 @@ class ElasticsearchRecord implements RecordInterface, MutableRecordInterface private $status; private $isStory; private $caption = []; + private $privateCaption = []; private $exif = []; private $subdefs = []; private $flags = []; @@ -236,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) @@ -247,6 +260,20 @@ class ElasticsearchRecord implements RecordInterface, MutableRecordInterface $this->caption = $caption; } + /** @return array */ + public function getPrivateCaption() + { + return $this->privateCaption; + } + + /** + * @param array $privateCaption + */ + public function setPrivateCaption(array $privateCaption) + { + $this->privateCaption = $privateCaption; + } + /** @return array */ public function getExif() { 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 33f1038b56..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 @@ -43,6 +42,7 @@ class ElasticsearchRecordHydrator $record->setStatusBitField(igorw\get_in($data, ['flags_bitfield'], 0)); $record->setTitles((array) igorw\get_in($data, ['title'], [])); $record->setCaption((array) igorw\get_in($data, ['caption'], [])); + $record->setPrivateCaption((array) igorw\get_in($data, ['private_caption'], [])); $record->setExif((array) igorw\get_in($data, ['exif'], [])); $record->setSubdefs((array) igorw\get_in($data, ['subdefs'], [])); $record->setFlags((array) igorw\get_in($data, ['flags'], [])); diff --git a/lib/Alchemy/Phrasea/SearchEngine/SearchEngineOptions.php b/lib/Alchemy/Phrasea/SearchEngine/SearchEngineOptions.php index 29165b01e5..8fea09ba77 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/SearchEngineOptions.php +++ b/lib/Alchemy/Phrasea/SearchEngine/SearchEngineOptions.php @@ -609,6 +609,15 @@ class SearchEngineOptions $status = is_array($request->get('status')) ? $request->get('status') : []; $fields = is_array($request->get('fields')) ? $request->get('fields') : []; + if (empty($fields)) { + // Select all fields (business included) + foreach ($databoxes as $databox) { + foreach ($databox->get_meta_structure() as $field) { + $fields[] = $field->get_name(); + } + } + $fields = array_unique($fields); + } $databoxFields = []; 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/caption/record.php b/lib/classes/caption/record.php index 6f01e50857..03e5f7f7d5 100644 --- a/lib/classes/caption/record.php +++ b/lib/classes/caption/record.php @@ -100,12 +100,12 @@ class caption_record implements caption_interface, cache_cacheableInterface } /** - * @param array $grep_fields - * @param Boolean $IncludeBusiness + * @param array $grep_fields + * @param bool $includeBusiness * * @return \caption_field[] */ - public function get_fields(Array $grep_fields = null, $IncludeBusiness = false) + public function get_fields(array $grep_fields = null, $includeBusiness = false) { $fields = []; @@ -114,7 +114,7 @@ class caption_record implements caption_interface, cache_cacheableInterface continue; } - if ($field->get_databox_field()->isBusiness() === true && ! $IncludeBusiness) { + if ((!$includeBusiness) && $field->get_databox_field()->isBusiness() === true) { continue; } diff --git a/lib/classes/record/adapter.php b/lib/classes/record/adapter.php index 20ecf9e2d6..d1c17baa27 100644 --- a/lib/classes/record/adapter.php +++ b/lib/classes/record/adapter.php @@ -26,7 +26,6 @@ use Alchemy\Phrasea\Model\Serializer\CaptionSerializer; use Alchemy\Phrasea\SearchEngine\SearchEngineInterface; use Alchemy\Phrasea\SearchEngine\SearchEngineOptions; use Doctrine\ORM\EntityManager; -use Doctrine\Common\Collections\ArrayCollection; use MediaVorus\Media\MediaInterface; use MediaVorus\MediaVorus; use Rhumsaa\Uuid\Uuid; @@ -678,12 +677,20 @@ 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($fields, true)); + } + + /** + * @param caption_field[] $fields + * @return array + */ + private function getCaptionFieldsMap(array $fields) { $collection = []; - /** @var caption_field $field */ - foreach ($this->get_caption()->get_fields() as $field) { + foreach ($fields as $field) { $values = array_map(function(caption_Field_Value $fieldValue) { return $fieldValue->getValue(); }, $field->get_values()); diff --git a/templates/web/common/macros.html.twig b/templates/web/common/macros.html.twig index ee712955a1..42bd4603f2 100644 --- a/templates/web/common/macros.html.twig +++ b/templates/web/common/macros.html.twig @@ -117,8 +117,7 @@ {% 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 }}