? cmf.patch
Index: cmf.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cmf/cmf.module,v
retrieving revision 1.2.2.19.2.6
diff -u -p -r1.2.2.19.2.6 cmf.module
--- cmf.module	17 Oct 2009 14:46:22 -0000	1.2.2.19.2.6
+++ cmf.module	10 Nov 2010 01:15:32 -0000
@@ -135,6 +135,18 @@ function cmf_filters($user_page = FALSE)
     '#options' => node_get_types('names'),
     );
 
+  //-- workflow filter
+  if(module_exists('workflow'))  {
+    $filters['workflow_state'] = array(
+      'title' => t('workflow state'),
+      'single_use' => FALSE,
+      'whole_value' => 'before',
+      'query_build' => '_cmf_workflow_query_build',
+      '#type' => 'select',
+      '#options' => cmf_get_workflows(),
+      );    
+  }
+  
   // The taxonomy filter.
   if (module_exists('taxonomy')) {
     $filters['category'] = array(
@@ -247,6 +259,7 @@ function cmf_filters($user_page = FALSE)
       '#options' => array(1 => t('active'), 0 => t('blocked')),
       );
   }
+  drupal_alter('cmf_filters', $filters);
   return $filters;
 }
 
@@ -1038,3 +1051,39 @@ function _cmf_get_forum($nid) {
   }
   return implode(' > ', array_reverse($path));
 }
+
+function cmf_get_workflows() {
+  if (!module_exists('workflow')) return;  
+  if (!function_exists('workflow_load_all')) return;
+  
+  $workflows = workflow_load_all();
+  
+  $states = array();
+  if (is_array($workflows)) {
+    foreach ($workflows as $workflow) {
+      if (is_array($workflow->states)) {
+        foreach ($workflow->states as $state) {
+          $states[$state->name] = $workflow->label . " : " . $state->label;
+        }
+      }
+    }
+  }
+  
+  return $states;
+  
+}
+
+/**
+ * Query_build function for workflow
+ */
+function _cmf_workflow_query_build($key, $value, $index) {
+  if (!module_exists('workflow')) return;  
+  if (!function_exists('workflow_load_all')) return;
+
+  $table = "workflow_node";
+  return array(
+    'where' => "$table.state_name = '%s'",
+    'join' => "INNER JOIN {$table} $table ON n.nid = $table.nid ",
+    'value' => $value,
+    );
+}
