mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
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:
@@ -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()
|
||||
{
|
||||
|
@@ -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;
|
||||
|
@@ -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'], []));
|
||||
|
@@ -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 = [];
|
||||
|
||||
|
@@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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());
|
||||
|
@@ -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)) %}
|
||||
<div class="desc">
|
||||
<b>{{ name }}</b> :
|
||||
{{ caption_field(record, name, value)|e|highlight }}
|
||||
|
Reference in New Issue
Block a user