Remove ArrayCollection as there is no benefits to use it.

Change twig from ArrayCollection to plain array.
This commit is contained in:
Benoît Burnichon
2015-04-29 18:56:40 +02:00
parent 2d5a36f5a2
commit 50ea2e26cb
9 changed files with 89 additions and 95 deletions

View File

@@ -11,9 +11,8 @@
namespace Alchemy\Phrasea\Model\Entities; namespace Alchemy\Phrasea\Model\Entities;
use Doctrine\Common\Collections\ArrayCollection;
use Alchemy\Phrasea\Model\RecordInterface;
use Alchemy\Phrasea\Model\MutableRecordInterface; use Alchemy\Phrasea\Model\MutableRecordInterface;
use Alchemy\Phrasea\Model\RecordInterface;
/** /**
* Record entity from elastic search * Record entity from elastic search
@@ -26,7 +25,7 @@ class ElasticsearchRecord implements RecordInterface, MutableRecordInterface
private $baseId; private $baseId;
private $collectionName; private $collectionName;
private $mimeType; private $mimeType;
private $title; private $title = [];
private $originalName; private $originalName;
private $updated; private $updated;
private $created; private $created;
@@ -36,16 +35,11 @@ class ElasticsearchRecord implements RecordInterface, MutableRecordInterface
private $type; private $type;
private $status; private $status;
private $isStory; private $isStory;
/** @var ArrayCollection */ private $caption = [];
private $caption; private $exif = [];
/** @var ArrayCollection */ private $subdefs = [];
private $exif; private $flags = [];
/** @var ArrayCollection */ private $highlight = [];
private $subdefs;
/** @var ArrayCollection */
private $flags;
/** @var ArrayCollection */
private $highlight;
/** {@inheritdoc} */ /** {@inheritdoc} */
public function getId() public function getId()
@@ -110,7 +104,7 @@ class ElasticsearchRecord implements RecordInterface, MutableRecordInterface
/** {@inheritdoc} */ /** {@inheritdoc} */
public function setIsStory($isStory) public function setIsStory($isStory)
{ {
$this->isStory = (bool) $isStory; $this->isStory = (bool)$isStory;
} }
/** {@inheritdoc} */ /** {@inheritdoc} */
@@ -187,12 +181,12 @@ class ElasticsearchRecord implements RecordInterface, MutableRecordInterface
*/ */
public function getTitle($locale = null) public function getTitle($locale = null)
{ {
if ($locale && $this->title->containsKey($locale)) { if ($locale && isset($this->title[$locale])) {
return $this->title->get($locale); return $this->title[$locale];
} }
if ($this->title->containsKey('default')) { if (isset($this->title['default'])) {
return $this->title->get('default'); return $this->title['default'];
} }
return $this->getOriginalName(); return $this->getOriginalName();
@@ -201,9 +195,9 @@ class ElasticsearchRecord implements RecordInterface, MutableRecordInterface
/** /**
* Sets a collection of titles * Sets a collection of titles
* *
* @param ArrayCollection $titles * @param string[] $titles
*/ */
public function setTitles(ArrayCollection $titles) public function setTitles(array $titles)
{ {
$this->title = $titles; $this->title = $titles;
} }
@@ -242,45 +236,41 @@ class ElasticsearchRecord implements RecordInterface, MutableRecordInterface
$this->uuid = $uuid; $this->uuid = $uuid;
} }
/** @return ArrayCollection */ /** @return array */
public function getCaption() public function getCaption()
{ {
return $this->caption; return $this->caption;
} }
public function setCaption(ArrayCollection $caption) public function setCaption(array $caption)
{ {
$this->caption = $caption; $this->caption = $caption;
} }
/** @return ArrayCollection */ /** @return array */
public function getExif() public function getExif()
{ {
return $this->exif; return $this->exif;
} }
/** public function setExif(array $exif)
* @param mixed $exif
*/
public function setExif(ArrayCollection $exif)
{ {
$this->exif = $exif; $this->exif = $exif;
} }
/** @return ArrayCollection */ /** @return array */
public function getSubdefs() public function getSubdefs()
{ {
return $this->subdefs; return $this->subdefs;
} }
/** @return ArrayCollection */ public function setSubdefs(array $subdefs)
public function setSubdefs(ArrayCollection $subdefs)
{ {
$this->subdefs = $subdefs; $this->subdefs = $subdefs;
} }
/** /**
* @return ArrayCollection * @return array
*/ */
public function getFlags() public function getFlags()
{ {
@@ -288,9 +278,9 @@ class ElasticsearchRecord implements RecordInterface, MutableRecordInterface
} }
/** /**
* @param ArrayCollection $flags * @param array $flags
*/ */
public function setFlags(ArrayCollection $flags) public function setFlags(array $flags)
{ {
$this->flags = $flags; $this->flags = $flags;
} }
@@ -323,7 +313,7 @@ class ElasticsearchRecord implements RecordInterface, MutableRecordInterface
} }
/** /**
* @return ArrayCollection * @return array
*/ */
public function getHighlight() public function getHighlight()
{ {
@@ -331,9 +321,9 @@ class ElasticsearchRecord implements RecordInterface, MutableRecordInterface
} }
/** /**
* @param ArrayCollection $highlight * @param array $highlight
*/ */
public function setHighlight(ArrayCollection $highlight) public function setHighlight(array $highlight)
{ {
$this->highlight = $highlight; $this->highlight = $highlight;
} }

View File

@@ -58,9 +58,9 @@ interface RecordInterface
/** @return integer */ /** @return integer */
public function getStatusBitField(); public function getStatusBitField();
/** @return ArrayCollection */ /** @return array */
public function getExif(); public function getExif();
/** @return ArrayCollection */ /** @return array */
public function getCaption(); public function getCaption();
} }

View File

@@ -41,12 +41,12 @@ class ElasticsearchRecordHydrator
$record->setUpdated($updatedOn ? new \DateTime($updatedOn) : $updatedOn); $record->setUpdated($updatedOn ? new \DateTime($updatedOn) : $updatedOn);
$record->setUuid(igorw\get_in($data, ['uuid'], '')); $record->setUuid(igorw\get_in($data, ['uuid'], ''));
$record->setStatusBitField(igorw\get_in($data, ['flags_bitfield'], 0)); $record->setStatusBitField(igorw\get_in($data, ['flags_bitfield'], 0));
$record->setTitles(new ArrayCollection((array) igorw\get_in($data, ['title'], []))); $record->setTitles((array) igorw\get_in($data, ['title'], []));
$record->setCaption(new ArrayCollection((array) igorw\get_in($data, ['caption'], []))); $record->setCaption((array) igorw\get_in($data, ['caption'], []));
$record->setExif(new ArrayCollection((array) igorw\get_in($data, ['exif'], []))); $record->setExif((array) igorw\get_in($data, ['exif'], []));
$record->setSubdefs(new ArrayCollection((array) igorw\get_in($data, ['subdefs'], []))); $record->setSubdefs((array) igorw\get_in($data, ['subdefs'], []));
$record->setFlags(new ArrayCollection((array) igorw\get_in($data, ['flags'], []))); $record->setFlags((array) igorw\get_in($data, ['flags'], []));
$record->setHighlight(new ArrayCollection($highlight)); $record->setHighlight((array) $highlight);
return $record; return $record;
} }

View File

@@ -2,10 +2,10 @@
namespace Alchemy\Phrasea\Twig; namespace Alchemy\Phrasea\Twig;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Model\Entities\ElasticsearchRecord; use Alchemy\Phrasea\Model\Entities\ElasticsearchRecord;
use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Model\Entities\User;
use Alchemy\Phrasea\Model\RecordInterface; use Alchemy\Phrasea\Model\RecordInterface;
use Silex\Application;
class PhraseanetExtension extends \Twig_Extension class PhraseanetExtension extends \Twig_Extension
{ {
@@ -49,11 +49,12 @@ class PhraseanetExtension extends \Twig_Extension
if ($record instanceof ElasticsearchRecord) { if ($record instanceof ElasticsearchRecord) {
$highlightKey = sprintf('caption.%s', $field); $highlightKey = sprintf('caption.%s', $field);
if (false === $record->getHighlight()->containsKey($highlightKey)) { $highlights = $record->getHighlight();
if (false === isset($highlights[$highlightKey])) {
return implode('; ', (array) $value); return implode('; ', (array) $value);
} }
$highlightValue = $record->getHighlight()->get($highlightKey); $highlightValue = $highlights[$highlightKey];
// if field is multivalued, merge highlighted values with captions ones // if field is multivalued, merge highlighted values with captions ones
if (is_array($value)) { if (is_array($value)) {
@@ -71,7 +72,9 @@ class PhraseanetExtension extends \Twig_Extension
public function getRecordFlags(RecordInterface $record) public function getRecordFlags(RecordInterface $record)
{ {
$recordStatuses = []; $recordStatuses = [];
$databox = $this->app['phraseanet.appbox']->get_databox($record->getDataboxId()); /** @var \appbox $appbox */
$appbox = $this->app['phraseanet.appbox'];
$databox = $appbox->get_databox($record->getDataboxId());
$structure = $databox->getStatusStructure()->toArray(); $structure = $databox->getStatusStructure()->toArray();
@@ -207,8 +210,9 @@ class PhraseanetExtension extends \Twig_Extension
public function getSubdefUrl(RecordInterface $record, $subdefName) public function getSubdefUrl(RecordInterface $record, $subdefName)
{ {
if ($record instanceof ElasticsearchRecord) { if ($record instanceof ElasticsearchRecord) {
if ($record->getSubdefs()->containsKey($subdefName)) { $subdefs = $record->getSubdefs();
$thumbnail = $record->getSubdefs()->get($subdefName); if (isset($subdefs[$subdefName])) {
$thumbnail = $subdefs[$subdefName];
if (null !== $path = $thumbnail['path']) { if (null !== $path = $thumbnail['path']) {
if (is_string($path) && '' !== $path) { if (is_string($path) && '' !== $path) {
return $this->app['phraseanet.static-file']->getUrl($path); return $this->app['phraseanet.static-file']->getUrl($path);

View File

@@ -765,14 +765,15 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
public function getCaption() public function getCaption()
{ {
$collection = new ArrayCollection(); $collection = [];
/** @var caption_field $field */
foreach ($this->get_caption()->get_fields() as $field) { foreach ($this->get_caption()->get_fields() as $field) {
$values = array_map(function($fieldValue) { $values = array_map(function(caption_Field_Value $fieldValue) {
return $fieldValue->getValue(); return $fieldValue->getValue();
}, $field->get_values()); }, $field->get_values());
$collection->set($field->get_name(), $values); $collection[$field->get_name()] = $values;
} }
return $collection; return $collection;
@@ -2035,7 +2036,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
/** {@inheritdoc} */ /** {@inheritdoc} */
public function getExif() public function getExif()
{ {
return new ArrayCollection($this->get_technical_infos()); return $this->get_technical_infos();
} }
public function getStatusStructure() public function getStatusStructure()

View File

@@ -19,52 +19,52 @@
<br/> <br/>
{% block td_size %} {% block td_size %}
{% set width = record.exif.get(constant('media_subdef::TC_DATA_WIDTH')) %} {% set width = record.exif[constant('media_subdef::TC_DATA_WIDTH')]|default(null) %}
{% set height = record.exif.get(constant('media_subdef::TC_DATA_HEIGHT')) %} {% set height = record.exif[constant('media_subdef::TC_DATA_HEIGHT')]|default(null) %}
{% if width is not none and height is not none %} {% if width is not none and height is not none %}
{{ width ~ " x " ~ height }} {{ width ~ " x " ~ height }}
{% endif %} {% endif %}
{% endblock %} {% endblock %}
<hr/> <hr/>
{% block td_camera_model %} {% block td_camera_model %}
{% if record.exif.get(constant('media_subdef::TC_DATA_CAMERAMODEL')) is not none %} {% if record.exif[constant('media_subdef::TC_DATA_CAMERAMODEL')] is defined %}
{{ 'Camera Model' | trans }} : {{ 'Camera Model' | trans }} :
{{ record.exif.get(constant('media_subdef::TC_DATA_CAMERAMODEL')) }} {{ record.exif[constant('media_subdef::TC_DATA_CAMERAMODEL')] }}
<br /> <br />
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block td_color_space %} {% block td_color_space %}
{% if record.exif.get(constant('media_subdef::TC_DATA_COLORSPACE')) is not none %} {% if record.exif[constant('media_subdef::TC_DATA_COLORSPACE')] is defined %}
{{ 'Color space' | trans }} : {{ 'Color space' | trans }} :
{{ record.exif.get(constant('media_subdef::TC_DATA_COLORSPACE')) }} {{ record.exif[constant('media_subdef::TC_DATA_COLORSPACE')] }}
<br /> <br />
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block td_channels %} {% block td_channels %}
{% if record.exif.get(constant('media_subdef::TC_DATA_CHANNELS')) is not none %} {% if record.exif[constant('media_subdef::TC_DATA_CHANNELS')] is defined %}
{{ 'Channels' | trans }} : {{ 'Channels' | trans }} :
{{ record.exif.get(constant('media_subdef::TC_DATA_CHANNELS')) }} {{ record.exif[constant('media_subdef::TC_DATA_CHANNELS')] }}
<br /> <br />
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block td_color_depth %} {% block td_color_depth %}
{% if record.exif.get(constant('media_subdef::TC_DATA_COLORDEPTH')) is not none %} {% if record.exif[constant('media_subdef::TC_DATA_COLORDEPTH')] is defined %}
{{ 'Color Depth' | trans }} : {{ 'Color Depth' | trans }} :
{{ record.exif.get(constant('media_subdef::TC_DATA_COLORDEPTH')) }} bits {{ record.exif[constant('media_subdef::TC_DATA_COLORDEPTH')] }} bits
<br /> <br />
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block td_iso_sensibility %} {% block td_iso_sensibility %}
{% if record.exif.get(constant('media_subdef::TC_DATA_ISO')) is not none %} {% if record.exif[constant('media_subdef::TC_DATA_ISO')] is defined %}
{{ 'ISO sensibility' | trans }} : {{ 'ISO sensibility' | trans }} :
{{ record.exif.get(constant('media_subdef::TC_DATA_ISO')) }} {{ record.exif[constant('media_subdef::TC_DATA_ISO')] }}
<br /> <br />
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block td_flash %} {% block td_flash %}
{% if record.exif.get(constant('media_subdef::TC_DATA_FLASHFIRED')) is not none %} {% if record.exif[constant('media_subdef::TC_DATA_FLASHFIRED')] is defined %}
{{ 'Flash' | trans }} : {{ 'Flash' | trans }} :
{% if record.exif.get(constant('media_subdef::TC_DATA_FLASHFIRED')) %} {% if record.exif[constant('media_subdef::TC_DATA_FLASHFIRED')] %}
{{ 'yes' | trans }} {{ 'yes' | trans }}
{% else %} {% else %}
{{ 'no' | trans }} {{ 'no' | trans }}
@@ -73,72 +73,72 @@
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block td_shutter_speed %} {% block td_shutter_speed %}
{% if record.exif.get(constant('media_subdef::TC_DATA_SHUTTERSPEED')) is not none %} {% if record.exif[constant('media_subdef::TC_DATA_SHUTTERSPEED')] is defined %}
{{ 'Shutter speed' | trans }} : {{ 'Shutter speed' | trans }} :
{{ record.exif.get(constant('media_subdef::TC_DATA_SHUTTERSPEED')) }} s. {{ record.exif[constant('media_subdef::TC_DATA_SHUTTERSPEED')] }} s.
<br /> <br />
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block td_apeture %} {% block td_apeture %}
{% if record.exif.get(constant('media_subdef::TC_DATA_APERTURE')) is not none %} {% if record.exif[constant('media_subdef::TC_DATA_APERTURE')] is defined %}
{{ 'Aperture' | trans }} : {{ 'Aperture' | trans }} :
{{ record.exif.get(constant('media_subdef::TC_DATA_APERTURE')) | round(2) }} {{ record.exif[constant('media_subdef::TC_DATA_APERTURE')] | round(2) }}
<br /> <br />
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block td_focal_length %} {% block td_focal_length %}
{% if record.exif.get(constant('media_subdef::TC_DATA_FOCALLENGTH')) is not none %} {% if record.exif[constant('media_subdef::TC_DATA_FOCALLENGTH')] is defined %}
{{ 'Focal length' | trans }} : {{ 'Focal length' | trans }} :
{{ record.exif.get(constant('media_subdef::TC_DATA_FOCALLENGTH')) }} mm {{ record.exif[constant('media_subdef::TC_DATA_FOCALLENGTH')] }} mm
<br /> <br />
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block td_hyperfocal_distance %} {% block td_hyperfocal_distance %}
{% if record.exif.get(constant('media_subdef::TC_DATA_HYPERFOCALDISTANCE')) is not none %} {% if record.exif[constant('media_subdef::TC_DATA_HYPERFOCALDISTANCE')] is defined %}
{{ 'Hyperfocal distance' | trans }} : {{ 'Hyperfocal distance' | trans }} :
{{ record.exif.get(constant('media_subdef::TC_DATA_HYPERFOCALDISTANCE')) | round(2) }} mm {{ record.exif[constant('media_subdef::TC_DATA_HYPERFOCALDISTANCE')] | round(2) }} mm
<br /> <br />
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block td_light_value %} {% block td_light_value %}
{% if record.exif.get(constant('media_subdef::TC_DATA_LIGHTVALUE')) is not none %} {% if record.exif[constant('media_subdef::TC_DATA_LIGHTVALUE')] is defined %}
{{ 'Light Value' | trans }} : {{ 'Light Value' | trans }} :
{{ record.exif.get(constant('media_subdef::TC_DATA_LIGHTVALUE')) | round(2) }} {{ record.exif[constant('media_subdef::TC_DATA_LIGHTVALUE')] | round(2) }}
<br /> <br />
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block td_duration %} {% block td_duration %}
{% if record.exif.get(constant('media_subdef::TC_DATA_DURATION')) is not none %} {% if record.exif[constant('media_subdef::TC_DATA_DURATION')] is defined %}
{{ 'Duree' | trans }} : {{ 'Duree' | trans }} :
{{ record.exif.get(constant('media_subdef::TC_DATA_DURATION')) }} {{ record.exif[constant('media_subdef::TC_DATA_DURATION')] }}
<br /> <br />
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block td_framerate %} {% block td_framerate %}
{% if record.exif.get(constant('media_subdef::TC_DATA_FRAMERATE')) is not none %} {% if record.exif[constant('media_subdef::TC_DATA_FRAMERATE')] is defined %}
{{ 'Images par secondes' | trans }} : {{ 'Images par secondes' | trans }} :
{{ record.exif.get(constant('media_subdef::TC_DATA_FRAMERATE')) | round(2) }} ips {{ record.exif[constant('media_subdef::TC_DATA_FRAMERATE')] | round(2) }} ips
<br /> <br />
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block td_codec_audio %} {% block td_codec_audio %}
{% if record.exif.get(constant('media_subdef::TC_DATA_AUDIOCODEC')) %} {% if record.exif[constant('media_subdef::TC_DATA_AUDIOCODEC')] is defined %}
{{ 'Codec Audio' | trans }} : {{ 'Codec Audio' | trans }} :
{{ record.exif.get(constant('media_subdef::TC_DATA_AUDIOCODEC')) }} {{ record.exif[constant('media_subdef::TC_DATA_AUDIOCODEC')] }}
<br /> <br />
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block td_codec_video %} {% block td_codec_video %}
{% if record.exif.get(constant('media_subdef::TC_DATA_VIDEOCODEC')) %} {% if record.exif[constant('media_subdef::TC_DATA_VIDEOCODEC')] is defined %}
{{ 'Codec Video' | trans }} : {{ 'Codec Video' | trans }} :
{{ record.exif.get(constant('media_subdef::TC_DATA_VIDEOCODEC')) }} {{ record.exif[constant('media_subdef::TC_DATA_VIDEOCODEC')] }}
<br /> <br />
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block td_audio_rate %} {% block td_audio_rate %}
{% if record.exif.get(constant('media_subdef::TC_DATA_AUDIOSAMPLERATE')) %} {% if record.exif[constant('media_subdef::TC_DATA_AUDIOSAMPLERATE')] is defined %}
{{ 'Frequence d\'echantillonage' | trans }} : {{ 'Frequence d\'echantillonage' | trans }} :
{{ record.exif.get(constant('media_subdef::TC_DATA_AUDIOSAMPLERATE')) | round(2) }} kHz {{ record.exif[constant('media_subdef::TC_DATA_AUDIOSAMPLERATE')] | round(2) }} kHz
<br /> <br />
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View File

@@ -5,7 +5,7 @@
{% set thumb_w = 70 %} {% set thumb_w = 70 %}
{% set thumb_h = 70 %} {% set thumb_h = 70 %}
{% set thumbnail = record.subdefs.get('thumbnail') %} {% set thumbnail = record.subdefs.thumbnail|default(null) %}
{% if thumbnail is not none %} {% if thumbnail is not none %}
{% set thumb_w = thumbnail.width %} {% set thumb_w = thumbnail.width %}
@@ -50,4 +50,3 @@
</div> </div>
</div> </div>
<div id="PREVIEWTOOL"></div> <div id="PREVIEWTOOL"></div>

View File

@@ -4,7 +4,7 @@
{% set thumb_w = 256 %} {% set thumb_w = 256 %}
{% set thumb_h = 256 %} {% set thumb_h = 256 %}
{% set thumbnail = record.subdefs.get('thumbnail') %} {% set thumbnail = record.subdefs.thumbnail|default(null) %}
{% if thumbnail is not none %} {% if thumbnail is not none %}
{% set thumb_w = thumbnail.width %} {% set thumb_w = thumbnail.width %}
{% set thumb_h = thumbnail.height %} {% set thumb_h = thumbnail.height %}
@@ -39,7 +39,7 @@
{% set thumb_w = 256 %} {% set thumb_w = 256 %}
{% set thumb_h = 256 %} {% set thumb_h = 256 %}
{% set thumbnail = record.subdefs.get('thumbnailgif') %} {% set thumbnail = record.subdefs.thumbnailgif|default(null) %}
{% if thumbnail is not none %} {% if thumbnail is not none %}
{% set thumb_w = thumbnail.width %} {% set thumb_w = thumbnail.width %}
{% set thumb_h = thumbnail.height %} {% set thumb_h = thumbnail.height %}

View File

@@ -34,7 +34,7 @@
{% endif %} {% endif %}
</span> </span>
</div> </div>
{% set rollover = record.subdefs.containsKey('thumbnailgif') %} {% set rollover = record.subdefs.thumbnailgif is defined %}
{% set extraclass = '' %} {% set extraclass = '' %}
<div class="{% if rollover %}rollovable{% endif %}"> <div class="{% if rollover %}rollovable{% endif %}">
{% if rollover %} {% if rollover %}
@@ -116,7 +116,7 @@
</tbody> </tbody>
</table> </table>
{% if record.subdefs.containsKey('preview') and has_access_subdef(record, 'preview') %} {% if record.subdefs.preview is defined and has_access_subdef(record, 'preview') %}
<div tooltipsrc="{{ path('prod_tooltip_preview', { 'sbas_id' : record.databoxId, 'record_id' : record.recordId }) }}" class="previewTips"></div> <div tooltipsrc="{{ path('prod_tooltip_preview', { 'sbas_id' : record.databoxId, 'record_id' : record.recordId }) }}" class="previewTips"></div>
{% endif %} {% endif %}