Refactor can see business fields.

This commit is contained in:
Benoît Burnichon
2015-05-29 17:53:45 +02:00
parent 80e2783855
commit 649f0fe510
7 changed files with 68 additions and 28 deletions

View File

@@ -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)

View File

@@ -63,7 +63,4 @@ interface RecordInterface
/** @return array */
public function getCaption();
/** @return array */
public function getPrivateCaption();
}

View File

@@ -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;

View File

@@ -12,7 +12,6 @@
namespace Alchemy\Phrasea\SearchEngine\Elastic;
use Alchemy\Phrasea\Model\Entities\ElasticsearchRecord;
use Doctrine\Common\Collections\ArrayCollection;
use igorw;
class ElasticsearchRecordHydrator

View File

@@ -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,
];
}
}

View File

@@ -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));
}
/**

View File

@@ -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)) %}
<div class="desc">
<b>{{ name }}</b> :
{{ caption_field(record, name, value)|e|highlight }}
</div>
{% endfor %}
{% if can_see_business %}
{% for name, value in record.privateCaption %}
<div class="desc">
<b>{{ name }}</b> :
{{ caption_field(record, name, value)|e|highlight }}
</div>
{% endfor %}
{% endif %}
{% if display_exif|default(true) and app['authentication'].user is not none and user_setting('technical_display') == 'group' %}
<hr/>
{% include 'common/technical_datas.html.twig' %}