Merge with master

This commit is contained in:
Romain Neutron
2012-02-10 14:48:58 +01:00
2 changed files with 106 additions and 37 deletions

View File

@@ -60,8 +60,9 @@ class caption_record implements caption_interface, cache_cacheableInterface
protected function retrieve_fields() protected function retrieve_fields()
{ {
if (is_array($this->fields)) if (is_array($this->fields))
{
return $this->fields; return $this->fields;
}
$fields = array(); $fields = array();
try try
@@ -70,12 +71,12 @@ class caption_record implements caption_interface, cache_cacheableInterface
} }
catch (Exception $e) 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 FROM metadatas m, metadatas_structure s
WHERE m.record_id = :record_id AND s.id = m.meta_struct_id"; WHERE m.record_id = :record_id AND s.id = m.meta_struct_id";
$stmt = $this->databox->get_connection()->prepare($sql); $stmt = $this->databox->get_connection()->prepare($sql);
$stmt->execute(array(':record_id' => $this->record->get_record_id())); $stmt->execute(array(':record_id' => $this->record->get_record_id()));
$fields = $stmt->fetchAll(PDO::FETCH_ASSOC); $fields = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
$this->set_data_to_cache($fields); $this->set_data_to_cache($fields);
} }
@@ -89,7 +90,7 @@ class caption_record implements caption_interface, cache_cacheableInterface
$metadata = new caption_field($databox_meta_struct, $this->record); $metadata = new caption_field($databox_meta_struct, $this->record);
$rec_fields[$databox_meta_struct->get_id()] = $metadata; $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) if ($dces_element instanceof databox_Field_DCESAbstract)
{ {
$this->dces_elements[$dces_element->get_label()] = $databox_meta_struct->get_id(); $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; 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 * @param type $label
@@ -134,8 +152,10 @@ class caption_record implements caption_interface, cache_cacheableInterface
{ {
$fields = $this->retrieve_fields(); $fields = $this->retrieve_fields();
if (isset($this->dces_elements[$label])) if (isset($this->dces_elements[$label]))
{
return $fields[$this->dces_elements[$label]]; return $fields[$this->dces_elements[$label]];
}
return null; return null;
} }
@@ -146,7 +166,7 @@ class caption_record implements caption_interface, cache_cacheableInterface
* @param searchEngine_adapter $searchEngine * @param searchEngine_adapter $searchEngine
* @return array * @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); return $this->highlight_fields($highlight, $grep_fields, $searchEngine);
} }
@@ -158,7 +178,7 @@ class caption_record implements caption_interface, cache_cacheableInterface
* @param searchEngine_adapter $searchEngine * @param searchEngine_adapter $searchEngine
* @return array * @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(); $fields = array();
foreach ($this->fields as $meta_struct_id => $field) foreach ($this->fields as $meta_struct_id => $field)
@@ -167,14 +187,14 @@ class caption_record implements caption_interface, cache_cacheableInterface
continue; continue;
$value = preg_replace( $value = preg_replace(
"(([^']{1})((https?|file):((/{2,4})|(\\{2,4}))[\w:#%/;$()~_?/\-=\\\.&]*)([^']{1}))" "(([^']{1})((https?|file):((/{2,4})|(\\{2,4}))[\w:#%/;$()~_?/\-=\\\.&]*)([^']{1}))"
, '$1 $2 <a title="' . _('Open the URL in a new window') . '" class="ui-icon ui-icon-extlink" href="$2" style="display:inline;padding:2px 5px;margin:0 4px 0 2px;" target="_blank"> &nbsp;</a>$7' , '$1 $2 <a title="' . _('Open the URL in a new window') . '" class="ui-icon ui-icon-extlink" href="$2" style="display:inline;padding:2px 5px;margin:0 4px 0 2px;" target="_blank"> &nbsp;</a>$7'
, $field->highlight_thesaurus() , $field->highlight_thesaurus()
); );
$fields[$field->get_name()] = array( $fields[$field->get_name()] = array(
'value' => $value 'value' => $value
, 'separator' => $field->get_databox_field()->get_separator() , 'separator' => $field->get_databox_field()->get_separator()
); );
} }

View File

@@ -749,11 +749,13 @@ class record_adapter implements record_Interface, cache_cacheableInterface
if ($data) if ($data)
{ {
if (isset($this->technical_datas[$data])) if (isset($this->technical_datas[$data]))
{
return $this->technical_datas[$data]; return $this->technical_datas[$data];
}
else else
{
return false; return false;
}
} }
return $this->technical_datas; return $this->technical_datas;
@@ -839,34 +841,39 @@ class record_adapter implements record_Interface, cache_cacheableInterface
{ {
$this->original_name = $original_name; $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; continue;
} }
/* @var $field caption_field */
/** /**
* Replacing original name in multi values is non sense * Replacing original name in multi values is non sense
*/ */
if (!$field->is_multi()) if (!$data_field->is_multi())
{ {
continue; continue;
} }
else
{
$value = array_pop($field->get_values());
$this->set_metadatas( try
array( {
'meta_struct_id' => $field->get_meta_struct_id() $field = $this->get_caption()->get_field($data_field->get_name())->get_meta_id();
, 'meta_id' => $value->getId() $value = array_pop($field->get_values());
, 'value' => $original_name $meta_id = $value->getId();
)
, true
);
} }
catch (\Exception $e)
{
$meta_id = null;
}
$metas = array(
'meta_struct_id' => $field->get_meta_struct_id()
, 'meta_id' => $meta_id
, 'value' => $original_name
);
$this->set_metadatas($metas, true);
} }
$sql = 'UPDATE record $sql = 'UPDATE record
@@ -1299,19 +1306,19 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$caption_field = new caption_field($databox_field, $this); $caption_field = new caption_field($databox_field, $this);
$vocab = $vocab_id = null; $vocab = $vocab_id = null;
if (isset($params['vocabularyId']) && $databox_field->getVocabularyControl()) if (isset($params['vocabularyId']) && $databox_field->getVocabularyControl())
{ {
try try
{ {
$vocab = $databox_field->getVocabularyControl(); $vocab = $databox_field->getVocabularyControl();
$vocab_id = $params['vocabularyId']; $vocab_id = $params['vocabularyId'];
$vocab->validate($vocab_id); $vocab->validate($vocab_id);
} }
catch (\Exception $e) catch (\Exception $e)
{ {
$vocab = $vocab_id = null; $vocab = $vocab_id = null;
} }
} }
@@ -1330,7 +1337,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
else else
{ {
$caption_field_value->set_value($params['value']); $caption_field_value->set_value($params['value']);
if($vocab && $vocab_id) if ($vocab && $vocab_id)
{ {
$caption_field_value->setVocab($vocab, $vocab_id); $caption_field_value->setVocab($vocab, $vocab_id);
} }
@@ -1357,7 +1364,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface
foreach ($metadatas as $param) foreach ($metadatas as $param)
{ {
if (!is_array($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']); $db_field = \databox_field::get_instance($this->get_databox(), $param['meta_struct_id']);
@@ -1489,8 +1498,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface
public function get_reg_name() public function get_reg_name()
{ {
if (!$this->is_grouping()) if (!$this->is_grouping())
{
return false; return false;
}
$balisename = ''; $balisename = '';
@@ -1633,8 +1643,48 @@ class record_adapter implements record_Interface, cache_cacheableInterface
, ':value' => $value , ':value' => $value
)); ));
} }
$stmt->closeCursor(); $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;
}
/**
* Replacing record_id in multi values is non sense
*/
if (!$data_field->is_multi())
{
continue;
}
try
{
$field = $record->get_caption()->get_field($data_field->get_name())->get_meta_id();
$value = array_pop($field->get_values());
$meta_id = $value->getId();
}
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; return $record;
} }
@@ -1686,7 +1736,6 @@ class record_adapter implements record_Interface, cache_cacheableInterface
{ {
$hd = $this->get_subdef('document'); $hd = $this->get_subdef('document');
if ($hd->is_physically_present()) if ($hd->is_physically_present())
return new system_file(p4string::addEndSlash($hd->get_path()) . $hd->get_file()); return new system_file(p4string::addEndSlash($hd->get_path()) . $hd->get_file());
return null; return null;
} }