Remove \databox_field::set_multi

This commit is contained in:
Romain Neutron
2012-06-26 13:41:29 +02:00
parent a9049b57ef
commit a73668e0ec
9 changed files with 276 additions and 436 deletions

View File

@@ -337,74 +337,6 @@ class caption_field implements cache_cacheableInterface
return;
}
protected static function merge_metadatas(databox_field $databox_field, record_adapter $record)
{
$sql = 'SELECT record_id, id, value FROM metadatas
WHERE meta_struct_id = :meta_struct_id
AND record_id = :record_id';
$params = array(
':meta_struct_id' => $databox_field->get_id(),
':record_id' => $record->get_record_id()
);
$stmt = $databox_field->get_databox()->get_connection()->prepare($sql);
$stmt->execute($params);
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
unset($stmt);
$values = $current_metadatas = array();
foreach ($rs as $row) {
$current_metadatas[] = array(
'meta_id' => $row['id']
, 'meta_struct_id' => $databox_field->get_id()
, 'value' => ''
);
$values[] = $row['value'];
}
try {
$record = $databox_field->get_databox()->get_record($record->get_record_id());
$record->set_metadatas($current_metadatas);
$record->set_metadatas(array(array(
'meta_id' => null
, 'meta_struct_id' => $databox_field->get_id()
, 'value' => implode(' ; ', $values)
)));
unset($record);
} catch (Exception $e) {
}
return;
}
public static function merge_all_metadatas(databox_field $databox_field)
{
$sql = 'SELECT distinct record_id FROM metadatas
WHERE meta_struct_id = :meta_struct_id ';
$params = array(
':meta_struct_id' => $databox_field->get_id()
);
$stmt = $databox_field->get_databox()->get_connection()->prepare($sql);
$stmt->execute($params);
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
unset($stmt);
foreach ($rs as $row) {
self::merge_metadatas($databox_field, $databox_field->get_databox()->get_record($row['record_id']));
}
return;
}
public static function delete_all_metadatas(databox_field $databox_field)
{
$sql = 'SELECT count(id) as count_id FROM metadatas

View File

@@ -858,7 +858,7 @@ class databox extends base
)
) ? $type : databox_field::TYPE_STRING;
$meta_struct_field = databox_field::create($this, $fname);
$meta_struct_field = databox_field::create($this, $fname, false);
$meta_struct_field
->set_readonly(isset($field['readonly']) ? $field['readonly'] : 0)
->set_indexable(isset($field['index']) ? $field['index'] : '1')
@@ -867,7 +867,6 @@ class databox extends base
->set_type($type)
->set_tbranch(isset($field['tbranch']) ? $field['tbranch'] : '')
->set_thumbtitle(isset($field['thumbtitle']) ? $field['thumbtitle'] : (isset($field['thumbTitle']) ? $field['thumbTitle'] : '0'))
->set_multi(isset($field['multi']) ? $field['multi'] : 0)
->set_report(isset($field['report']) ? $field['report'] : '1')
->save();

View File

@@ -104,7 +104,6 @@ class databox_field implements cache_cacheableInterface
*/
protected $Business;
protected $renamed = false;
protected $metaToMerge = false;
/**
*
@@ -365,11 +364,6 @@ class databox_field implements cache_cacheableInterface
$this->renamed = false;
}
if ($this->metaToMerge) {
caption_field::merge_all_metadatas($this);
$this->metaToMerge = false;
}
$dom_struct = $this->databox->get_dom_structure();
$xp_struct = $this->databox->get_xpath_structure();
@@ -595,26 +589,6 @@ class databox_field implements cache_cacheableInterface
return $this;
}
/**
*
* @param boolean $bool
* @return databox_field
*/
public function set_multi($multi)
{
$multi = ! ! $multi;
if ($this->multi !== $multi && ! $multi) {
$this->metaToMerge = true;
}
$this->multi = $multi;
$this->set_separator(';');
return $this;
}
/**
*
* @param boolean $bool
@@ -804,7 +778,7 @@ class databox_field implements cache_cacheableInterface
return $this->on_error;
}
public static function create(databox $databox, $name)
public static function create(databox $databox, $name, $multi)
{
$sorter = 0;
@@ -822,7 +796,7 @@ class databox_field implements cache_cacheableInterface
`thumbtitle`, `multi`, `business`,
`report`, `sorter`)
VALUES (null, :name, '', 0, 1, 'string', '',
null, 0,
null, :multi,
0, 1, :sorter)";
$name = self::generateName($name);
@@ -831,8 +805,10 @@ class databox_field implements cache_cacheableInterface
throw new \Exception_InvalidArgument();
}
$multi = $multi ? 1 : 0;
$stmt = $databox->get_connection()->prepare($sql);
$stmt->execute(array(':name' => $name, ':sorter' => $sorter));
$stmt->execute(array(':name' => $name, ':sorter' => $sorter, ':multi' => $multi));
$id = $databox->get_connection()->lastInsertId();
$stmt->closeCursor();