diff --git a/lib/classes/caption/record.class.php b/lib/classes/caption/record.class.php
index 43ac0636c6..8c6169ee0d 100644
--- a/lib/classes/caption/record.class.php
+++ b/lib/classes/caption/record.class.php
@@ -60,8 +60,9 @@ class caption_record implements caption_interface, cache_cacheableInterface
protected function retrieve_fields()
{
if (is_array($this->fields))
-
+ {
return $this->fields;
+ }
$fields = array();
try
@@ -70,12 +71,12 @@ class caption_record implements caption_interface, cache_cacheableInterface
}
catch (Exception $e)
{
- $sql = "SELECT m.id as meta_id, s.id as structure_id
+ $sql = "SELECT m.id as meta_id, s.id as structure_id
FROM metadatas m, metadatas_structure s
WHERE m.record_id = :record_id AND s.id = m.meta_struct_id";
$stmt = $this->databox->get_connection()->prepare($sql);
$stmt->execute(array(':record_id' => $this->record->get_record_id()));
- $fields = $stmt->fetchAll(PDO::FETCH_ASSOC);
+ $fields = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$this->set_data_to_cache($fields);
}
@@ -86,10 +87,10 @@ class caption_record implements caption_interface, cache_cacheableInterface
try
{
$databox_meta_struct = databox_field::get_instance($this->databox, $row['structure_id']);
- $metadata = new caption_field($databox_meta_struct, $this->record, $row['meta_id']);
+ $metadata = new caption_field($databox_meta_struct, $this->record, $row['meta_id']);
$rec_fields[$databox_meta_struct->get_id()] = $metadata;
- $dces_element = $metadata->get_databox_field()->get_dces_element();
+ $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();
@@ -125,6 +126,23 @@ class caption_record implements caption_interface, cache_cacheableInterface
return $fields;
}
+ /**
+ *
+ * @param type $fieldname
+ * @return \caption_field
+ * @throws \Exception
+ */
+ public function get_field($fieldname)
+ {
+ foreach ($this->retrieve_fields() as $meta_struct_id => $field)
+ {
+ if ($field->get_name() == $fieldname)
+ return $field;
+ }
+
+ throw new \Exception('Field not found');
+ }
+
/**
*
* @param type $label
@@ -134,8 +152,10 @@ class caption_record implements caption_interface, cache_cacheableInterface
{
$fields = $this->retrieve_fields();
if (isset($this->dces_elements[$label]))
-
+ {
return $fields[$this->dces_elements[$label]];
+ }
+
return null;
}
@@ -146,7 +166,7 @@ class caption_record implements caption_interface, cache_cacheableInterface
* @param searchEngine_adapter $searchEngine
* @return array
*/
- public function get_highlight_fields($highlight='', Array $grep_fields = null, searchEngine_adapter $searchEngine = null)
+ public function get_highlight_fields($highlight = '', Array $grep_fields = null, searchEngine_adapter $searchEngine = null)
{
return $this->highlight_fields($highlight, $grep_fields, $searchEngine);
}
@@ -158,7 +178,7 @@ class caption_record implements caption_interface, cache_cacheableInterface
* @param searchEngine_adapter $searchEngine
* @return array
*/
- protected function highlight_fields($highlight, Array $grep_fields = null, searchEngine_adapter $searchEngine =null)
+ protected function highlight_fields($highlight, Array $grep_fields = null, searchEngine_adapter $searchEngine = null)
{
$fields = array();
foreach ($this->fields as $meta_struct_id => $field)
@@ -167,14 +187,14 @@ class caption_record implements caption_interface, cache_cacheableInterface
continue;
$value = preg_replace(
- "(([^']{1})((https?|file):((/{2,4})|(\\{2,4}))[\w:#%/;$()~_?/\-=\\\.&]*)([^']{1}))"
- , '$1 $2 $7'
- , $field->highlight_thesaurus()
+ "(([^']{1})((https?|file):((/{2,4})|(\\{2,4}))[\w:#%/;$()~_?/\-=\\\.&]*)([^']{1}))"
+ , '$1 $2 $7'
+ , $field->highlight_thesaurus()
);
$fields[$field->get_name()] = array(
- 'value' => $value
- , 'separator' => $field->get_databox_field()->get_separator()
+ 'value' => $value
+ , 'separator' => $field->get_databox_field()->get_separator()
);
}
diff --git a/lib/classes/record/adapter.class.php b/lib/classes/record/adapter.class.php
index 2e8ff7206f..2e564b553d 100644
--- a/lib/classes/record/adapter.class.php
+++ b/lib/classes/record/adapter.class.php
@@ -617,8 +617,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface
throw new Exception_Media_SubdefNotFound ();
if (isset($this->subdefs[$name]))
-
+ {
return $this->subdefs[$name];
+ }
if (!$this->subdefs)
$this->subdefs = array();
@@ -757,11 +758,13 @@ class record_adapter implements record_Interface, cache_cacheableInterface
if ($data)
{
if (isset($this->technical_datas[$data]))
-
+ {
return $this->technical_datas[$data];
+ }
else
-
+ {
return false;
+ }
}
return $this->technical_datas;
@@ -846,18 +849,29 @@ class record_adapter implements record_Interface, cache_cacheableInterface
{
$this->original_name = $original_name;
- foreach ($this->get_caption()->get_fields() as $field)
+ foreach ($this->get_databox()->get_meta_structure()->get_elements() as $data_field)
{
- if ($field->get_databox_field()->get_source() != metadata_description_PHRASEANET_tffilename::get_source())
+ if ($data_field->get_metadata_source() != metadata_description_PHRASEANET_tffilename::get_source())
{
continue;
}
+ $meta_id = null;
+
+ try
+ {
+ $meta_id = $this->get_caption()->get_field($data_field->get_name())->get_meta_id();
+ }
+ catch (\Exception $e)
+ {
+ $meta_id = null;
+ }
+
$this->set_metadatas(
array(
- 'meta_struct_id' => $field->get_meta_struct_id()
- , 'meta_id' => get_meta_id
- , 'value' => array($original_name)
+ 'meta_struct_id' => $data_field->get_id()
+ , 'meta_id' => $meta_id
+ , 'value' => array($original_name)
)
, true
);
@@ -1226,8 +1240,10 @@ class record_adapter implements record_Interface, cache_cacheableInterface
foreach ($metadatas as $param)
{
if (!is_array($param))
- throw new Exception_InvalidArgument();
-
+ {
+ throw new Exception_InvalidArgument('Invalid metadatas argument');
+ }
+
$db_field = \databox_field::get_instance($this->get_databox(), $param['meta_struct_id']);
if ($db_field->is_readonly() === true && !$force_readonly)
@@ -1358,7 +1374,6 @@ class record_adapter implements record_Interface, cache_cacheableInterface
public function get_reg_name()
{
if (!$this->is_grouping())
-
return false;
$balisename = '';
@@ -1502,8 +1517,39 @@ class record_adapter implements record_Interface, cache_cacheableInterface
, ':value' => $value
));
}
+
$stmt->closeCursor();
+ foreach ($record->get_databox()->get_meta_structure()->get_elements() as $data_field)
+ {
+ if ($data_field->get_metadata_source() != metadata_description_PHRASEANET_tfrecordid::get_source())
+ {
+
+ continue;
+ }
+ $meta_id = null;
+
+ try
+ {
+ $meta_id = $record->get_caption()->get_field($data_field->get_name())->get_meta_id();
+ }
+ catch (\Exception $e)
+ {
+ $meta_id = null;
+ }
+
+ $metas = array(
+ array(
+ 'meta_struct_id' => $data_field->get_id()
+ , 'meta_id' => $meta_id
+ , 'value' => array($record->get_record_id())
+ )
+ );
+
+ $record->set_metadatas($metas, true);
+ }
+
+
return $record;
}
@@ -1555,7 +1601,6 @@ class record_adapter implements record_Interface, cache_cacheableInterface
{
$hd = $this->get_subdef('document');
if ($hd->is_physically_present())
-
return new system_file(p4string::addEndSlash($hd->get_path()) . $hd->get_file());
return null;
}
@@ -1894,7 +1939,6 @@ class record_adapter implements record_Interface, cache_cacheableInterface
public function get_container_baskets()
{
if ($this->container_basket)
-
return $this->container_basket;
$appbox = appbox::get_instance();