--- unique_field.module.orig 2009-03-31 10:30:11.000000000 +1000 +++ unique_field.module 2009-03-31 13:36:28.000000000 +1000 @@ -29,6 +29,7 @@ define('UNIQUE_FIELD_COMP_ALL', 'all'); // query field definitions define('UNIQUE_FIELD_FIELDS_TITLE', 'title'); define('UNIQUE_FIELD_FIELDS_AUTHOR', 'name'); +define('UNIQUE_FIELD_FIELDS_TAXONOMY', 'taxonomy_'); // setting definition define('UNIQUE_FIELD_SHOW_MATCHES', 'show_matches'); @@ -127,6 +128,15 @@ function unique_field_nodeapi(&$node, $o else if ($field == UNIQUE_FIELD_FIELDS_AUTHOR) { $values = $node->uid; } + elseif (strpos($field, UNIQUE_FIELD_FIELDS_TAXONOMY) === 0) { + $vid = str_replace(UNIQUE_FIELD_FIELDS_TAXONOMY, '', $field); + $values = array(); + foreach ($node->taxonomy as $vocabulary => $terms) { + if ($vocabulary == $vid) { + $values = array_merge($values, $terms); + } + } + } else { // if cck_field_perms is enabled and the current user is // not permitted to access a field, then the field data is cleared @@ -175,6 +185,11 @@ function unique_field_nodeapi(&$node, $o else if ($field == UNIQUE_FIELD_FIELDS_AUTHOR) { $labels[$field] = t('Author'); } + elseif (strpos($field, UNIQUE_FIELD_FIELDS_TAXONOMY) === 0) { + $vid = str_replace(UNIQUE_FIELD_FIELDS_TAXONOMY, '', $field); + $vocabulary = taxonomy_get_vocabulary($vid); + $labels[$field] = $vocabulary->name; + } else { $fld = content_fields($field, $node->type); $labels[$field] = $fld['widget']['label']; @@ -208,6 +223,7 @@ function unique_field_match_value($field // initialize query variables $qtbl = ''; $qwhere = ''; + $qjoinfield = 'vid'; // Only needed for D5 // generate query where clause for title field if ($field === UNIQUE_FIELD_FIELDS_TITLE) { @@ -218,6 +234,13 @@ function unique_field_match_value($field else if ($field === UNIQUE_FIELD_FIELDS_AUTHOR) { $qwhere = "node.uid = '". intval($values) ."' "; } + + // generate query where clause for taxonomy term + elseif (strpos($field, UNIQUE_FIELD_FIELDS_TAXONOMY) === 0) { + $qtbl = 'term_node'; + $qjoinfield = 'nid'; // Only needed for D5 + $qwhere = "term_node.tid = '". implode("' OR term_node.tid = '", $values) ."' "; + } // generate query where clause for a CCK field else { @@ -282,7 +305,7 @@ function unique_field_match_value($field // do query $q = "SELECT node.nid FROM {node} node "; if (!empty($qtbl)) { - $q .= "JOIN {". $qtbl ."} AS ". $qtbl ." USING (vid) "; + $q .= "JOIN {". $qtbl ."} AS ". $qtbl ." USING (". $qjoinfield .") "; } $q .= "WHERE ". $qwhere; $res = db_query($q); @@ -313,6 +336,14 @@ function unique_field_node_settings_form } } } + if (module_exists('taxonomy')) { + $vocabularies = taxonomy_get_vocabularies($ntype); + if (is_array($vocabularies)) { + foreach ($vocabularies as $vocabulary) { + $fieldopts[UNIQUE_FIELD_FIELDS_TAXONOMY . $vocabulary->vid] = 'Taxonomy: Terms for '. $vocabulary->name; + } + } + } // build the form $form['unique_field'] = array(