function taxonomy_manager_term_data_edit in Taxonomy Manager 6
Same name and namespace in other branches
- 5 taxonomy_manager.module \taxonomy_manager_term_data_edit()
- 6.2 taxonomy_manager.admin.inc \taxonomy_manager_term_data_edit()
callback handler for updating term data
Parameters
$vid:
1 string reference to 'taxonomy_manager_term_data_edit'
- taxonomy_manager_menu in ./
taxonomy_manager.module - Implementation of hook_menu
File
- ./
taxonomy_manager.admin.inc, line 994
Code
function taxonomy_manager_term_data_edit() {
$param = $_POST;
$tid = $param['tid'];
if (!$tid) {
$tid = $param['term_data']['tid'];
}
$values = $param['value'];
$attr_type = $param['attr_type'];
$op = $param['op'];
if ($op == "Save changes") {
db_query("UPDATE {term_data} SET name = '%s' WHERE tid = %d", $param['term_data']['name'], $tid);
db_query("UPDATE {term_data} SET description = '%s' WHERE tid = %d", $param['term_data']['description'], $tid);
}
$term = taxonomy_get_term($tid);
$vid = $term->vid;
if ($op == 'add') {
if ($attr_type == 'synonym') {
$regexp = '%(?:^|,\\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x';
preg_match_all($regexp, $values, $matches);
$synonyms = array_unique($matches[1]);
$values = array();
foreach ($synonyms as $syn) {
$values[] = trim($syn);
}
}
else {
$typed_term_tids = array();
$typed_term_tids = taxonomy_manager_autocomplete_tags_get_tids($values, $term->vid);
$values = array();
foreach ($typed_term_tids as $term_info) {
$values[] = $term_info['tid'];
}
}
}
switch ($attr_type) {
case 'parent':
if (!is_array($values)) {
$values = array(
$values,
);
}
foreach ($values as $value) {
db_query("DELETE FROM {term_hierarchy} WHERE parent = %d AND tid = %d", $value, $tid);
if ($op == 'add') {
db_query("INSERT INTO {term_hierarchy} (parent, tid) VALUES (%d, %d)", $value, $tid);
}
}
if ($op == 'delete') {
$parents = taxonomy_get_parents($tid);
if (count($parents) == 0) {
//ensure that a term has a least parent 0
db_query("DELETE FROM {term_hierarchy} WHERE parent = 0 AND tid = %d", $tid);
db_query("INSERT INTO {term_hierarchy} (parent, tid) VALUES (0, %d)", $tid);
}
}
else {
if ($op == 'add') {
db_query("DELETE FROM {term_hierarchy} WHERE parent = 0 AND tid = %d", $tid);
}
}
taxonomy_manager_update_voc($vid, taxonomy_get_parents($tid));
break;
case 'related':
if (!is_array($values)) {
$values = array(
$values,
);
}
foreach ($values as $value) {
if ($value != 0) {
db_query("DELETE FROM {term_relation} WHERE tid1 = %d AND tid2 = %d", $tid, $value);
// db_query("DELETE FROM {term_relation} WHERE tid2 = %d AND tid1 = %d", $tid, $value);
if ($op == 'add') {
db_query('INSERT INTO {term_relation} (tid1, tid2) VALUES (%d, %d)', $tid, $value);
}
}
}
break;
case 'synonym':
if (!is_array($values)) {
$values = array(
$values,
);
}
foreach ($values as $value) {
db_query("DELETE FROM {term_synonym} WHERE tid = %d AND name = '%s'", $tid, $value);
if ($op == 'add') {
db_query("INSERT INTO {term_synonym} (tid, name) VALUES (%d, '%s')", $tid, $value);
}
}
break;
case 'weight':
if (is_numeric($values)) {
db_query("UPDATE {term_data} SET weight = %d WHERE tid = %d", $values, $tid);
}
break;
}
$term = (array) taxonomy_get_term($tid);
$term['fields'] = $param['term_data']['fields'];
module_invoke_all('taxonomy', 'update', 'term', $term);
module_invoke_all('taxonomy_manager_term_data_submit', $param, $values);
drupal_json(array(
'data' => taxonomy_manager_update_term_data_form($vid, $tid, TRUE, FALSE),
));
//taxonomy_manager_update_term_data_form($vid, $tid, TRUE);
exit;
}