diff --git a/lib/classes/caption/record.php b/lib/classes/caption/record.php index e58f590308..5c47286703 100644 --- a/lib/classes/caption/record.php +++ b/lib/classes/caption/record.php @@ -38,7 +38,6 @@ class caption_record implements caption_interface, cache_cacheableInterface * @var record */ protected $record; - protected $dces_elements = array(); protected $databox; protected $app; @@ -179,10 +178,6 @@ class caption_record implements caption_interface, cache_cacheableInterface $metadata = new caption_field($this->app, $databox_meta_struct, $this->record); $rec_fields[$databox_meta_struct->get_id()] = $metadata; - $dces_element = $metadata->get_databox_field()->get_dces_element(); - if ($dces_element instanceof databox_Field_DCESAbstract) { - $this->dces_elements[$dces_element->get_label()] = $databox_meta_struct->get_id(); - } } $this->fields = $rec_fields; @@ -240,8 +235,11 @@ class caption_record implements caption_interface, cache_cacheableInterface public function get_dc_field($label) { $fields = $this->retrieve_fields(); - if (isset($this->dces_elements[$label])) { - return $fields[$this->dces_elements[$label]]; + + if (null !== $field = $this->databox->get_meta_structure()->get_dces_field($label)) { + if (isset($fields[$field->get_id()])) { + return $fields[$field->get_id()]; + } } return null; @@ -271,7 +269,7 @@ class caption_record implements caption_interface, cache_cacheableInterface protected function highlight_fields($highlight, Array $grep_fields = null, SearchEngineInterface $searchEngine = null, $includeBusiness = false) { $fields = array(); - + foreach ($this->get_fields($grep_fields, $includeBusiness) as $meta_struct_id => $field) { $value = preg_replace( diff --git a/lib/classes/databox/descriptionStructure.php b/lib/classes/databox/descriptionStructure.php index fdfce8d6c7..4445b00219 100644 --- a/lib/classes/databox/descriptionStructure.php +++ b/lib/classes/databox/descriptionStructure.php @@ -109,6 +109,19 @@ class databox_descriptionStructure implements IteratorAggregate return null; } + public function get_dces_field($label) + { + foreach ($this->elements as $field) { + if (null !== $dces_element = $field->get_dces_element()) { + if ($label === $dces_element->get_label()) { + return $field; + } + } + } + + return null; + } + /** * * @param string $id diff --git a/tests/classes/caption/caption_recordTest.php b/tests/classes/caption/caption_recordTest.php index a90bf6ad60..3a45e0e406 100644 --- a/tests/classes/caption/caption_recordTest.php +++ b/tests/classes/caption/caption_recordTest.php @@ -170,7 +170,7 @@ class caption_recordTest extends PhraseanetPHPUnitAbstract break; } - if (!$meta) { + if (!$field) { $this->markTestSkipped('Unable to set a DC field'); } @@ -180,7 +180,7 @@ class caption_recordTest extends PhraseanetPHPUnitAbstract self::$DI['record_1']->set_metadatas(array( array( 'meta_id' => null, - 'meta_struct_id' => $meta->get_id(), + 'meta_struct_id' => $field->get_id(), 'value' => array('HELLO MO !'), ) ));