### Eclipse Workspace Patch 1.0
#P pivots_block
Index: blocks_and_nodes/pivots_block.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drupalorg/blocks_and_nodes/pivots_block.module,v
retrieving revision 1.21
diff -u -r1.21 pivots_block.module
--- blocks_and_nodes/pivots_block.module	15 Mar 2010 23:54:38 -0000	1.21
+++ blocks_and_nodes/pivots_block.module	20 Mar 2010 00:32:07 -0000
@@ -17,30 +17,14 @@
  * Foundation.
  */
 
-define('PID_DOUBLE', 5006);       // double pivot algorithm ID that displays related projects in different algorithms.
+define('PID_DOUBLE', 6001);       // double pivot algorithm ID that displays related projects in different algorithms.
 define('LIMIT_DOUBLE', 5);
-define('LIMIT_MAX', 100);         // maximum items to display in the block or on a page.
 
 function pivots_block_output() {
   // skip nid=3060, the drupal project
   if (($node = project_get_project_from_menu()) && ($node->nid != 3060)) {
-
-    //HACK: randomize algorithm rotation
-    $_pivots_block_pid_double = PID_DOUBLE;  // double pivot ID defaults to conversation pivots
-    switch (rand(0,2)) {
-      case 0:
-        $_pivots_block_pid_double = 5004; // conversation pivots
-        break;
-      case 1:
-        $_pivots_block_pid_double = 5005; // solr10
-        break;
-      case 2:
-        $_pivots_block_pid_double = 5006; // corrhr + solr10
-        break;
-    }
-
-    $output = _pivots_block_content($node->nid, $_pivots_block_pid_double, t("Related projects"), LIMIT_DOUBLE);
-    //$output .= _pivots_block_suggestbox($node->nid, $_pivots_block_pid_double);
+    $output = _pivots_block_content($node->nid, PID_DOUBLE, t("Related projects"), LIMIT_DOUBLE);
+    $output .= _pivots_block_suggestbox($node->nid, PID_DOUBLE);
     return $output;
   }
 }
@@ -57,22 +41,20 @@
       )));
       $ga_event .= "_{$item['nid']}";
     }
-    //$output = theme('item_list', $items, $title);
-    $output = theme('item_list', $items); // hack: don't show title
+    $output = theme('item_list', $items);
+  }
+  else {
+    $output = '<p>'. t("No related project yet. Please make suggestions. Thanks.") .'</p>';
   }
   $GLOBALS['conf']['googleanalytics_codesnippet_after'] .= "pageTracker._trackEvent('PivotsPageview_{$pivot_id}', '{$ga_event}');";
   return $output;
 }
 
 function _pivots_block_generate_items($node_id, $pivot_id, $limit) {
-  if ($limit <= 0) {
-    $limit = LIMIT_MAX;
-  }
-
   db_set_active('pivots');  // NOTE: here we activate the pivots database.
   // if there's database failure, we just pretend nothing happens whatsoever. pivots_block returns nothing in this case.
-  $matches = @db_query("SELECT DISTINCT dest_id FROM {pivots_match} WHERE pivot_id=%d AND src_id=%d
-        AND dest_id<>%d ORDER BY score DESC", $pivot_id, $node_id, $node_id);
+  $matches = db_query("SELECT DISTINCT dst dest_id FROM {pivots_mab_match} WHERE pid=%d AND src=%d
+        AND dst<>%d ORDER BY updated DESC, score DESC", $pivot_id, $node_id, $node_id);
   db_set_active();  // NOTE: change back to use the default database
 
   $count = 0;
@@ -91,34 +73,31 @@
   return $items;
 }
 
-/*function _pivots_block_suggestbox($node_id, $pivot_id) {
+function _pivots_block_suggestbox($node_id, $pivot_id) {
   $form = array();
-  $form['suggestion'] = array (
-    '#type' => 'textfield',
-    //'#description' => t("Please suggest related projects. Multiple suggestions require multiple submission."),
-    '#size' => 20,
-    '#maxlength' => 128,
-    '#weight' => 0,
-    '#id' => 'pivots_block_suggestbox',
-  );
-  $form['submit'] = array(
+  $form['suggest'] = array(
     '#type' => 'button',
-    '#value' => t('Suggest project!'),
+    '#value' => t('Make a suggestion!'),
     '#weight' => 1,
     '#id' => 'pivots_block_suggestbutton'
   );
 
+  $node = node_load($node_id);
   drupal_add_js("
       $(document).ready(function() {
         $('#pivots_block_suggestbutton').click(function() {
           var pattern = /^http[:][/][/]drupal[.]org[/]project[/]\w+$/;
-          var suggestion = $('#pivots_block_suggestbox').val();
+          var suggestion = '';
+          var promption = 'Please suggest a related project to *{$node->title}* using its URL such as http://drupal.org/project/xxx. Thank you.';
+          var error_promption = 'Your suggested URL does not look like http://drupal.org/project/xxx. Please try again, or press Cancel.';
+          var success_promption = 'Thank you for suggesting a related project. It may or may not display soon according to the competition algorithm.';
           while (!suggestion.match(pattern)) {
-            suggestion = prompt('Please suggest a related project using URLs such as http://drupal.org/project/cck. Thank you.');
+            suggestion = prompt(promption);
             if (!suggestion) break;
+            else promption = error_promption;
           }
           if (suggestion) {
-            alert('Thank you for suggesting a related project. All suggestions will be aggregated and updated to the results soon.');
+            alert(success_promption);
             pageTracker._trackEvent('PivotsSuggest_${pivot_id}', '${node_id}_'+suggestion);
           }
         });
@@ -126,7 +105,7 @@
     ", 'inline');
 
   return drupal_render_form('pivots_block_suggestbox', $form);
-}*/
+}
 
 /**
  * Implementation of hook_block()
