? suggestedterms-allterms.patch
Index: suggestedterms.install
===================================================================
RCS file: /cvs/drupal/contributions/modules/suggestedterms/suggestedterms.install,v
retrieving revision 1.2
diff -u -p -r1.2 suggestedterms.install
--- suggestedterms.install	9 Oct 2008 17:16:13 -0000	1.2
+++ suggestedterms.install	20 May 2009 19:41:58 -0000
@@ -1,5 +1,10 @@
 <?php
-/* $Id: suggestedterms.install,v 1.2 2008/10/09 17:16:13 crell Exp $ */
+// $Id: suggestedterms.install,v 1.2 2008/10/09 17:16:13 crell Exp $
+
+/**
+ * @file
+ * Install, update and uninstall functions for the suggestedterms.
+ */
 
 function suggestedterms_install() {
   // Always make sure this module runs after taxonomy does.
Index: suggestedterms.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/suggestedterms/suggestedterms.module,v
retrieving revision 1.2.2.3
diff -u -p -r1.2.2.3 suggestedterms.module
--- suggestedterms.module	9 Oct 2008 17:58:17 -0000	1.2.2.3
+++ suggestedterms.module	20 May 2009 19:41:58 -0000
@@ -1,14 +1,27 @@
 <?php
-/* $Id: suggestedterms.module,v 1.2.2.3 2008/10/09 17:58:17 crell Exp $ */
+// $Id$ : suggestedterms.module,v 1.2.2.3 2008/10/09 17:58:17 crell Exp $
 
 /**
-* define constants
-*/
-//
+ * @file
+ * A module to add to the free-tagging Taxonomy system already in place
+ *
+ * This module provides "suggested terms" for free-tagging Taxonomy
+ * fields based on terms already submitted. It replaces the description
+ * field on free-tagging fields with a clickable list of previously
+ * entered terms.
+ */
+
+
+/**
+ * define constants.
+ */
 define('SUGGESTEDTERMS_SORT_NAME', 1);
 define('SUGGESTEDTERMS_SORT_POPULAR', 0);
 define('SUGGESTEDTERMS_SORT_RECENT', 2);
 
+define('SUGGESTEDTERMS_DISPLAY_ALL', 1);
+define('SUGGESTEDTERMS_DISPLAY_USED', 0);
+
 /**
  * Implementation of hook_help().
  */
@@ -17,7 +30,7 @@ function suggestedterms_help($path, $arg
 
   switch ($path) {
     case "admin/help#suggestedterms":
-      $output = '<p>'.  t("Replaces the default \'description\' text on free-tagging textfields on node edit pages with a list of taxonomy terms in that vocabulary, with appropriate labeling"). '</p>';
+      $output = '<p>'. t("Replaces the default \'description\' text on free-tagging textfields on node edit pages with a list of taxonomy terms in that vocabulary, with appropriate labeling") .'</p>';
       break;
   }
 
@@ -44,7 +57,7 @@ function suggestedterms_theme() {
 
 /**
  * Build tags for each term.
- * 
+ *
  * @ingroup themeable
  * @param $name
  *   The term name to theme.
@@ -57,31 +70,33 @@ function theme_suggestedterm($name) {
 }
 
 /**
-* Creates all spans from vocabulary terms
-* 
-* @return 
-*   A string containing the clickable spans for the suggestedterms module.
-*/
-function _suggestedterms_build_suggestions($vid, $sort_order) {
+ * Creates all spans from vocabulary terms
+ *
+ * @return
+ *   A string containing the clickable spans for the suggestedterms module.
+ */
+function _suggestedterms_build_suggestions($vid, $sort_order, $show_terms) {
+  // use left join to display all entries, inner join to diaplay only used ones
+  $query_type = ($show_terms == SUGGESTEDTERMS_DISPLAY_ALL) ? " LEFT " : " INNER ";
   // get total terms set by admin
   $total_terms = variable_get('suggestedterms_maximum_displayed', 5);
   // get sort order set by admin
   switch ($sort_order) {
     case SUGGESTEDTERMS_SORT_POPULAR:
-      $query = "SELECT t.name AS name, COUNT(t.name) AS total FROM {term_data} t INNER JOIN {term_node} n ON (t.tid = n.tid) WHERE t.vid = %d GROUP BY t.name ORDER BY total desc";
+      $query = "SELECT t.name AS name, COUNT(t.name) AS total FROM {term_data} t $query_type JOIN {term_node} n ON (t.tid = n.tid) WHERE t.vid = %d GROUP BY t.name ORDER BY total desc";
       break;
 
     case SUGGESTEDTERMS_SORT_RECENT:
-      $query = "SELECT t.name AS name FROM {term_data} t INNER JOIN {term_node} n ON (t.tid = n.tid) WHERE t.vid = %d GROUP BY t.name ORDER BY t.tid desc";
+      $query = "SELECT t.name AS name FROM {term_data} t $query_type JOIN {term_node} n ON (t.tid = n.tid) WHERE t.vid = %d GROUP BY t.name ORDER BY t.tid desc";
       break;
 
     default:
-      $query = "SELECT t.name AS name FROM {term_data} t INNER JOIN {term_node} n ON (t.tid = n.tid) WHERE t.vid = %d GROUP BY t.name ORDER BY t.name";
+      $query = "SELECT t.name AS name FROM {term_data} t $query_type JOIN {term_node} n ON (t.tid = n.tid) WHERE t.vid = %d GROUP BY t.name ORDER BY t.name";
       break;
   }
   $query_result = ($total_terms > 0) ? db_query_range($query, $vid, 0, $total_terms) : db_query($query, $vid);
   $terms = array();
-  while($record = db_fetch_object($query_result)) {
+  while ($record = db_fetch_object($query_result)) {
     $terms[] = theme('suggestedterm', check_plain($record->name));
   }
   return implode(', ', $terms);
@@ -93,14 +108,16 @@ function _suggestedterms_build_suggestio
 function suggestedterms_form_alter(&$form, $form_state, $form_id) {
   if ((isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) && isset($form['taxonomy']['tags'])) {
     $path = drupal_get_path('module', 'suggestedterms');
-    drupal_add_js($path . '/suggestedterms.js');
+    drupal_add_js($path .'/suggestedterms.js');
+    //Added this to be able to display all terms, including the ones that are not used by a node
+    $show_terms = variable_get('suggestedterms_display_all', SUGGESTEDTERMS_DISPLAY_ALL);
     // If multiple vocabularies, loop over each.
     foreach ($form['taxonomy']['tags'] as $vid => $thisindex) {
       // If free-tagging taxonomy is true, add new links for each free-tag textfield.
       $sort_order = variable_get('suggestedterms_sort_order', SUGGESTEDTERMS_SORT_NAME);
       switch ($sort_order) {
         case SUGGESTEDTERMS_SORT_POPULAR:
-	      $tag_description = 'Most popular terms';
+        $tag_description = 'Most popular terms';
           break;
 
         case SUGGESTEDTERMS_SORT_RECENT:
@@ -112,7 +129,7 @@ function suggestedterms_form_alter(&$for
           break;
       }
       // Build the suggested terms and set in description tag.
-      $form['taxonomy']['tags'][$vid]['#description'] .= "<br />\n". t($tag_description) . ': ' . _suggestedterms_build_suggestions($vid, $sort_order);
+      $form['taxonomy']['tags'][$vid]['#description'] .= "<br />\n". t($tag_description) .': '. _suggestedterms_build_suggestions($vid, $sort_order, $show_terms);
     }
   }
 }
@@ -139,7 +156,17 @@ function suggestedterms_admin() {
       SUGGESTEDTERMS_SORT_POPULAR => t('Most used'),
       SUGGESTEDTERMS_SORT_NAME => t('Alphabetically'),
       SUGGESTEDTERMS_SORT_RECENT => t('Most recently added'),
-     ),
+    ),
+  );
+  $form['suggestedterms_display_all'] = array(
+    '#type' => 'radios',
+    '#title' => t('Which terms to display'),
+    '#default_value' => variable_get('suggestedterms_display_all', SUGGESTEDTERMS_DISPLAY_ALL),
+    '#description' => t("Whether to display all defined terms or only the ones previously used."),
+    '#options' => array(
+      SUGGESTEDTERMS_DISPLAY_USED => t('Previously-used terms'),
+      SUGGESTEDTERMS_DISPLAY_ALL => t('All terms'),
+    ),
   );
 
   return system_settings_form($form);
