/[drupal]/contributions/modules/taxonomy_node_operations/taxonomy_node_operations.module
ViewVC logotype

Contents of /contributions/modules/taxonomy_node_operations/taxonomy_node_operations.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Thu Jul 12 05:52:28 2007 UTC (2 years, 4 months ago) by morrissinger
Branch: MAIN
CVS Tags: DRUPAL-5--1-0, HEAD
Branch point for: DRUPAL-5
File MIME type: text/x-php
Initial commit of taxonomy_node_operations module. This module adds the ability to assign terms to nodes in the node operations dropdown.
1 <?php
2 // $Id$
3
4 function taxonomy_node_operations_node_operations() {
5 $vocabularies = taxonomy_get_vocabularies();
6
7 $operations = array();
8
9 foreach($vocabularies as $vid => $vocabulary) {
10 $tree = taxonomy_get_tree($vid);
11 foreach($tree as $term) {
12 $operations[$term->tid] = array(
13 'label' => t('Taxonomy: Add to ') . $vocabulary->name . '->' . $term->name,
14 'callback' => 'taxonomy_node_operations_node_save',
15 'callback arguments' => array(
16 'term' => $term,
17 'vocabulary' => $vocabulary,
18 ),
19 );
20 }
21 }
22 if(!empty($operations)) {
23 $separator1 = array(
24 array(
25 'label' => '------------------ ' . t('Taxonomy') . ' ------------------',
26 ),
27 );
28 $separator2 = array(
29 array(
30 'label' => '----------------------------------------------',
31 ),
32 );
33
34 $operations = array_merge($separator1, $operations, $separator2);
35 }
36
37 return $operations;
38 }
39
40 function taxonomy_node_operations_node_save($nodes, $term, $vocabulary) {
41 foreach((array)$nodes as $nid => $node) {
42 $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));
43 db_query('DELETE FROM {term_node} WHERE nid = %d AND tid = %d', $nid, $tid);
44 }
45
46 $terms = taxonomy_node_get_terms($nid);
47
48 $tids = array();
49 foreach(array_keys($terms) as $tid) {
50 $tids[$tid] = $tid;
51 }
52 $tids[$term->tid] = $term->tid;
53
54 $tids = array_unique($tids);
55
56 taxonomy_node_save($nid, $tids);
57
58 drupal_set_message(t('The nodes have been !a to the %t term.', array('!a' => ($vocabulary->multiple ? t('added') : t('moved')), '%t' => $term->name)));
59 }

  ViewVC Help
Powered by ViewVC 1.1.2