diff -Naurx .svn taxonomy_node_operations.info taxonomy_node_operations/taxonomy_node_operations.info --- taxonomy_node_operations.info 2007-07-12 10:50:52.000000000 -0400 +++ taxonomy_node_operations/taxonomy_node_operations.info 2008-05-22 05:53:12.000000000 -0400 @@ -1,9 +1,10 @@ ;$Id: taxonomy_node_operations.info,v 1.1 2007/07/12 05:52:28 morrissinger Exp $ name = Taxonomy Node Operations description = Adds the ability to assign terms to nodes in the node operations dropdown in admin/content/node. -dependencies = taxonomy +dependencies[] = taxonomy ; Information added by drupal.org packaging script on 2007-07-12 -version = "5.x-1.1" +version = "6.x-2.0" +core = "6.x" project = "taxonomy_node_operations" datestamp = "1184251852" diff -Naurx .svn taxonomy_node_operations.module taxonomy_node_operations/taxonomy_node_operations.module --- taxonomy_node_operations.module 2007-07-12 10:47:09.000000000 -0400 +++ taxonomy_node_operations/taxonomy_node_operations.module 2008-05-22 14:49:23.000000000 -0400 @@ -1,61 +1,89 @@ $vocabulary) { - $tree = taxonomy_get_tree($vid); - foreach($tree as $term) { - $operations[$term->tid] = array( - 'label' => t('Taxonomy: Add to ') . $vocabulary->name . '->' . $term->name, - 'callback' => 'taxonomy_node_operations_node_save', + $vocabularies = taxonomy_get_vocabularies(); + + $operations = array(); + + foreach($vocabularies as $vid => $vocabulary) { + $operations[]=array( + 'label' => t('Vocabulary')." '".$vocabulary->name."'", + ); + if ($vocabulary->multiple) { + $operation="add"; + } else { + $operation="change to"; + } + $tree = taxonomy_get_tree($vid); + foreach($tree as $term) { + $operations['add_'.$term->tid] = array( + 'label' => t('--- '.$operation.' ') .' ' . $term->name, + 'callback' => 'taxonomy_node_operations_add_term', + 'callback arguments' => array( + 'term' => $term, + 'vocabulary' => $vocabulary, + ), + ); + if ($vocabulary->multiple) { + $operations['delete_'.$term->tid] = array( + 'label' => t('--- Delete ') . $term->name, + 'callback' => 'taxonomy_node_operations_remove_term', 'callback arguments' => array( 'term' => $term, 'vocabulary' => $vocabulary, - ), - ); - } - } - if(!empty($operations)) { - $separator1 = array( - array( - 'label' => '------------------ ' . t('Taxonomy') . ' ------------------', - ), - ); - $separator2 = array( - array( - 'label' => '----------------------------------------------', - ), - ); - - $operations = array_merge($separator1, $operations, $separator2); - } - - return $operations; + ), + ); + } + } + } + return $operations; +} + +function debug_query($query) { + $args = func_get_args(); + array_shift($args); + $query = db_prefix_tables($query); + if (isset($args[0]) and is_array($args[0])) { // 'All arguments in one array' syntax + $args = $args[0]; + } + _db_query_callback($args, TRUE); + $query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query); + error_log($query); + return db_query($query,$args); +} + +function taxonomy_node_operations_add_term($nodes, $term, $vocabulary) { + foreach((array)$nodes as $nid) { + $node=node_load($nid); + $tmp = taxonomy_node_get_terms($node); + $terms=array(); + foreach ($tmp as $node_term) { + if ($vocabulary->multiple || $node_term->vid!=$vocabulary->vid) { + $terms[]=$node_term; + } + } + $terms[$term->tid]=$term; + taxonomy_node_save($node, $terms); + } + drupal_set_message(t('The nodes have been !a to the %t term.', array('!a' => ($vocabulary->multiple ? t('added') : t('moved')), '%t' => $term->name))); } -function taxonomy_node_operations_node_save($nodes, $term, $vocabulary) { - foreach((array)$nodes as $nid => $node) { - if(!$vocabulary->multiple) { - $tid = db_result(db_query("SELECT tn.tid FROM {term_node} tn INNER JOIN {term_data} td ON tn.tid=td.tid WHERE tn.nid = %d AND td.vid = %d", $nid, $vocabulary->vid)); - db_query('DELETE FROM {term_node} WHERE nid = %d AND tid = %d', $nid, $tid); - } - - $terms = taxonomy_node_get_terms($nid); - - $tids = array(); - foreach(array_keys($terms) as $tid) { - $tids[$tid] = $tid; - } - $tids[$term->tid] = $term->tid; - - $tids = array_unique($tids); - - taxonomy_node_save($nid, $tids); - } - - drupal_set_message(t('The nodes have been !a to the %t term.', array('!a' => ($vocabulary->multiple ? t('added') : t('moved')), '%t' => $term->name))); +function taxonomy_node_operations_remove_term($nodes, $term, $vocabulary) { + foreach((array)$nodes as $nid) { + $node=node_load($nid); + $tmp = taxonomy_node_get_terms($node); + $terms=array(); + foreach ($tmp as $node_term) { + if ($term->tid!=$node_term->tid) { + $terms[]=$node_term; + } + } + taxonomy_node_save($node, $terms); + } + drupal_set_message(t('The nodes have removed from %t term.', array('%t' => $term->name))); } \ No newline at end of file