? 231614_project_no_terms_29.patch
Index: /Applications/MAMP/htdocs/rg3/drupal/sites/all/modules/project/project.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project/project.module,v
retrieving revision 1.313
diff -u -p -r1.313 project.module
--- project.module	11 Jun 2008 18:19:41 -0000	1.313
+++ project.module	4 Jul 2008 01:04:05 -0000
@@ -521,11 +521,13 @@ function project_page_overview($termname
   $sort_methods = module_invoke_all('project_sort_methods', 'methods');
 
   $output = '';
+  $active_tids = array();
   if (module_exists('project_release') && variable_get('project_release_browse_versions', 0)) {
     $version_form = drupal_get_form('project_release_version_filter_form');
     $output .= $version_form;
     // Read in requested version, if any.
     $version = isset($_SESSION['project_version']) ? $_SESSION['project_version'] : variable_get('project_release_overview', -1);
+    $active_tids = project_release_compatibility_list();
   }
 
   // If browsing by taxonomy, only fetch projects for this term.
@@ -558,7 +560,11 @@ function project_page_overview($termname
         $terms = array();
         if ($tree) {
           $tids = array();
-          if (variable_get('project_release_browse_versions', 0)) {
+          // Make sure the API compatability term vocabulary exists and contains one
+          // or more terms (not including the term with key of -1, which is always
+          // automatically added to the array of terms. If not then browsing
+          // by version is not possible.
+          if (variable_get('project_release_browse_versions', 0) && count($active_tids) > 1) {
             $version_params = array();
             if ($version != -1) {
               $version_where = 'tr.tid = %d';
@@ -566,7 +572,6 @@ function project_page_overview($termname
             }
             else {
               $placeholders = array();
-              $active_tids = project_release_compatibility_list();
               foreach ($active_tids as $tid => $api_term) {
                 $placeholders[] = '%d';
                 $version_params[] = $tid;
@@ -650,15 +655,21 @@ function project_page_overview($termname
         $sql_settings = array();
       }
 
+      $active_tids = array();
       if (module_exists('project_release')) {
         $project_release_sql = array(
           'joins' => array('INNER JOIN {project_release_projects} prp ON n.nid = prp.nid'),
           'wheres' => array('prp.releases = 1'),
         );
         $sql_settings = array_merge_recursive($sql_settings, $project_release_sql);
+        $active_tids = project_release_compatibility_list();
       }
 
-      if (variable_get('project_release_browse_versions', 0)) {
+      // Make sure the API compatability term vocabulary exists and contains one
+      // or more terms (not including the term with key of -1, which is always
+      // automatically added to the array of terms. If not then browsing
+      // by version is not possible.
+      if (variable_get('project_release_browse_versions', 0) && count($active_tids) > 1) {
         $release_settings = array(
           'fields' => array('prn.file_path', 'prn.version', 'MAX(prn.file_date) AS changed', 'COUNT(*) AS release_count'),
           'group_bys' => array('n.nid'),
@@ -677,7 +688,7 @@ function project_page_overview($termname
         }
         else {
           $placeholders = array();
-          $active_tids = project_release_compatibility_list();
+//          $active_tids = project_release_compatibility_list();
           foreach ($active_tids as $tid => $compatibility_term) {
             $placeholders[] = '%d';
             $release_settings['parameters'][] = $tid;
Index: /Applications/MAMP/htdocs/rg3/drupal/sites/all/modules/project/release/project_release.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project/release/project_release.module,v
retrieving revision 1.69
diff -u -p -r1.69 project_release.module
--- release/project_release.module	11 Jun 2008 18:14:55 -0000	1.69
+++ release/project_release.module	4 Jul 2008 01:04:07 -0000
@@ -1098,23 +1098,29 @@ function project_release_project_edit_re
 }
 
 function project_release_project_edit_form($node) {
-  // Get all the data about major versions for this project.
-  $data = _project_release_get_version_major_data($node);
-
-  // Build all the form elements for supported and recommended major versions.
-  $form = _project_release_edit_version_major_form($data);
-
-  // Now, add a header and some help text for those elements.
-  $form['header'] = array(
-    '#type' => 'markup',
-    '#value' => t('Supported versions'),
-  );
-
-  $vocab = taxonomy_get_vocabulary(_project_release_get_api_vid());
-  $form['help'] = array(
-    '#type' => 'markup',
-    '#value' => t('For each term in the %api_vocabulary_name vocabulary, the following tables allow you to define which major versions are supported. If there are releases from more than one major version number, you can select which major version should be recommended for new users to download. You can also control if the development snapshot releases should be displayed on the front page of the project. Finally, for each term in the %api_vocabulary_name vocabulary, the current recommended release is shown. If no official releases have been made, the development snapshot from the corresponding branch will be listed. Otherwise, the most recent official release will be listed.', array('%api_vocabulary_name' => $vocab->name)),
-  );
+  $active_tids = project_release_compatibility_list();
+  // Make sure there is more than 1 active tid because
+  // project_release_compatibility_list() will always
+  // add $terms[-1] = 'all'.
+  if (!empty($active_tids) && count($active_tids) > 1) {
+    // Get all the data about major versions for this project.
+    $data = _project_release_get_version_major_data($node);
+  
+    // Build all the form elements for supported and recommended major versions.
+    $form = _project_release_edit_version_major_form($data);
+  
+    // Now, add a header and some help text for those elements.
+    $form['header'] = array(
+      '#type' => 'markup',
+      '#value' => t('Supported versions'),
+    );
+  
+    $vocab = taxonomy_get_vocabulary(_project_release_get_api_vid());
+    $form['help'] = array(
+      '#type' => 'markup',
+      '#value' => t('For each term in the %api_vocabulary_name vocabulary, the following tables allow you to define which major versions are supported. If there are releases from more than one major version number, you can select which major version should be recommended for new users to download. You can also control if the development snapshot releases should be displayed on the front page of the project. Finally, for each term in the %api_vocabulary_name vocabulary, the current recommended release is shown. If no official releases have been made, the development snapshot from the corresponding branch will be listed. Otherwise, the most recent official release will be listed.', array('%api_vocabulary_name' => $vocab->name)),
+    );
+  }
 
   // Finally, add everything else (currently, the "Advanced options").
   $form['advanced'] = array(
@@ -1162,11 +1168,18 @@ function _project_release_get_version_ma
   $params[] = $node->nid;
   $placeholders = array();
   $active_tids = project_release_compatibility_list();
+  // Get rid of -1 => 'all' element inserted by project_release_compatibility_list().
+  if (isset($active_tids[-1])) {
+    unset($active_tids[-1]);
+  }
   foreach ($active_tids as $tid => $api_term) {
     $placeholders[] = '%d';
     $params[] = $tid;
   }
-  $tid_where = 'prsv.tid IN ('. implode(',', $placeholders) .')';
+  $tid_where = '';
+  if (!empty($active_tids)) {
+    $tid_where = 'prsv.tid IN ('. implode(',', $placeholders) .')';
+  }
   $result = db_query("SELECT prsv.*, td.name AS term_name FROM {project_release_supported_versions} prsv INNER JOIN {term_data} td ON prsv.tid = td.tid WHERE prsv.nid = %d AND $tid_where ORDER BY td.weight, td.name", $params);
   while ($obj = db_fetch_object($result)) {
     $tid = $obj->tid;
@@ -1724,7 +1737,10 @@ function project_release_table($project,
     case 'snapshot':
       // For snapshot tables, restrict to snapshot nodes from branches where
       // the maintainer wants the snapshot visible.
-      $where = 'AND r.rebuild = 1 AND prsv.snapshot = 1';
+      $where = 'AND r.rebuild = 1';
+      if ($tids) {
+        $where .= 'AND prsv.snapshot = 1';
+      }
       break;
     case 'all':
       // If we're generating the default releases table, we want the
@@ -2179,3 +2195,53 @@ function project_release_pick_project_fo
 function project_release_pick_project_form_submit($form_id, $form_values) {
   return 'node/add/project-release/'. $form_values['pid'];
 }
+
+/**
+ * Returns whether or not the project release module should use
+ * taxonomy-specific functionality.
+ */
+function project_release_use_taxonomy() {
+  return module_exists('taxonomy') && _project_release_get_api_vid();
+}
+
+/**
+ * Implementation of hook_help().
+ */
+function project_release_help($section) {
+  switch ($section) {
+    case 'admin/project/project-release-settings':
+      if (project_release_use_taxonomy()) {
+        return _project_release_taxonomy_help();
+      }
+      break;
+  }
+  if (arg(0) == 'admin' && arg(1) == 'content' && arg(2) == 'taxonomy') {
+    $vid = _project_release_get_api_vid();
+    if (arg(3) == $vid) {
+      return _project_release_taxonomy_help($vid, FALSE);
+    }
+  }
+}
+
+/**
+ * Prints out a help message about how to configure the project release API
+ * compatability term vocabulary.
+ *
+ * @param $vid
+ *   Vocabulary ID of the project taxonomy.
+ * @param $vocab_link
+ *   Boolean that controls if a link to the vocabulary admin page is added.
+ */
+function _project_release_taxonomy_help($vid = 0, $vocab_link = TRUE) {
+  if (!$vid) {
+    $vid = _project_release_get_api_vid();
+  }
+  $vocabulary = taxonomy_get_vocabulary($vid);
+  $text = '<p>'. t('The Project release module makes special use of the taxonomy (category) system. A special vocabulary, %vocabulary_name, has been created automatically.', array('%vocabulary_name' => $vocabulary->name)) .'</p>';
+  $text .= '<p>'. t('To categorize project releases by their compatibility with a version of some outside software (eg. a library or API of some sort), add at least one term to this vocabulary. For example, you might add the following terms: "5.x", "6.x", "7.x".') .'</p>';
+  $text .='<p>'. t('For more information, please see !url.', array('!url' => l('http://drupal.org/node/116544', 'http://drupal.org/node/116544'))) .'</p>';
+  if ($vocab_link) {
+    $text .= '<p>'. t('Use the <a href="@taxonomy-admin">vocabulary admininistration page</a> to view and add terms.', array('@taxonomy-admin' => url('admin/content/taxonomy/'. $vid))) .'</p>';
+  }
+  return $text;
+}
