Merge pull request #1385 from bburnichon/feature/private-fields-not-displayed-on-production-phras-544

private fields are not displayed on production
PHRAS-544
This commit is contained in:
Benoît Burnichon
2015-05-29 18:11:54 +02:00
8 changed files with 106 additions and 14 deletions

View File

@@ -36,6 +36,7 @@ class ElasticsearchRecord implements RecordInterface, MutableRecordInterface
private $status; private $status;
private $isStory; private $isStory;
private $caption = []; private $caption = [];
private $privateCaption = [];
private $exif = []; private $exif = [];
private $subdefs = []; private $subdefs = [];
private $flags = []; private $flags = [];
@@ -236,10 +237,22 @@ class ElasticsearchRecord implements RecordInterface, MutableRecordInterface
$this->uuid = $uuid; $this->uuid = $uuid;
} }
/** @return array */ public function getCaption(array $fields = null)
public function getCaption()
{ {
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) public function setCaption(array $caption)
@@ -247,6 +260,20 @@ class ElasticsearchRecord implements RecordInterface, MutableRecordInterface
$this->caption = $caption; $this->caption = $caption;
} }
/** @return array */
public function getPrivateCaption()
{
return $this->privateCaption;
}
/**
* @param array $privateCaption
*/
public function setPrivateCaption(array $privateCaption)
{
$this->privateCaption = $privateCaption;
}
/** @return array */ /** @return array */
public function getExif() public function getExif()
{ {

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\SearchEngine\Elastic; namespace Alchemy\Phrasea\SearchEngine\Elastic;
use Alchemy\Phrasea\Exception\LogicException;
use Alchemy\Phrasea\SearchEngine\Elastic\Indexer\RecordIndexer; use Alchemy\Phrasea\SearchEngine\Elastic\Indexer\RecordIndexer;
use Alchemy\Phrasea\SearchEngine\Elastic\Indexer\TermIndexer; use Alchemy\Phrasea\SearchEngine\Elastic\Indexer\TermIndexer;
use Alchemy\Phrasea\SearchEngine\Elastic\RecordHelper; use Alchemy\Phrasea\SearchEngine\Elastic\RecordHelper;

View File

@@ -12,7 +12,6 @@
namespace Alchemy\Phrasea\SearchEngine\Elastic; namespace Alchemy\Phrasea\SearchEngine\Elastic;
use Alchemy\Phrasea\Model\Entities\ElasticsearchRecord; use Alchemy\Phrasea\Model\Entities\ElasticsearchRecord;
use Doctrine\Common\Collections\ArrayCollection;
use igorw; use igorw;
class ElasticsearchRecordHydrator class ElasticsearchRecordHydrator
@@ -43,6 +42,7 @@ class ElasticsearchRecordHydrator
$record->setStatusBitField(igorw\get_in($data, ['flags_bitfield'], 0)); $record->setStatusBitField(igorw\get_in($data, ['flags_bitfield'], 0));
$record->setTitles((array) igorw\get_in($data, ['title'], [])); $record->setTitles((array) igorw\get_in($data, ['title'], []));
$record->setCaption((array) igorw\get_in($data, ['caption'], [])); $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->setExif((array) igorw\get_in($data, ['exif'], []));
$record->setSubdefs((array) igorw\get_in($data, ['subdefs'], [])); $record->setSubdefs((array) igorw\get_in($data, ['subdefs'], []));
$record->setFlags((array) igorw\get_in($data, ['flags'], [])); $record->setFlags((array) igorw\get_in($data, ['flags'], []));

View File

@@ -609,6 +609,15 @@ class SearchEngineOptions
$status = is_array($request->get('status')) ? $request->get('status') : []; $status = is_array($request->get('status')) ? $request->get('status') : [];
$fields = is_array($request->get('fields')) ? $request->get('fields') : []; $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 = []; $databoxFields = [];

View File

@@ -41,6 +41,7 @@ class PhraseanetExtension extends \Twig_Extension
new \Twig_SimpleFunction('record_flags', array($this, 'getRecordFlags')), new \Twig_SimpleFunction('record_flags', array($this, 'getRecordFlags')),
new \Twig_SimpleFunction('border_checker_from_fqcn', array($this, 'getCheckerFromFQCN')), new \Twig_SimpleFunction('border_checker_from_fqcn', array($this, 'getCheckerFromFQCN')),
new \Twig_SimpleFunction('caption_field', array($this, 'getCaptionField')), 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); 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) public function getRecordFlags(RecordInterface $record)
{ {
$recordStatuses = []; $recordStatuses = [];
@@ -253,4 +277,29 @@ class PhraseanetExtension extends \Twig_Extension
{ {
return 'phraseanet'; 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

@@ -100,12 +100,12 @@ class caption_record implements caption_interface, cache_cacheableInterface
} }
/** /**
* @param array $grep_fields * @param array $grep_fields
* @param Boolean $IncludeBusiness * @param bool $includeBusiness
* *
* @return \caption_field[] * @return \caption_field[]
*/ */
public function get_fields(Array $grep_fields = null, $IncludeBusiness = false) public function get_fields(array $grep_fields = null, $includeBusiness = false)
{ {
$fields = []; $fields = [];
@@ -114,7 +114,7 @@ class caption_record implements caption_interface, cache_cacheableInterface
continue; continue;
} }
if ($field->get_databox_field()->isBusiness() === true && ! $IncludeBusiness) { if ((!$includeBusiness) && $field->get_databox_field()->isBusiness() === true) {
continue; continue;
} }

View File

@@ -26,7 +26,6 @@ use Alchemy\Phrasea\Model\Serializer\CaptionSerializer;
use Alchemy\Phrasea\SearchEngine\SearchEngineInterface; use Alchemy\Phrasea\SearchEngine\SearchEngineInterface;
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions; use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Doctrine\Common\Collections\ArrayCollection;
use MediaVorus\Media\MediaInterface; use MediaVorus\Media\MediaInterface;
use MediaVorus\MediaVorus; use MediaVorus\MediaVorus;
use Rhumsaa\Uuid\Uuid; 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()); 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 = []; $collection = [];
/** @var caption_field $field */ foreach ($fields as $field) {
foreach ($this->get_caption()->get_fields() as $field) {
$values = array_map(function(caption_Field_Value $fieldValue) { $values = array_map(function(caption_Field_Value $fieldValue) {
return $fieldValue->getValue(); return $fieldValue->getValue();
}, $field->get_values()); }, $field->get_values());

View File

@@ -117,8 +117,7 @@
{% endmacro %} {% endmacro %}
{% macro caption(record, can_see_business, display_exif) %} {% macro caption(record, can_see_business, display_exif) %}
{# @todo handle business fields #} {% for name, value in record.getCaption(caption_field_order(record, can_see_business)) %}
{% for name, value in record.caption %}
<div class="desc"> <div class="desc">
<b>{{ name }}</b> : <b>{{ name }}</b> :
{{ caption_field(record, name, value)|e|highlight }} {{ caption_field(record, name, value)|e|highlight }}