Moved vocabulary to Alchemy namespace

This commit is contained in:
Romain Neutron
2012-01-23 18:18:49 +01:00
parent 7b1e98ce6c
commit a4c103fa42
3 changed files with 238 additions and 193 deletions

View File

@@ -117,6 +117,27 @@ class caption_Field_Value
return $this; return $this;
} }
public function setVocab(\Alchemy\Phrasea\Vocabulary\ControlProvider\ControlProviderInterface $vocabulary, $vocab_id)
{
$params = array(
':VocabType' => $vocabulary->getType()
, ':VocabularyId' => $vocab_id
);
$sql_up = 'UPDATE metadatas
SET VocabularyType = :VocabType, VocabularyId = :VocabularyId
WHERE id = :meta_id';
$stmt_up = $connbas->prepare($sql_up);
$stmt_up->execute($params);
$stmt_up->closeCursor();
$this->set_value($vocabulary->getValue($vocab_id));
return $this;
}
public function set_value($value) public function set_value($value)
{ {
$sbas_id = $this->databox_field->get_databox()->get_sbas_id(); $sbas_id = $this->databox_field->get_databox()->get_sbas_id();
@@ -206,21 +227,24 @@ class caption_Field_Value
return $this; return $this;
} }
public static function create(databox_field &$databox_field, record_Interface $record, $value) public static function create(databox_field &$databox_field, record_Interface $record, $value, \Alchemy\Phrasea\Vocabulary\ControlProvider\ControlProviderInterface $vocabulary = null, $vocabularyId = null)
{ {
$sbas_id = $databox_field->get_databox()->get_sbas_id(); $sbas_id = $databox_field->get_databox()->get_sbas_id();
$connbas = $databox_field->get_connection(); $connbas = $databox_field->get_connection();
$sql_ins = 'INSERT INTO metadatas (id, record_id, meta_struct_id, value) $sql_ins = 'INSERT INTO metadatas
(id, record_id, meta_struct_id, value, VocabularyType, VocabularyId)
VALUES VALUES
(null, :record_id, :field, :value)'; (null, :record_id, :field, :value, :VocabType, :VocabId)';
$stmt_ins = $connbas->prepare($sql_ins); $stmt_ins = $connbas->prepare($sql_ins);
$stmt_ins->execute( $stmt_ins->execute(
array( array(
':record_id' => $record->get_record_id(), ':record_id' => $record->get_record_id(),
':field' => $databox_field->get_id(), ':field' => $databox_field->get_id(),
':value' => $value ':value' => $value,
':VocabType' => $vocabulary ? $vocabulary->getType() : null,
':VocabId' => $vocabulary ? $vocabularyId : null,
) )
); );
$stmt_ins->closeCursor(); $stmt_ins->closeCursor();

View File

@@ -185,7 +185,7 @@ class databox_field implements cache_cacheableInterface
try try
{ {
$this->Vocabulary = databox_Field_VocabularyControl::get($row['VocabularyControlType']); $this->Vocabulary = \Alchemy\Phrasea\Vocabulary\Controller::get($row['VocabularyControlType']);
$this->VocabularyRestriction = !!$row['RestrictToVocabularyControl']; $this->VocabularyRestriction = !!$row['RestrictToVocabularyControl'];
} }
catch (Exception $e) catch (Exception $e)
@@ -498,7 +498,7 @@ class databox_field implements cache_cacheableInterface
return $this; return $this;
} }
public function setVocabularyControl(databox_Field_VocabularyControl_Interface $vocabulary = null) public function setVocabularyControl(\Alchemy\Phrasea\Vocabulary\ControlProvider\ControlProviderInterface $vocabulary = null)
{ {
$this->Vocabulary = $vocabulary; $this->Vocabulary = $vocabulary;

View File

@@ -1284,6 +1284,23 @@ 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;
if ($params['vocabularyId'] && $databox_field->getVocabularyControl())
{
try
{
$vocab = $databox_field->getVocabularyControl();
$vocab_id = $params['vocabularyId'];
$vocab->validate($vocab_id);
}
catch (\Exception $e)
{
$vocab = $vocab_id = null;
}
}
if (trim($params['meta_id']) !== '') if (trim($params['meta_id']) !== '')
{ {
$tmp_val = trim($params['value']); $tmp_val = trim($params['value']);
@@ -1298,11 +1315,15 @@ 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)
{
$caption_field_value->setVocab($vocab, $vocab_id);
}
} }
} }
else else
{ {
$caption_field_value = caption_Field_Value::create($databox_field, $this, $params['value']); $caption_field_value = caption_Field_Value::create($databox_field, $this, $params['value'], $vocab, $vocab_id);
} }
$this->caption_record = null; $this->caption_record = null;