Index: modules/taxonomy.module =================================================================== RCS file: /cvs/drupal/drupal/modules/taxonomy.module,v retrieving revision 1.167 diff -u -F^f -r1.167 taxonomy.module --- modules/taxonomy.module 17 Jan 2005 19:00:03 -0000 1.167 +++ modules/taxonomy.module 18 Jan 2005 20:44:30 -0000 @@ -123,7 +123,7 @@ function taxonomy_form_vocabulary($edit $form .= form_textfield(t('Vocabulary name'), 'name', $edit['name'], 50, 64, t('The name for this vocabulary. Example: "Topic".'), NULL, TRUE); $form .= form_textarea(t('Description'), 'description', $edit['description'], 60, 5, t('Description of the vocabulary; can be used by modules.')); $form .= form_textfield(t('Help text'), 'help', $edit['help'], 50, 255, t('Instructions to present to the user when choosing a term.')); - $form .= form_checkboxes(t('Types'), 'nodes', explode(',', $edit['nodes']), $nodetypes, t('A list of node types you want to associate with this vocabulary.'), NULL, TRUE); + $form .= form_checkboxes(t('Types'), 'nodes', $edit['nodes'], $nodetypes, t('A list of node types you want to associate with this vocabulary.'), NULL, TRUE); $form .= form_checkbox(t('Related terms'), 'relations', 1, $edit['relations'], t('Allows related terms in this vocabulary.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'related-terms')))); $form .= form_radios(t('Hierarchy'), 'hierarchy', $edit['hierarchy'], array(t('Disabled'), t('Single'), t('Multiple')), t('Allows a tree-like hierarchy between terms of this vocabulary.', array('%help-url' => url('admin/help/taxonomy', NULL, NULL, 'hierarchy')))); $form .= form_checkbox(t('Multiple select'), 'multiple', 1, $edit['multiple'], t('Allows nodes to have more than one term in this vocabulary.')); @@ -144,9 +144,13 @@ function taxonomy_save_vocabulary($edit) $edit['nodes'] = array(); } - $data = array('name' => $edit['name'], 'nodes' => implode(',', $edit['nodes']), 'description' => $edit['description'], 'help' => $edit['help'], 'multiple' => $edit['multiple'], 'required' => $edit['required'], 'hierarchy' => $edit['hierarchy'], 'relations' => $edit['relations'], 'weight' => $edit['weight']); + $data = array('name' => $edit['name'], 'description' => $edit['description'], 'help' => $edit['help'], 'multiple' => $edit['multiple'], 'required' => $edit['required'], 'hierarchy' => $edit['hierarchy'], 'relations' => $edit['relations'], 'weight' => $edit['weight']); if ($edit['vid'] && $edit['name']) { db_query('UPDATE {vocabulary} SET '. _taxonomy_prepare_update($data) .' WHERE vid = %d', $edit['vid']); + db_query("DELETE FROM {vocabulary_node} WHERE vid = %d", $edit['vid']); + foreach ($edit['nodes'] as $type) { + db_query("INSERT INTO {vocabulary_node} (vid, type) VALUES (%d, '%s')", $edit['vid'], $type); + } module_invoke_all('taxonomy', 'update', 'vocabulary', $edit); $message = t('Updated vocabulary %name.', array('%name' => ''. $edit['name'] .'')); } @@ -156,6 +160,9 @@ function taxonomy_save_vocabulary($edit) else { $data['vid'] = $edit['vid'] = db_next_id('{vocabulary}_vid'); db_query('INSERT INTO {vocabulary} '. _taxonomy_prepare_insert($data, 1) .' VALUES '. _taxonomy_prepare_insert($data, 2)); + foreach ($edit['nodes'] as $type) { + db_query("INSERT INTO {vocabulary_node} (vid, type) VALUES (%d, '%s')", $edit['vid'], $type); + } module_invoke_all('taxonomy', 'insert', 'vocabulary', $edit); $message = t('Created new vocabulary %name.', array('%name' => ''. $edit['name'] .'')); } @@ -171,6 +178,7 @@ function taxonomy_del_vocabulary($vid) { $vocabulary = taxonomy_get_vocabulary($vid); db_query('DELETE FROM {vocabulary} WHERE vid = %d', $vid); + db_query('DELETE FROM {vocabulary_node} WHERE vid = %d', $vid); $result = db_query('SELECT tid FROM {term_data} WHERE vid = %d', $vid); while ($term = db_fetch_object($result)) { taxonomy_del_term($term->tid); @@ -350,7 +358,7 @@ function taxonomy_overview() { foreach ($vocabularies as $vocabulary) { $links = array(); $types = array(); - foreach(explode(',', $vocabulary->nodes) as $type) { + foreach($vocabulary->nodes as $type) { $types[] = node_invoke($type, 'node_name'); } $rows[] = array($vocabulary->name, array('data' => implode(', ', $types), 'align' => 'center'), l(t('edit vocabulary'), "admin/taxonomy/edit/vocabulary/$vocabulary->vid"), l(t('add term'), "admin/taxonomy/add/term/$vocabulary->vid"), l(t('preview form'), "admin/taxonomy/preview/vocabulary/$vocabulary->vid")); @@ -389,23 +397,50 @@ function taxonomy_form($vid, $value = 0, } /** - * Return an array of all vocabulary objects. + * Return an array of vocabulary objects. * * @param $type * If set, return only those vocabularies associated with this node type. + * @param $vid + * If set, return only that vocabulary associated with this vocabulary ID. */ -function taxonomy_get_vocabularies($type = '', $key = 'vid') { +function taxonomy_get_vocabularies($type = NULL, $vid =NULL) { + static $all_vocabularies = array(); + if ($type) { - $result = db_query("SELECT * FROM {vocabulary} WHERE nodes LIKE '%%%s%%' ORDER BY weight, name", $type); + if (isset($all_vocabularies['type'][$type])) { + return $all_vocabularies['type'][$type]; + } + $query = 'type'; + $query_argument = $type; + $result = db_query("SELECT v.*, n.type FROM {vocabulary_node} n INNER JOIN {vocabulary} v ON v.vid = n.vid WHERE n.type = '%s' ORDER BY v.weight, v.name", $type); + } + elseif ($vid) { + if (isset($all_vocabularies['vid'][$vid])) { + return $all_vocabularies['vid'][$vid]; + } + $query = 'vid'; + $query_argument = $vid; + $result = db_query('SELECT v.*, n.type FROM {vocabulary_node} n INNER JOIN {vocabulary} v ON v.vid = n.vid WHERE v.vid = %d ORDER BY v.weight, v.name', $vid); } else { - $result = db_query('SELECT * FROM {vocabulary} ORDER BY weight, name'); + if (isset($all_vocabularies['all']['none'])) { + return $all_vocabularies['all']['none']; + } + $query = 'all'; + $query_argument = 'none'; + $result = db_query('SELECT v.*, n.type FROM {vocabulary_node} n INNER JOIN {vocabulary} v ON v.vid = n.vid ORDER BY v.weight, v.name'); } $vocabularies = array(); + $node_types = array(); while ($voc = db_fetch_object($result)) { - $vocabularies[$voc->$key] = $voc; + $node_types[$voc->vid][] = $voc->type; + unset($voc->type); + $voc->nodes = $node_types[$voc->vid]; + $vocabularies[$voc->vid] = $voc; } + $all_vocabularies[$query][$query_argument] = $vocabularies; return $vocabularies; } @@ -425,7 +460,7 @@ function taxonomy_node_form($type, $node $terms = $node->taxonomy; } - $c = db_query("SELECT * FROM {vocabulary} WHERE nodes LIKE '%%%s%%' ORDER BY weight, name", $type); + $c = db_query("SELECT v.*, n.type FROM {vocabulary} v INNER JOIN {vocabulary_node} n ON v.vid = n.vid WHERE n.type = '%s' ORDER BY v.weight, v.name", $type); while ($vocabulary = db_fetch_object($c)) { $result[] = taxonomy_form($vocabulary->vid, $terms, $help, $name); } @@ -690,10 +725,12 @@ function _taxonomy_term_children($tid) { * An array of matching vocabulary objects. */ function taxonomy_get_vocabulary_by_name($name) { - $db_result = db_query("SELECT * FROM {vocabulary} WHERE LOWER('%s') LIKE LOWER(name)", trim($name)); + $db_result = db_query("SELECT v.*, n.type FROM {vocabulary} v INNER JOIN {vocabulary_node} n ON v.vid= n.vid WHERE LOWER('%s') LIKE LOWER(v.name)", trim($name)); $result = array(); + $node_types = array(); while ($vocabulary = db_fetch_object($db_result)) { - $result[] = $vocabulary; + $node_types[$vocabulary->vid][] = $vocabulary->type; + $result[$vocabulary->vid] = $vocabulary; } return $result; @@ -725,7 +762,8 @@ function taxonomy_get_term_by_name($name * Return the vocabulary object matching a vocabulary ID. */ function taxonomy_get_vocabulary($vid) { - return db_fetch_object(db_query('SELECT * FROM {vocabulary} WHERE vid = %d', $vid)); + $vocabularies = taxonomy_get_vocabularies(NULL, $vid); + return $vocabularies[$vid]; } /** Index: database/database.mysql =================================================================== RCS file: /cvs/drupal/drupal/database/database.mysql,v retrieving revision 1.165 diff -u -F^f -r1.165 database.mysql --- database/database.mysql 14 Jan 2005 17:29:41 -0000 1.165 +++ database/database.mysql 18 Jan 2005 20:44:30 -0000 @@ -755,6 +755,16 @@ ) TYPE=MyISAM; -- +-- Table structure for table 'vocabulary_node' +-- + +CREATE TABLE vocabulary_node ( + vid int(10) unsigned NOT NULL DEFAULT '', + type varchar(16) NOT NULL DEFAULT '', + PRIMARY KEY (vid, type) +) TYPE=MyISAM; + +-- -- Table structure for table 'watchdog' -- Index: database/database.pgsql =================================================================== RCS file: /cvs/drupal/drupal/database/database.pgsql,v retrieving revision 1.101 diff -u -F^f -r1.101 database.pgsql --- database/database.pgsql 14 Jan 2005 17:29:41 -0000 1.101 +++ database/database.pgsql 18 Jan 2005 20:44:30 -0000 @@ -742,6 +742,16 @@ ); -- +-- Table structure for vocabulary_node +-- + +CREATE TABLE vocabulary_node ( + vid integer NOT NULL default '0', + type varchar(16) NOT NULL default '', + PRIMARY KEY (vid, type) +); + +-- -- Table structure for watchdog --