瀏覽代碼

Brought tripal_views back to Drupal coding standards

Lacey Sanderson 12 年之前
父節點
當前提交
ba5321de2d

+ 48 - 38
tripal_views/tripal_views.api.inc

@@ -30,7 +30,7 @@ function tripal_views_get_lightest_priority_setup($table_name) {
   }
 }
 
-/** 
+/**
  * Check to see if this table already has an integration record with the given priority
  *
  * @param $table_name
@@ -39,22 +39,24 @@ function tripal_views_get_lightest_priority_setup($table_name) {
  *   The priority of record to check for
  *
  * @return
- *  If the table is already integrated, the setup_id of the existing integration 
+ *  If the table is already integrated, the setup_id of the existing integration
  *  record is returned (If priority is not specified this will be the lightest record);
  *  Otherwise the table is not already integrated and FALSE is returned.
  */
 function tripal_views_is_integrated($table_name, $priority = NULL) {
-  
+
   if ($priority) {
     $sql = "SELECT setup_id FROM {tripal_views} WHERE table_name='%s' AND priority=%d";
     $setup = db_fetch_object(db_query($sql, $table_name, $priority));
-  } else {
+  }
+  else {
     $sql = "SELECT setup_id FROM {tripal_views} WHERE table_name='%s' ORDER BY priority ASC";
-    $setup = db_fetch_object(db_query($sql, $table_name));  
+    $setup = db_fetch_object(db_query($sql, $table_name));
   }
   if ($setup) {
-    return $setup->setup_id;  
-  } else {
+    return $setup->setup_id;
+  }
+  else {
     return FALSE;
   }
 }
@@ -142,12 +144,13 @@ function tripal_views_integration_add_entry($defn_array) {
       }
   }
   if ($view_record['name'] && $view_record['comment']) {
-    $status = drupal_write_record('tripal_views',$view_record);
-  } else {
+    $status = drupal_write_record('tripal_views', $view_record);
+  }
+  else {
     $status = FALSE;
-    drupal_set_message('Unable to integrate '.$defn_array['table'].' table due to a missing name or comment field.', 'error');
+    drupal_set_message(t('Unable to integrate %table table due to a missing name or comment field.', array('%table' => $defn_array['table'])), 'error');
   }
-  
+
   if ($status) {
 
     // Insert Field Definitions
@@ -160,12 +163,13 @@ function tripal_views_integration_add_entry($defn_array) {
         'type' => $field['type'],
       );
       if ($view_record['setup_id'] && $field['name'] && $field['title'] && $field['description'] && $field['type']) {
-        $status = drupal_write_record('tripal_views_field',$field_record);
-      } else {
-        drupal_set_message('Unable to integrate '.$field['name'].' field due to a missing required fields.', 'error');
+        $status = drupal_write_record('tripal_views_field', $field_record);
+      }
+      else {
+        drupal_set_message(t('Unable to integrate %name field due to a missing required fields.', array('%name' => $field['name'])), 'error');
         $status = FALSE;
       }
-      
+
       if ($status) {
 
         // Insert Handler Definitions
@@ -178,8 +182,9 @@ function tripal_views_integration_add_entry($defn_array) {
             'arguments' => serialize($handler)
           );
           if ($view_record['setup_id'] && $field['name'] && $handler_type && $handler['name'] && $handler) {
-            $status = drupal_write_record('tripal_views_handlers',$handler_record);
-          } else {
+            $status = drupal_write_record('tripal_views_handlers', $handler_record);
+          }
+          else {
             $status = FALSE;
           }
           if (!$status) {
@@ -209,8 +214,9 @@ function tripal_views_integration_add_entry($defn_array) {
           }
 
           if ($view_record['setup_id'] && $defn_array['table'] && $field['name'] && $join['table'] && $join['field']) {
-            $status = drupal_write_record('tripal_views_join',$join_record);
-          } else {
+            $status = drupal_write_record('tripal_views_join', $join_record);
+          }
+          else {
             $status = FALSE;
           }
           if (!$status) {
@@ -295,70 +301,74 @@ function tripal_views_integration_remove_entry_by_setup_id($setup_id) {
  * @param $tablename
  *   The table to generate the tripal views integration array for
  * @return
- *   The tripal views integration array which is the parameter for 
+ *   The tripal views integration array which is the parameter for
  *   tripal_views_integration_add_entry($defn_array)
  */
-function tripal_views_get_integration_array_for_chado_table ($table_name, $base_table = TRUE) {
+function tripal_views_get_integration_array_for_chado_table($table_name, $base_table = TRUE) {
 
   // Get the schema for this table (via the chado schema api)
-  $schema = module_invoke_all('chado_'.$table_name.'_schema');
-  
+  $schema = module_invoke_all('chado_' . $table_name . '_schema');
+
   // Base definition array
   $defn_array = array(
     'table' => $table_name,
     'type' => 'chado',
-    'name' => ucwords(str_replace('_',' ',$table_name)),
+    'name' => ucwords(str_replace('_', ' ', $table_name)),
     'description' => ($schema['description']) ? $schema['description'] : ' ',
     'priority' => 10,
     'base_table' => $base_table,
     'fields' => array(),
   );
-  
+
   // Add fields
-  if (!isset($schema['fields'])) { 
+  if (!isset($schema['fields'])) {
     $schema['fields'] = array();
-    drupal_set_message('There are no fields defined for '.$table_name.' in the Chado Schema API.','warning');
+    drupal_set_message(t('There are no fields defined for %table in the Chado Schema API.', array('%table' => $table_name)), 'warning');
   }
   foreach ($schema['fields'] as $field_name => $field_schema) {
-    
+
     // Base field definition
     if (!empty($field_name) && !empty($field_schema['type'])) {
       $defn_array['fields'][$field_name] = array(
         'name' => $field_name,
-        'title' => ucwords(str_replace('_',' ',$field_name)),
+        'title' => ucwords(str_replace('_', ' ', $field_name)),
         'type' => $field_schema['type'],
         'description' => ($field_schema['description']) ? $field_schema['description'] : ' ',
         'handlers' => array(),
         'joins' => array()
       );
-      
+
       // Add handlers based on type
-      if (preg_match('/^int/',$field_schema['type'])) {
+      if (preg_match('/^int/', $field_schema['type'])) {
         $defn_array['fields'][$field_name]['handlers'] = array(
           'field' => array('name' => 'chado_views_handler_field_numeric'),
           'filter' => array('name' => 'chado_views_handler_filter_numeric'),
           'sort' => array('name' => 'chado_views_handler_sort'),
         );
-      } elseif (preg_match('/^serial/',$field_schema['type'])) {
+      }
+      elseif (preg_match('/^serial/', $field_schema['type'])) {
         $defn_array['fields'][$field_name]['handlers'] = array(
           'field' => array('name' => 'chado_views_handler_field_numeric'),
           'filter' => array('name' => 'chado_views_handler_filter_numeric'),
           'sort' => array('name' => 'chado_views_handler_sort'),
         );
         $defn_array['fields'][$field_name]['type'] = 'int';
-      } elseif (preg_match('/^varchar/',$field_schema['type'])) {
+      }
+      elseif (preg_match('/^varchar/', $field_schema['type'])) {
         $defn_array['fields'][$field_name]['handlers'] = array(
           'field' => array('name' => 'chado_views_handler_field'),
           'filter' => array('name' => 'chado_views_handler_filter_string'),
           'sort' => array('name' => 'chado_views_handler_sort'),
         );
-      } elseif (preg_match('/^text/',$field_schema['type'])) {
+      }
+      elseif (preg_match('/^text/', $field_schema['type'])) {
         $defn_array['fields'][$field_name]['handlers'] = array(
           'field' => array('name' => 'chado_views_handler_field'),
           'filter' => array('name' => 'chado_views_handler_filter_string'),
           'sort' => array('name' => 'chado_views_handler_sort'),
         );
-      } else {
+      }
+      else {
         $defn_array['fields'][$field_name]['handlers'] = array(
           'field' => array('name' => 'chado_views_handler_field'),
           'filter' => array('name' => 'chado_views_handler_filter_string'),
@@ -367,11 +377,11 @@ function tripal_views_get_integration_array_for_chado_table ($table_name, $base_
       }
     }
   }
-  
+
   // Add Joins to fields
   if (!isset($schema['foreign keys'])) {
     $schema['foreign keys'] = array();
-    drupal_set_message('There are no foreign keys defined for '.$table_name.' in the Chado Schema API.','warning');
+    drupal_set_message(t('There are no foreign keys defined for %table in the Chado Schema API.', array('%table' => $table_name)), 'warning');
   }
   foreach ($schema['foreign keys'] as $foreign_key_schema) {
     foreach ($foreign_key_schema['columns'] as $left_field => $right_field) {
@@ -382,6 +392,6 @@ function tripal_views_get_integration_array_for_chado_table ($table_name, $base_
       );
     }
   }
-  
+
   return $defn_array;
 }

+ 8 - 1
tripal_views/tripal_views.coder_ignores.txt

@@ -7,13 +7,20 @@ tripal_views_integration_fields_form.tpl.php:48:style
 tripal_views_data_export_download_form.tpl.php:8:style
 
 ; All variables are set through the code and thus don't need to be filtered
-tripal_views_integration.inc:734:security
+tripal_views_integration.inc:809:security
 
 ; SQL queries the chado database which does not use the drupal prefixing functionality
 ; therefore, curly brackets ({}) are not appropriate.
 views/handlers/views_handler_filter_chado_select_cvterm_name.inc:53:sql
 views/handlers/views_handler_filter_chado_select_cvterm_name.inc:61:sql
 views/handlers/views_handler_field_dbxref_accession_link.inc:31:sql
+views/handlers/views_handler_filter_stockprop_id.inc:78:sql
+views/handlers/views_handler_filter_stockprop_id.inc:104:sql
+views/handlers/views_handler_filter_stock_relationship_id.inc:23:sql
+views/handlers/views_handler_filter_stock_relationship_id.inc:72:sql
+views/handlers/views_handler_filter_stock_relationship_id.inc:79:sql
+views/handlers/views_handler_filter_stock_relationship_id.inc:160:sql
+views/handlers/views_handler_argument_stockprop_id.inc:21:sql
 
 ; SQL queries the pg_tables table to check if a table exists in chado; drupal
 ; prefixing is not appropriate

+ 8 - 8
tripal_views/tripal_views.install

@@ -74,14 +74,14 @@ function tripal_views_update_6040() {
   // Add handler to tripal_views_join
   db_add_field($ret, 'tripal_views_join', 'handler', array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''));
 
-	// Add tripal_views_field to keep track of fields for views integration
-	$schema = tripal_views_views_schema();
-	db_create_table(&$ret, 'tripal_views_field', $schema['tripal_views_field']);
-	
-	// Add base_table TRUE/FALSE to tripal_views
-	db_add_field($ret, 'tripal_views', 'base_table', array('type' => 'int', 'not null ' => TRUE,
-			'default' => 1));
-	
+  // Add tripal_views_field to keep track of fields for views integration
+  $schema = tripal_views_views_schema();
+  db_create_table(&$ret, 'tripal_views_field', $schema['tripal_views_field']);
+
+  // Add base_table TRUE/FALSE to tripal_views
+  db_add_field($ret, 'tripal_views', 'base_table', array('type' => 'int', 'not null ' => TRUE,
+      'default' => 1));
+
   return $ret;
 }
 

+ 52 - 48
tripal_views/tripal_views.views.inc

@@ -438,22 +438,23 @@ function tripal_views_views_data() {
     $setup_id = $tvi_row->setup_id;
     $mview_id = $tvi_row->mview_id;
 
-      // holds the base table name and fields
-      $base_table = '';
-      $base_fields = array();
-      $type_prefix = '';
-      
-      // indicated whether the current table is a base table or not
-      $is_base_table = $tvi_row->base_table;
-      
-      // populate the base table name and fields.  If an $mview_id is given
-      // then get the materialized view info, otherwise get the Chado table info
-      if($mview_id){
-         $type_prefix = 'MView';
-         // get the base table name from the materialized view
-         $sql = "SELECT name, mv_specs FROM {tripal_mviews} WHERE mview_id = %d";
-         $mview_table = db_fetch_object(db_query($sql,$mview_id));
-         $base_table = $mview_table->name;
+    // holds the base table name and fields
+    $base_table = '';
+    $base_fields = array();
+    $type_prefix = '';
+
+    // indicated whether the current table is a base table or not
+    $is_base_table = $tvi_row->base_table;
+
+    // populate the base table name and fields.  If an $mview_id is given
+    // then get the materialized view info, otherwise get the Chado table info
+    if ($mview_id) {
+      $type_prefix = 'MView';
+
+      // get the base table name from the materialized view
+      $sql = "SELECT name, mv_specs FROM {tripal_mviews} WHERE mview_id = %d";
+      $mview_table = db_fetch_object(db_query($sql, $mview_id));
+      $base_table = $mview_table->name;
 
       // get the columns in this materialized view.  They are separated by commas
       // where the first word is the column name and the rest is the type
@@ -510,58 +511,61 @@ function tripal_views_views_data() {
 
       // Setup the base table info in the data array
       $data[$base_table]['table']['group'] = t("$type_prefix $tvi_row->name");
-      
+
       if ($is_base_table) {
         $data[$base_table]['table']['base'] = array(
           'group' => "$type_prefix $tvi_row->name",
           'title' => "$type_prefix $tvi_row->name",
           'help'  => $tvi_row->comment,
         );
-      } else {
+      }
+      else {
         $data[$base_table]['table'] = array(
           'group' => "$type_prefix $tvi_row->name",
           'title' => "$type_prefix $tvi_row->name",
           'help'  => $tvi_row->comment,
         );
       }
-      
+
       // first add the fields
-      foreach ($base_fields as $column_name => $base_field){
+      foreach ($base_fields as $column_name => $base_field) {
         $data[$base_table][$column_name] = array(
-           'title' => t($base_field['name']),
-           'help' => t($base_field['help']),
-           'field' => array(
-              'click sortable' => TRUE,
-           ),
+          'title' => t($base_field['name']),
+          'help' => t($base_field['help']),
+          'field' => array(
+            'click sortable' => TRUE,
+          ),
         );
-        
-        
+
+
         // now add the handlers
         $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id = %d AND column_name = '%s'";
-        $handlers = db_query($sql,$setup_id,$column_name);
-        while($handler = db_fetch_object($handlers)){
-           $data[$base_table][$column_name][$handler->handler_type]['handler'] = $handler->handler_name;
+        $handlers = db_query($sql, $setup_id, $column_name);
+        while ($handler = db_fetch_object($handlers)) {
+          $data[$base_table][$column_name][$handler->handler_type]['handler'] = $handler->handler_name;
         };
     }
 
-     // now add the joins
-     $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
-     $joins = db_query($sql,$setup_id);
-     if (!isset($joins)) { $joins = array(); }
-     while($join = db_fetch_object($joins)){               
-        $left_table = $join->left_table;
-        $left_field = $join->left_field;
-        $base_field = $join->base_field; 
-        $handler = $join->handler;
-      
-        // add join entry
-        $data[$base_table]['table']['join'][$left_table] = array(
-          'left_field' => $left_field,
-          'field' => $base_field,
-        );
-        if ($handler) {
-          $data[$base_table]['table']['join'][$left_table]['handler'] = $handler;
-        }
+    // now add the joins
+    $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
+    $joins = db_query($sql, $setup_id);
+    if (!isset($joins)) {
+      $joins = array();
+    }
+    while ($join = db_fetch_object($joins)) {
+      $left_table = $join->left_table;
+      $left_field = $join->left_field;
+      $base_field = $join->base_field;
+      $handler = $join->handler;
+
+      // add join entry
+      $data[$base_table]['table']['join'][$left_table] = array(
+        'left_field' => $left_field,
+        'field' => $base_field,
+      );
+      if ($handler) {
+        $data[$base_table]['table']['join'][$left_table]['handler'] = $handler;
+      }
 
       // check to see if the join table is one that correlates with Drupal nodes
       // if so, there will be a chado_<table_name> table in the Drupal database

+ 153 - 149
tripal_views/tripal_views_integration.inc

@@ -69,97 +69,99 @@ function tripal_views_description_page() {
  *
  * @ingroup tripal_views_integration
  */
-function tripal_views_integration_setup_list(){
-   $output = '';
-
-   $output .= '<h3>'.l('Add a new entry',"admin/tripal/views/integration/new") . " | " .
-                         l("Create Materialized View",'admin/build/views/add').'</h3>';
-                         
-   $output .= '<p>The following tables list the views integration setups available. If '
-    .'there is more then one setup for a given table, then the setup with the lightest ' 
+function tripal_views_integration_setup_list() {
+  $output = '';
+
+  $output .= '<h3>' . l(t('Add a new entry'), "admin/tripal/views/integration/new") . " | " .
+    l(t("Create Materialized View"), 'admin/build/views/add') . '</h3>';
+
+  $output .= '<p>The following tables list the views integration setups available. If '
+    .'there is more then one setup for a given table, then the setup with the lightest '
     .'priority will be used. For example, if you have created a custom setup for the '
     .'feature chado table and your setup has a priority of -5 then your setup will be '
     .'used instead of the default feature integration because -5 is lighter then 10.'
     .'Priorities use the Drupal -10 to +10 scale where a record with -10 has a '
     .'greater priority then one with 0 and both have a greater priority then one with +10.</p>';
-      
-   
-   // Start with materialized views           
-   $output .= '<br /><h3>Materialized Views</h3>';           
-   $header = array('', 'Drupal Views Type Name', 'Table Name', 'Is Legacy?', 'Priority', 'Comment','');
-   $rows = array();
-
-   // get the list of materialized views
-   $tviews = db_query('SELECT tv.name, tv.table_name, tc.table_id, tv.priority, tv.comment '
-   									.'FROM {tripal_views} tv '
-   									.'LEFT JOIN {tripal_custom_tables} tc ON tc.table_name=tv.table_name '
-   									.'WHERE tv.mview_id IS NOT NULL '
-   									.'ORDER BY tv.table_name ASC, tv.priority ASC');
-   while($tview = db_fetch_object($tviews)){
-         $rows[] = array(
-            l('Edit',"admin/tripal/views/integration/edit/".$tview->setup_id) ,
-            $tview->name, 
-            $tview->table_name,
-            ($tview->table_id) ? 'No' : 'Yes',  
-            $tview->priority,
-            $tview->comment,
-            l('Delete',"admin/tripal/views/integration/delete/".$tview->setup_id),
-         );         
-   }
-   
-   $output .= theme('table', $header, $rows);
-		
-	 // Now list non-mview custom tables
-   $output .= '<br /><h3>Custom Tables</h3>';           
-   $header = array('', 'Drupal Views Type Name', 'Table Name', 'Priority', 'Comment','');
-   $rows = array();
-
-   // get the list of chado tables
-   $tviews = db_query('SELECT tv.name, tv.table_name, tv.priority, tv.comment '
-   									.'FROM {tripal_views} tv '
-   									.'LEFT JOIN {tripal_custom_tables} tc ON tc.table_name=tv.table_name '
-   									.'WHERE mview_id IS NULL AND tc.table_id IS NOT NULL '
-   									.'ORDER BY table_name ASC, priority ASC');
-   while($tview = db_fetch_object($tviews)){
-         $rows[] = array(
-            l('Edit',"admin/tripal/views/integration/edit/".$tview->setup_id) ,
-            $tview->name, 
-            $tview->table_name,  
-            $tview->priority,
-            $tview->comment,
-            l('Delete',"admin/tripal/views/integration/delete/".$tview->setup_id),
-         );         
-   }
-   
-   if ($rows) {
-	   $output .= theme('table', $header, $rows);
-	 } else {
-	   $output .= '<p>There are currently no non-Materialized View Custom Tables defined.</p>';
-	 }
-   // Now list chado tables
-   $output .= '<br /><h3>Chado Tables</h3>';           
-   $header = array('', 'Drupal Views Type Name', 'Table Name', 'Priority', 'Comment','');
-   $rows = array();
-
-   // get the list of chado tables
-   $tviews = db_query('SELECT tv.name, tv.table_name, tv.priority, tv.comment '
-   									.'FROM {tripal_views} tv '
-   									.'LEFT JOIN {tripal_custom_tables} tc ON tc.table_name=tv.table_name '
-   									.'WHERE mview_id IS NULL AND tc.table_id IS NULL '
-   									.'ORDER BY table_name ASC, priority ASC');
-   while($tview = db_fetch_object($tviews)){
-         $rows[] = array(
-            l('Edit',"admin/tripal/views/integration/edit/".$tview->setup_id) ,
-            $tview->name, 
-            $tview->table_name,  
-            $tview->priority,
-            $tview->comment,
-            l('Delete',"admin/tripal/views/integration/delete/".$tview->setup_id),
-         );         
-   }
-   
-   $output .= theme('table', $header, $rows);
-   return $output;
+
+
+  // Start with materialized views
+  $output .= '<br /><h3>Materialized Views</h3>';
+  $header = array('', 'Drupal Views Type Name', 'Table Name', 'Is Legacy?', 'Priority', 'Comment', '');
+  $rows = array();
+
+  // get the list of materialized views
+  $tviews = db_query('SELECT tv.name, tv.table_name, tc.table_id, tv.priority, tv.comment '
+                     .'FROM {tripal_views} tv '
+                     .'LEFT JOIN {tripal_custom_tables} tc ON tc.table_name=tv.table_name '
+                     .'WHERE tv.mview_id IS NOT NULL '
+                     .'ORDER BY tv.table_name ASC, tv.priority ASC');
+  while ($tview = db_fetch_object($tviews)) {
+    $rows[] = array(
+      l(t('Edit'), "admin/tripal/views/integration/edit/" . $tview->setup_id) ,
+      $tview->name,
+      $tview->table_name,
+      ($tview->table_id) ? 'No' : 'Yes',
+      $tview->priority,
+      $tview->comment,
+      l(t('Delete'), "admin/tripal/views/integration/delete/" . $tview->setup_id),
+    );
+  }
+
+  $output .= theme('table', $header, $rows);
+
+  // Now list non-mview custom tables
+  $output .= '<br /><h3>Custom Tables</h3>';
+  $header = array('', 'Drupal Views Type Name', 'Table Name', 'Priority', 'Comment', '');
+  $rows = array();
+
+  // get the list of chado tables
+  $tviews = db_query('SELECT tv.name, tv.table_name, tv.priority, tv.comment '
+                     .'FROM {tripal_views} tv '
+                     .'LEFT JOIN {tripal_custom_tables} tc ON tc.table_name=tv.table_name '
+                     .'WHERE mview_id IS NULL AND tc.table_id IS NOT NULL '
+                     .'ORDER BY table_name ASC, priority ASC');
+  while ($tview = db_fetch_object($tviews)) {
+    $rows[] = array(
+      l(t('Edit'), "admin/tripal/views/integration/edit/" . $tview->setup_id) ,
+      $tview->name,
+      $tview->table_name,
+      $tview->priority,
+      $tview->comment,
+      l(t('Delete'), "admin/tripal/views/integration/delete/" . $tview->setup_id),
+    );
+  }
+
+  if ($rows) {
+    $output .= theme('table', $header, $rows);
+  }
+  else {
+    $output .= '<p>There are currently no non-Materialized View Custom Tables defined.</p>';
+  }
+
+  // Now list chado tables
+  $output .= '<br /><h3>Chado Tables</h3>';
+  $header = array('', 'Drupal Views Type Name', 'Table Name', 'Priority', 'Comment', '');
+  $rows = array();
+
+  // get the list of chado tables
+  $tviews = db_query('SELECT tv.name, tv.table_name, tv.priority, tv.comment '
+                     .'FROM {tripal_views} tv '
+                     .'LEFT JOIN {tripal_custom_tables} tc ON tc.table_name=tv.table_name '
+                     .'WHERE mview_id IS NULL AND tc.table_id IS NULL '
+                     .'ORDER BY table_name ASC, priority ASC');
+  while ($tview = db_fetch_object($tviews)) {
+    $rows[] = array(
+      l(t('Edit'), "admin/tripal/views/integration/edit/" . $tview->setup_id),
+      $tview->name,
+      $tview->table_name,
+      $tview->priority,
+      $tview->comment,
+      l(t('Delete'), "admin/tripal/views/integration/delete/" . $tview->setup_id),
+    );
+  }
+
+  $output .= theme('table', $header, $rows);
+  return $output;
 }
 
 /**
@@ -218,56 +220,57 @@ function tripal_views_integration_form(&$form_state, $setup_id = NULL) {
     $form_state['storage']['mview_id'] = $mview_id;
     $form_state['storage']['table_name'] = $table_name;
 
-      // get the default field name/description
-      $sql = "SELECT * FROM {tripal_views_field} WHERE setup_id=%d";
-      $query = db_query($sql,$setup_id);
-      $default_fields = array();
-      while ($field = db_fetch_object($query)) {
-        $default_fields[$field->column_name]['name'] = $field->name;
-        $default_fields[$field->column_name]['description'] = $field->description;
-      }
-      
-      // get the default join settings and handlers
-      $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
-      $query = db_query($sql,$setup_id);
-      $default_joins = array();
-      while ($join = db_fetch_object($query)){
-         $default_joins[$join->base_field]['left_table'] = $join->left_table;
-         $default_joins[$join->base_field]['left_field'] = $join->left_field;
-      }
+    // get the default field name/description
+    $sql = "SELECT * FROM {tripal_views_field} WHERE setup_id=%d";
+    $query = db_query($sql, $setup_id);
+    $default_fields = array();
+    while ($field = db_fetch_object($query)) {
+      $default_fields[$field->column_name]['name'] = $field->name;
+      $default_fields[$field->column_name]['description'] = $field->description;
+    }
 
-      // get the default handlers
-      $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id = %d";
-      $query = db_query($sql,$setup_id);
-      $default_handlers = array();
-      while ($handler = db_fetch_object($query)){
-         $default_handlers[$handler->column_name][$handler->handler_type]['handler_name'] = $handler->handler_name;
-         $default_handlers[$handler->column_name][$handler->handler_type]['arguments'] = $handler->arguments;
-      }
-      
-      // get the default join handlers
-      $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
-      $query = db_query($sql,$setup_id);
-      while ($handler = db_fetch_object($query)){
-         $default_handlers[$handler->base_field]['join']['handler_name'] = $handler->handler;
-         //$default_handlers[$handler->base_field]['join']['arguments'] = $handler->arguments;
-      }   
-      
-      // add in the setup_id for the form so we know this is an update not an insert
-      $form['setup_id'] = array(
-         '#type' => 'hidden',
-         '#value' => $setup_id,
-      );    
-   }
-   // add a fieldset for the MView & Chado table selectors
-   $form['base_table_type'] = array(
-     '#type' => 'fieldset',
-     '#title' => 'Base Table',
-     '#description' => 'Please select either a materialized view or a Chado table for integration with '.
+    // get the default join settings and handlers
+    $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
+    $query = db_query($sql, $setup_id);
+    $default_joins = array();
+    while ($join = db_fetch_object($query)) {
+      $default_joins[$join->base_field]['left_table'] = $join->left_table;
+      $default_joins[$join->base_field]['left_field'] = $join->left_field;
+    }
+
+    // get the default handlers
+    $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id = %d";
+    $query = db_query($sql, $setup_id);
+    $default_handlers = array();
+    while ($handler = db_fetch_object($query)) {
+      $default_handlers[$handler->column_name][$handler->handler_type]['handler_name'] = $handler->handler_name;
+      $default_handlers[$handler->column_name][$handler->handler_type]['arguments'] = $handler->arguments;
+    }
+
+    // get the default join handlers
+    $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
+    $query = db_query($sql, $setup_id);
+    while ($handler = db_fetch_object($query)) {
+      $default_handlers[$handler->base_field]['join']['handler_name'] = $handler->handler;
+      //$default_handlers[$handler->base_field]['join']['arguments'] = $handler->arguments;
+    }
+
+    // add in the setup_id for the form so we know this is an update not an insert
+    $form['setup_id'] = array(
+       '#type' => 'hidden',
+       '#value' => $setup_id,
+    );
+  }
+
+  // add a fieldset for the MView & Chado table selectors
+  $form['base_table_type'] = array(
+    '#type' => 'fieldset',
+    '#title' => 'Base Table',
+    '#description' => 'Please select either a materialized view or a Chado table for integration with '.
                        'Drupal Views.  In Drupal Views terminology, the selected table becomes the "base table". '.
                        'After you select a table from either list, the fields from that table will appear below '.
                        'and you can specify other tables to join with and handlers.',
-   );
+  );
 
   // build the form element for the Chado tables
   $chado_tables = tripal_core_get_chado_tables();
@@ -935,24 +938,25 @@ function tripal_views_integration_form_submit($form, &$form_state) {
     $left_table = $form_state['values']["fields_join_$table_id-$i"];
     $left_column = $form_state['values']["fields_join_column_$table_id-$i"];
 
-      if($left_column){
-         if($mview_id){
-            $base_table = $mview->mv_table;
-         } else {
-            $base_table = $table_name;
-         }
-         $view_join_record = array(
-           'setup_id' => $tripal_views_record['setup_id'],
-           'base_table' => $base_table,
-           'base_field' => $key,
-           'left_table' => $left_table,
-           'left_field' => $left_column,
-           'handler' => $form_state['values']["fields_join_handler_$table_id-$i"],
-         );
-         
-         // write the new joins to the database
-         drupal_write_record('tripal_views_join', $view_join_record);
+    if ($left_column) {
+      if ($mview_id) {
+        $base_table = $mview->mv_table;
       }
+      else {
+        $base_table = $table_name;
+      }
+      $view_join_record = array(
+        'setup_id' => $tripal_views_record['setup_id'],
+        'base_table' => $base_table,
+        'base_field' => $key,
+        'left_table' => $left_table,
+        'left_field' => $left_column,
+        'handler' => $form_state['values']["fields_join_handler_$table_id-$i"],
+      );
+
+      // write the new joins to the database
+      drupal_write_record('tripal_views_join', $view_join_record);
+    }
 
     // add the hanlders
     $handlers = array('filter', 'field', 'sort', 'argument', 'join', 'relationship');

+ 42 - 37
tripal_views/views/handlers/views_handler_argument_stockprop_id.inc

@@ -1,6 +1,7 @@
 <?php
 
 /**
+ * @file
  * Allows a stock property in the path to be used to filter a view
  *
  * @ingroup tripal_stock
@@ -8,64 +9,68 @@
  */
 class views_handler_argument_stockprop_id extends views_handler_argument_string {
 
-	function options_form(&$form, &$form_state) {
-    parent::options_form($form, $form_state);   
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
     unset($form['glossary']);
     unset($form['limit']);
     unset($form['add_table']);
     unset($form['require_value']);
-    
+
     //get options & display as options
-	  $previous_db = tripal_db_set_active('chado');
+    $previous_db = tripal_db_set_active('chado');
     $result = db_query("SELECT cvt.cvterm_id as type_id, cvt.name FROM cvterm cvt WHERE cvt.cvterm_id IN (SELECT type_id FROM stockprop)");
     tripal_db_set_active($previous_db);
     $types = array();
-    while ($r = db_fetch_object($result)) { $types[$r->type_id] = $r->name; }
-		$form['stockprop_type_id'] = array(
-			'#type' => 'radios',
-			'#title' => t('Property Types'),
-			'#options' => $types,
-			'#default_value' => $this->options['stockprop_type_id'],
-			'#required' => TRUE,
-			'#description' => t('Select the type of property represented by this argument.'),
-		);
-		
-		$operators = array(
+    while ($r = db_fetch_object($result)) {
+      $types[$r->type_id] = $r->name;
+    }
+    $form['stockprop_type_id'] = array(
+      '#type' => 'radios',
+      '#title' => t('Property Types'),
+      '#options' => $types,
+      '#default_value' => $this->options['stockprop_type_id'],
+      '#required' => TRUE,
+      '#description' => t('Select the type of property represented by this argument.'),
+    );
+
+    $operators = array(
       '=' => t('Is equal to'),
       '!=' => t('Is not equal to'),
       '~' => t('Contains'),
       '!~' => t('Does not contain'),
       'IS NOT NULL' => t('Is Present (Not Empty)'),
-      'IS NULL' => t('Is Absent (Empty)'),		
-		);
-		$form['operator'] = array(
-			'#type' => 'radios',
-			'#title' => 'Operator',
-			'#description' => t('Specify how to compare the argument with the property values.'),
-			'#options' => $operators,
-			'#default_value' => $this->options['operator'],
-			'#required' => TRUE,
-		);
+      'IS NULL' => t('Is Absent (Empty)'),
+    );
+    $form['operator'] = array(
+      '#type' => 'radios',
+      '#title' => 'Operator',
+      '#description' => t('Specify how to compare the argument with the property values.'),
+      '#options' => $operators,
+      '#default_value' => $this->options['operator'],
+      '#required' => TRUE,
+    );
   }
-  
+
   /**
    * Build the query based upon the formula
    */
-	function query() {
+  function query() {
     $argument = $this->argument;
     if (!empty($this->options['transform_dash'])) {
       $argument = strtr($argument, '-', ' ');
     }
-    
-		if (preg_match('/IS NOT NULL/', $this->options['operator'])) {
-			$new_where_sql = "stock.stock_id IN (SELECT stockprop.stock_id FROM stockprop WHERE stockprop.type_id=".$this->options['stockprop_type_id'].")";
-		} elseif (preg_match('/IS NULL/', $this->options['operator'])) {
-			$new_where_sql = "stock.stock_id NOT IN (SELECT stockprop.stock_id FROM stockprop WHERE stockprop.type_id=".$this->options['stockprop_type_id'].")";
-		} else {
-			$new_where_sql = "stock.stock_id IN (SELECT stockprop.stock_id FROM stockprop "
-							. "WHERE stockprop.type_id=".$this->options['stockprop_type_id']." AND stockprop.value".$this->options['operator']."'".$argument."')";
-		}
-		$this->query->add_where($this->options['group'], $new_where_sql);
+
+    if (preg_match('/IS NOT NULL/', $this->options['operator'])) {
+      $new_where_sql = "stock.stock_id IN (SELECT stockprop.stock_id FROM stockprop WHERE stockprop.type_id=" . $this->options['stockprop_type_id'] . ")";
+    }
+    elseif (preg_match('/IS NULL/', $this->options['operator'])) {
+      $new_where_sql = "stock.stock_id NOT IN (SELECT stockprop.stock_id FROM stockprop WHERE stockprop.type_id=" . $this->options['stockprop_type_id'] . ")";
+    }
+    else {
+      $new_where_sql = "stock.stock_id IN (SELECT stockprop.stock_id FROM stockprop "
+              . "WHERE stockprop.type_id=" . $this->options['stockprop_type_id'] . " AND stockprop.value" . $this->options['operator'] . "'" . $argument . "')";
+    }
+    $this->query->add_where($this->options['group'], $new_where_sql);
   }
 
 }

+ 75 - 71
tripal_views/views/handlers/views_handler_field_chado_relationship_all.inc

@@ -1,7 +1,7 @@
 <?php
-// $Id: views_handler_field_term_node_tid.inc,v 1.4 2009/07/01 23:07:14 merlinofchaos Exp $
 
 /**
+ * @file
  * Field handler for terms.
  */
 class views_handler_field_chado_relationship_all extends views_handler_field_prerender_list {
@@ -14,87 +14,91 @@ class views_handler_field_chado_relationship_all extends views_handler_field_pre
     $this->add_additional_fields();
   }
 
-	function pre_render($values) {
-		$this->aliases['relationships'] = 'relationships';
-		$this->aliases['primary_id'] = $this->view->base_table.'_id';
-		$this->field_alias = $this->aliases['primary_id'];
-		$relationship_tablename = $this->view->base_table.'_relationship';
-		$this->aliases['relationship_primary_id'] = $relationship_tablename . '_id';
-		$table_desc = module_invoke_all('chado_'.$relationship_tablename.'_schema');
-		foreach($table_desc['foreign keys'][$this->view->base_table]['columns'] as $k => $v) {
-		  if (preg_match('/subject/',$k)) { $subject_id = $k; }
-		  if (preg_match('/object/', $k)) { $object_id = $k; }
-		}
-		$this->aliases['subject_id'] = $subject_id;
-		$this->aliases['object_id'] = $object_id;
-		  
+  function pre_render($values) {
+    $this->aliases['relationships'] = 'relationships';
+    $this->aliases['primary_id'] = $this->view->base_table . '_id';
+    $this->field_alias = $this->aliases['primary_id'];
+    $relationship_tablename = $this->view->base_table . '_relationship';
+    $this->aliases['relationship_primary_id'] = $relationship_tablename  .  '_id';
+    $table_desc = module_invoke_all('chado_' . $relationship_tablename . '_schema');
+    foreach ($table_desc['foreign keys'][$this->view->base_table]['columns'] as $k => $v) {
+      if (preg_match('/subject/', $k)) {
+        $subject_id = $k;
+      }
+      if (preg_match('/object/', $k)) {
+        $object_id = $k;
+      }
+    }
+    $this->aliases['subject_id'] = $subject_id;
+    $this->aliases['object_id'] = $object_id;
+
     //Add values for all if possible
     if (!$this->view->result[0]->relationships) {
       //get base table primary keys
       $primary_ids = array();
-		  foreach ($this->view->result as $row_num => $row) {
-			  $primary_ids[$row_num] = $row->{$this->aliases['primary_id']};
-		  }
-		
-		  //generate results from db
-      $sql = "SELECT ".$relationship_tablename.".*, cvterm.name as type_name, "
-					."subject_parent.name as subject_name, object_parent.name as object_name "
-					."FROM ".$relationship_tablename." "
-					."LEFT JOIN ".$this->view->base_table." subject_parent ON "
-					  .$relationship_tablename.".".$subject_id."=subject_parent.".$this->aliases['primary_id']." "
-					."LEFT JOIN ".$this->view->base_table." object_parent ON "
-					  .$relationship_tablename.".".$object_id."=object_parent.".$this->aliases['primary_id']." "
-					."LEFT JOIN cvterm cvterm ON "
-					  .$relationship_tablename.".type_id = cvterm.cvterm_id "
-					."WHERE ".$relationship_tablename.".".$subject_id." IN (".implode(',',$primary_ids).") "
-					."OR ".$relationship_tablename.".".$object_id." IN (".implode(',',$primary_ids).") ";
-			$previous_db = tripal_db_set_active('chado');
-			$resource = db_query($sql);
-			tripal_db_set_active($previous_db);
-			
-			//add results to views results
-			while ($r = db_fetch_object($resource)) {
-				if (in_array($r->{$subject_id}, $primary_ids)) {
-					$key = array_search($r->{$subject_id}, $primary_ids);
-					$r->{$this->aliases['primary_id']} = $r->{$subject_id};
-					$this->view->result[$key]->relationships[] = clone $r;
-				}
-				if (in_array($r->{$object_id}, $primary_ids)) {
-					$key = array_search($r->{$object_id}, $primary_ids);
-					$r->{$this->aliases['primary_id']} = $r->{$object_id};
-					$this->view->result[$key]->relationships[] = clone $r;
-				}
-			} //end of while
+      foreach ($this->view->result as $row_num => $row) {
+        $primary_ids[$row_num] = $row->{$this->aliases['primary_id']};
+      }
+
+      //generate results from db
+      $sql = "SELECT " . $relationship_tablename . ".*, cvterm.name as type_name, "
+          ."subject_parent.name as subject_name, object_parent.name as object_name "
+          ."FROM " . $relationship_tablename . " "
+          ."LEFT JOIN " . $this->view->base_table . " subject_parent ON "
+            . $relationship_tablename . "." . $subject_id . "=subject_parent." . $this->aliases['primary_id'] . " "
+          ."LEFT JOIN " . $this->view->base_table . " object_parent ON "
+            . $relationship_tablename . "." . $object_id . "=object_parent." . $this->aliases['primary_id'] . " "
+          ."LEFT JOIN cvterm cvterm ON "
+            . $relationship_tablename . ".type_id = cvterm.cvterm_id "
+          ."WHERE " . $relationship_tablename . "." . $subject_id . " IN (" . implode(',', $primary_ids) . ") "
+          ."OR " . $relationship_tablename . "." . $object_id . " IN (" . implode(',', $primary_ids) . ") ";
+      $previous_db = tripal_db_set_active('chado');
+      $resource = db_query($sql);
+      tripal_db_set_active($previous_db);
+
+      //add results to views results
+      while ($r = db_fetch_object($resource)) {
+        if (in_array($r->{$subject_id}, $primary_ids)) {
+          $key = array_search($r->{$subject_id}, $primary_ids);
+          $r->{$this->aliases['primary_id']} = $r->{$subject_id};
+          $this->view->result[$key]->relationships[] = clone $r;
+        }
+        if (in_array($r->{$object_id}, $primary_ids)) {
+          $key = array_search($r->{$object_id}, $primary_ids);
+          $r->{$this->aliases['primary_id']} = $r->{$object_id};
+          $this->view->result[$key]->relationships[] = clone $r;
+        }
+      } //end of while
     }// end of if add values
 
-		//for each stock in this view page, add the values
-		foreach ($values as $result) {
-			if (!empty($result->{$this->aliases['relationships']})) {
-				
-				// all relationships including the current stock
-				$relationships = $result->{$this->aliases['relationships']};
-				foreach ($relationships as $relationship) {			
-					// Add relationship to the list of items to be rendered
-					// Note: $this->aliases['primary_id'] = base table primary key
-					
-					$elements = array(
-					  $this->aliases['primary_id'] => $relationship->{$this->aliases['primary_id']},
-					  $this->aliases['relationship_primary_id'] => $relationship->{$this->aliases['relationship_primary_id']},
-					  'subject_id' => $relationship->{$this->aliases['subject_id']},
-					  'subject_name' => $relationship->subject_name,
-					  'object_id' => $relationship->{$this->aliases['object_id']},
+    //for each stock in this view page, add the values
+    foreach ($values as $result) {
+      if (!empty($result->{$this->aliases['relationships']})) {
+
+        // all relationships including the current stock
+        $relationships = $result->{$this->aliases['relationships']};
+        foreach ($relationships as $relationship) {
+          // Add relationship to the list of items to be rendered
+          // Note: $this->aliases['primary_id'] = base table primary key
+
+          $elements = array(
+            $this->aliases['primary_id'] => $relationship->{$this->aliases['primary_id']},
+            $this->aliases['relationship_primary_id'] => $relationship->{$this->aliases['relationship_primary_id']},
+            'subject_id' => $relationship->{$this->aliases['subject_id']},
+            'subject_name' => $relationship->subject_name,
+            'object_id' => $relationship->{$this->aliases['object_id']},
             'object_name' => $relationship->object_name,
             'type_id' => $relationship->type_id,
             'type_name' => $relationship->type_name,
-					);
-					$this->items[$relationship->{$this->aliases['primary_id']}][$relationship->{$this->aliases['relationship_primary_id']}] = $elements;
-				}
-			}
-		}
-	}
+          );
+          $this->items[$relationship->{$this->aliases['primary_id']}][$relationship->{$this->aliases['relationship_primary_id']}] = $elements;
+        }
+      }
+    }
+  }
 
   function render_item($count, $item) {
-		return $item['subject_name'].' '.$item['type_name'].' '.$item['object_name'];
+    return $item['subject_name'] . ' ' . $item['type_name'] . ' ' . $item['object_name'];
   }
 
 }

+ 15 - 14
tripal_views/views/handlers/views_handler_field_chado_relationship_by_type.inc

@@ -1,7 +1,7 @@
 <?php
-// $Id: views_handler_field_term_node_tid.inc,v 1.4 2009/07/01 23:07:14 merlinofchaos Exp $
 
 /**
+ * @file
  * Field handler for terms.
  */
 class views_handler_field_chado_relationship_by_type extends views_handler_field_prerender_list {
@@ -10,7 +10,7 @@ class views_handler_field_chado_relationship_by_type extends views_handler_field
 
     // Boolean to determine whether
     //    TRUE =>  value (property type)      -more than one property type displayed
-    //    FALSE => or just value is rendered  -only 1 porperty type is displayed    
+    //    FALSE => or just value is rendered  -only 1 porperty type is displayed
     $this->display_type = TRUE;
 
   }
@@ -18,7 +18,7 @@ class views_handler_field_chado_relationship_by_type extends views_handler_field
   function option_definition() {
     $options = parent::option_definition();
     $options['stockrel_type_ids'] = array('default' => array());
-    $options['stockrel_display_options'] = array('default' => array('subject','type','object'));
+    $options['stockrel_display_options'] = array('default' => array('subject', 'type', 'object'));
     return $options;
   }
 
@@ -42,7 +42,7 @@ class views_handler_field_chado_relationship_by_type extends views_handler_field
       ),
       '#default_value' => array($this->options['stockrel_display_parts']['subject'], $this->options['stockrel_display_parts']['type'], $this->options['stockrel_display_parts']['object']),
     );
-    
+
     $form['stockrel_display_rels'] = array(
       '#type' => 'radios',
       '#title' => t('Display Relationships Where'),
@@ -59,7 +59,7 @@ class views_handler_field_chado_relationship_by_type extends views_handler_field
       ),
       '#default_value' => $this->options['stockrel_display_rels'],
     );
-    
+
     $options = tripal_cv_get_cvterm_options( variable_get('chado_stock_relationship_cv', 'null') );
     $form['stockrel_type_ids'] = array(
       '#type' => 'checkboxes',
@@ -80,14 +80,14 @@ class views_handler_field_chado_relationship_by_type extends views_handler_field
     $this->aliases['relationships'] = 'relationships';
     $this->aliases['stock_id'] = 'stock_id';
     $this->field_alias = $this->aliases['stock_id'];
-    
+
     //for each stock in this view page
     foreach ($values as $result) {
       if (!empty($result->{$this->aliases['relationships']})) {
-          
+
         // all relationships including the current stock
         $relationships = $result->{$this->aliases['relationships']};
-        foreach ($relationships as $relationship) {      
+        foreach ($relationships as $relationship) {
           // perform filtering------
           //type
           if (!empty($this->options['stockrel_type_ids'])) {
@@ -96,18 +96,19 @@ class views_handler_field_chado_relationship_by_type extends views_handler_field
               continue;
             }
           }
-          
+
           //"Display Relationships Where" criteria
           if (preg_match('/subject/', $this->options['stockrel_display_rels'])) {
             if ($relationship->stock_id != $relationship->subject_id) {
               continue;
-            }      
-          } elseif (preg_match('/object/', $this->options['stockrel_display_rels'])) {
+            }
+          }
+          elseif (preg_match('/object/', $this->options['stockrel_display_rels'])) {
             if ($relationship->stock_id != $relationship->object_id) {
               continue;
             }
           }
-          
+
           // Add relationship to the list of items to be rendered
           $this->items[$relationship->stock_id][$relationship->stock_relationship_id]['stock_id'] = $relationship->stock_id;
           $this->items[$relationship->stock_id][$relationship->stock_relationship_id]['stock_relationship_id'] = $relationship->stock_relationship_id;
@@ -124,7 +125,7 @@ class views_handler_field_chado_relationship_by_type extends views_handler_field
 
   function render_item($count, $item) {
     $text = array();
-    
+
     // Render Parts
     if ($this->options['stockrel_display_parts']['subject']) {
       $text[] = $item['subject_name'];
@@ -135,7 +136,7 @@ class views_handler_field_chado_relationship_by_type extends views_handler_field
     if ($this->options['stockrel_display_parts']['object']) {
       $text[] = $item['object_name'];
     }
-    
+
     return implode(' ', $text);
   }
 

+ 0 - 26
tripal_views/views/handlers/views_handler_field_computed_stock_nid.inc

@@ -1,26 +0,0 @@
-<?php
-
-/**
- * Adds the Node ID to for the current stock 
- *
- * This handler is only needed if chado is in a separate database and, therefore, the node tables 
- * cannot be joined to the stock tables
- *
- * @ingroup tripal_stock
- * @ingroup views_field_handlers
- */
-class views_handler_field_computed_stock_nid extends views_handler_field_numeric {
-	function construct() {
-		parent::construct();
-		$this->additional_fields['stock_id'] = array('table' => 'stock', 'field' => 'stock_id');
-	}
-
-	function query() { 
-		$this->ensure_my_table();
-		$this->add_additional_fields(); 
-	}
-
-	function render($values) { 
-		return $values->stock_nid;
-	}
-} 

+ 53 - 51
tripal_views/views/handlers/views_handler_field_stock_dbxref_all.inc

@@ -1,9 +1,10 @@
 <?php
 
 /**
+ * @file
  * Field handler allowing all database references for a given stock to be displayed in a single cell
  *
- * This handler only deals with database references joined to the stock through stock_dbxref. For 
+ * This handler only deals with database references joined to the stock through stock_dbxref. For
  * the database reference joined to the stock by stock.dbxref_id simply join to the dbxref table.
  *
  * @ingroup tripal_stock
@@ -21,66 +22,67 @@ class views_handler_field_stock_dbxref_all extends views_handler_field_prerender
     $this->add_additional_fields();
   }
 
-	function pre_render($values) {
-		$this->aliases['dbxref'] = 'dbxref';
-		$this->aliases['stock_id'] = 'stock_id';
-		$this->field_alias = $this->aliases['stock_id'];
-		
-		//for each stock in this view page
-		foreach ($values as $result) {
-			if (!empty($result->{$this->aliases['dbxref']})) {
-				
-				// all dbxrefs including the current stock
-				$dbxrefs = $result->{$this->aliases['dbxref']};
-				foreach ($dbxrefs as $dbxref) {			
-					// Add dbxref to the list of items to be rendered
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['stock_id'] = $dbxref->stock_id;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['stock_dbxref_id'] = $dbxref->stock_dbxref_id;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['dbxref_id'] = $dbxref->dbxref_id;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['is_current'] = $dbxref->is_current;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['db_id'] = $dbxref->db_id;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['db_name'] = $dbxref->db_name;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['urlprefix'] = $dbxref->urlprefix;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['accession'] = $dbxref->accession;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['version'] = $dbxref->version;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['description'] = $dbxref->description;
-				}
-			}
-		}
-	}
+  function pre_render($values) {
+    $this->aliases['dbxref'] = 'dbxref';
+    $this->aliases['stock_id'] = 'stock_id';
+    $this->field_alias = $this->aliases['stock_id'];
+
+    //for each stock in this view page
+    foreach ($values as $result) {
+      if (!empty($result->{$this->aliases['dbxref']})) {
+
+        // all dbxrefs including the current stock
+        $dbxrefs = $result->{$this->aliases['dbxref']};
+        foreach ($dbxrefs as $dbxref) {
+          // Add dbxref to the list of items to be rendered
+          $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['stock_id'] = $dbxref->stock_id;
+          $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['stock_dbxref_id'] = $dbxref->stock_dbxref_id;
+          $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['dbxref_id'] = $dbxref->dbxref_id;
+          $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['is_current'] = $dbxref->is_current;
+          $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['db_id'] = $dbxref->db_id;
+          $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['db_name'] = $dbxref->db_name;
+          $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['urlprefix'] = $dbxref->urlprefix;
+          $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['accession'] = $dbxref->accession;
+          $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['version'] = $dbxref->version;
+          $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['description'] = $dbxref->description;
+        }
+      }
+    }
+  }
 
   function render_item($count, $item) {
-		if (!empty($item['urlprefix'])) {
-			return l($item['accession'],$item['urlprefix'].$item['accession']).' ('.$item['db_name'].')';
-		} else {
-			return $item['accession'].' ('.$item['db_name'].')';
-		}
+    if (!empty($item['urlprefix'])) {
+      return l($item['accession'], $item['urlprefix'] . $item['accession']) . ' (' . $item['db_name'] . ')';
+    }
+    else {
+      return $item['accession'] . ' (' . $item['db_name'] . ')';
+    }
   }
 
   function document_self_tokens(&$tokens) {
     $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = t('The Stock ID.');
-		$tokens['[' . $this->options['id'] . '-stock_dbxref_id' . ']'] = t('Stock Database Reference ID');
-		$tokens['[' . $this->options['id'] . '-dbxref_id' . ']'] = t('Database Reference ID');
-		$tokens['[' . $this->options['id'] . '-is_current' . ']'] = t('Is Current');
-		$tokens['[' . $this->options['id'] . '-db_id' . ']'] = t('Database ID');
-		$tokens['[' . $this->options['id'] . '-db_name' . ']'] = t('Database Name');
-		$tokens['[' . $this->options['id'] . '-urlprefix' . ']'] = t('URL Prefix');
-		$tokens['[' . $this->options['id'] . '-accession' . ']'] = t('Accession');
-		$tokens['[' . $this->options['id'] . '-version' . ']'] = t('Version');
-		$tokens['[' . $this->options['id'] . '-description' . ']'] = t('Description');
+    $tokens['[' . $this->options['id'] . '-stock_dbxref_id' . ']'] = t('Stock Database Reference ID');
+    $tokens['[' . $this->options['id'] . '-dbxref_id' . ']'] = t('Database Reference ID');
+    $tokens['[' . $this->options['id'] . '-is_current' . ']'] = t('Is Current');
+    $tokens['[' . $this->options['id'] . '-db_id' . ']'] = t('Database ID');
+    $tokens['[' . $this->options['id'] . '-db_name' . ']'] = t('Database Name');
+    $tokens['[' . $this->options['id'] . '-urlprefix' . ']'] = t('URL Prefix');
+    $tokens['[' . $this->options['id'] . '-accession' . ']'] = t('Accession');
+    $tokens['[' . $this->options['id'] . '-version' . ']'] = t('Version');
+    $tokens['[' . $this->options['id'] . '-description' . ']'] = t('Description');
   }
 
   function add_self_tokens(&$tokens, $item) {
     $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = $item['stock_id'];
-		$tokens['[' . $this->options['id'] . '-stock_dbxref_id' . ']'] = $item['stock_dbxref_id'];
-		$tokens['[' . $this->options['id'] . '-dbxref_id' . ']'] =  $item['dbxref_id'];
-		$tokens['[' . $this->options['id'] . '-is_current' . ']'] = $item['is_current'];
-		$tokens['[' . $this->options['id'] . '-db_id' . ']'] = $item['db_id'];
-		$tokens['[' . $this->options['id'] . '-db_name' . ']'] = $item['db_name'];
-		$tokens['[' . $this->options['id'] . '-urlprefix' . ']'] = $item['urlprefix'];
-		$tokens['[' . $this->options['id'] . '-accession' . ']'] = $item['accession'];
-		$tokens['[' . $this->options['id'] . '-version' . ']'] = $item['version'];
-		$tokens['[' . $this->options['id'] . '-description' . ']'] = $item['description'];
+    $tokens['[' . $this->options['id'] . '-stock_dbxref_id' . ']'] = $item['stock_dbxref_id'];
+    $tokens['[' . $this->options['id'] . '-dbxref_id' . ']'] =  $item['dbxref_id'];
+    $tokens['[' . $this->options['id'] . '-is_current' . ']'] = $item['is_current'];
+    $tokens['[' . $this->options['id'] . '-db_id' . ']'] = $item['db_id'];
+    $tokens['[' . $this->options['id'] . '-db_name' . ']'] = $item['db_name'];
+    $tokens['[' . $this->options['id'] . '-urlprefix' . ']'] = $item['urlprefix'];
+    $tokens['[' . $this->options['id'] . '-accession' . ']'] = $item['accession'];
+    $tokens['[' . $this->options['id'] . '-version' . ']'] = $item['version'];
+    $tokens['[' . $this->options['id'] . '-description' . ']'] = $item['description'];
   }
 }
 

+ 100 - 96
tripal_views/views/handlers/views_handler_field_stock_dbxref_by_type.inc

@@ -1,10 +1,11 @@
 <?php
 
 /**
- * Field handler allowing all database references of a specified db for a given stock to be 
+ * @file
+ * Field handler allowing all database references of a specified db for a given stock to be
  * displayed in a single cell.
  *
- * This handler only deals with database references joined to the stock through stock_dbxref. For 
+ * This handler only deals with database references joined to the stock through stock_dbxref. For
  * the database reference joined to the stock by stock.dbxref_id simply join to the dbxref table.
  *
  * @ingroup tripal_stock
@@ -16,7 +17,7 @@ class views_handler_field_stock_dbxref_by_type extends views_handler_field_prere
 
     // Boolean to determine whether
     //    TRUE =>  value (property type)      -more than one property type displayed
-    //    FALSE => or just value is rendered  -only 1 porperty type is displayed    
+    //    FALSE => or just value is rendered  -only 1 porperty type is displayed
     $this->display_type = TRUE;
 
   }
@@ -24,7 +25,7 @@ class views_handler_field_stock_dbxref_by_type extends views_handler_field_prere
   function option_definition() {
     $options = parent::option_definition();
     $options['stockprop_type_ids'] = array('default' => array());
-		$options['display_options'] = array('default' => array('accession','db_name','link'));
+    $options['display_options'] = array('default' => array('accession', 'db_name', 'link'));
     return $options;
   }
 
@@ -34,23 +35,23 @@ class views_handler_field_stock_dbxref_by_type extends views_handler_field_prere
   function options_form(&$form, &$form_state) {
     parent::options_form($form, $form_state);
 
-		$form['display_options'] = array(
-			'#type' => 'checkboxes',
-			'#title' => t('Display DB Reference Parts'),
-			'#description' => t('Check each part of the database reference you want displayed where the parts '
-				.'of a database relationship are: <Accession> (<Datbase Name>). You can also specify whether the accession '
-				.'should be linked to the record in the database by checking "Link to External Record".'),
-			'#options' => array(
-				'accession' => 'Accession',
-				'db_name' => 'Database Name',
-				'link' => 'Link to External Record',
-			),
-			'#default_value' => array($this->options['display_options']['accession'], $this->options['display_options']['db_name'], $this->options['display_options']['link']),
-		);
-		
+    $form['display_options'] = array(
+      '#type' => 'checkboxes',
+      '#title' => t('Display DB Reference Parts'),
+      '#description' => t('Check each part of the database reference you want displayed where the parts '
+        ."of a database relationship are: \<Accession\> (\<Datbase Name\>). You can also specify whether the accession "
+        .'should be linked to the record in the database by checking "Link to External Record".'),
+      '#options' => array(
+        'accession' => 'Accession',
+        'db_name' => 'Database Name',
+        'link' => 'Link to External Record',
+      ),
+      '#default_value' => array($this->options['display_options']['accession'], $this->options['display_options']['db_name'], $this->options['display_options']['link']),
+    );
+
     $db_options = tripal_db_get_db_options();
-	  $db_options[0] = 'Select a Database';
-	  ksort($db_options);
+    $db_options[0] = 'Select a Database';
+    ksort($db_options);
     $form['db_ids'] = array(
       '#type' => 'checkboxes',
       '#title' => t('Database'),
@@ -66,92 +67,95 @@ class views_handler_field_stock_dbxref_by_type extends views_handler_field_prere
     $this->add_additional_fields();
   }
 
-	function pre_render($values) {
-		$this->aliases['dbxref'] = 'dbxref';
-		$this->aliases['stock_id'] = 'stock_id';
-		$this->field_alias = $this->aliases['stock_id'];
-		
-		//for each stock in this view page
-		foreach ($values as $result) {
-			if (!empty($result->{$this->aliases['dbxref']})) {
-				
-				// all dbxrefs including the current stock
-				$dbxrefs = $result->{$this->aliases['dbxref']};
-				foreach ($dbxrefs as $dbxref) {
-							
-					// perform filtering
-					if (!empty($this->options['db_ids'])) {
-						$dbs2keep = array_filter($this->options['db_ids']);
-						if (!in_array($dbxref->db_id, $dbs2keep)) {
-							continue;
-						}
-					}
-					
-					// Add dbxref to the list of items to be rendered
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['stock_id'] = $dbxref->stock_id;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['stock_dbxref_id'] = $dbxref->stock_dbxref_id;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['dbxref_id'] = $dbxref->dbxref_id;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['is_current'] = $dbxref->is_current;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['db_id'] = $dbxref->db_id;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['db_name'] = $dbxref->db_name;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['urlprefix'] = $dbxref->urlprefix;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['accession'] = $dbxref->accession;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['version'] = $dbxref->version;
-					$this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['description'] = $dbxref->description;				}
-			}
-		}
-	}
+  function pre_render($values) {
+    $this->aliases['dbxref'] = 'dbxref';
+    $this->aliases['stock_id'] = 'stock_id';
+    $this->field_alias = $this->aliases['stock_id'];
+
+    //for each stock in this view page
+    foreach ($values as $result) {
+      if (!empty($result->{$this->aliases['dbxref']})) {
+
+        // all dbxrefs including the current stock
+        $dbxrefs = $result->{$this->aliases['dbxref']};
+        foreach ($dbxrefs as $dbxref) {
+
+          // perform filtering
+          if (!empty($this->options['db_ids'])) {
+            $dbs2keep = array_filter($this->options['db_ids']);
+            if (!in_array($dbxref->db_id, $dbs2keep)) {
+              continue;
+            }
+          }
+
+          // Add dbxref to the list of items to be rendered
+          $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['stock_id'] = $dbxref->stock_id;
+          $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['stock_dbxref_id'] = $dbxref->stock_dbxref_id;
+          $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['dbxref_id'] = $dbxref->dbxref_id;
+          $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['is_current'] = $dbxref->is_current;
+          $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['db_id'] = $dbxref->db_id;
+          $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['db_name'] = $dbxref->db_name;
+          $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['urlprefix'] = $dbxref->urlprefix;
+          $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['accession'] = $dbxref->accession;
+          $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['version'] = $dbxref->version;
+          $this->items[$dbxref->stock_id][$dbxref->stock_dbxref_id]['description'] = $dbxref->description;        }
+      }
+    }
+  }
 
   function render_item($count, $item) {
-		$text = array();
-		if ($this->options['display_options']['link']) {
-			if ($this->options['display_options']['accession']) {
-				$text[] = l($item['accession'],$item['urlprefix'].$item['accession']);
-			} else {
-				$text[] = l('External Record',$item['urlprefix'].$item['accession']);
-			}	
-		} else {
-			if ($this->options['display_options']['accession']) {
-				$text[] = $item['accession'];
-			}
-		}
-		
-		
-		if ($this->options['display_options']['db_name']) {
-			$text[] = $item['db_name'];
-		}
-		
-		if (sizeof($text) > 1) {
-			return $text[0].' ('.$text[1].')';
-		} else {
-			return $text[0];
-		}
+    $text = array();
+    if ($this->options['display_options']['link']) {
+      if ($this->options['display_options']['accession']) {
+        $text[] = l(t($item['accession']), $item['urlprefix'] . $item['accession']);
+      }
+      else {
+        $text[] = l(t('External Record'), $item['urlprefix'] . $item['accession']);
+      }
+    }
+    else {
+      if ($this->options['display_options']['accession']) {
+        $text[] = $item['accession'];
+      }
+    }
+
+
+    if ($this->options['display_options']['db_name']) {
+      $text[] = $item['db_name'];
+    }
+
+    if (sizeof($text) > 1) {
+      return $text[0] . ' (' . $text[1] . ')';
+    }
+    else {
+      return $text[0];
+    }
   }
 
   function document_self_tokens(&$tokens) {
     $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = t('The Stock ID.');
-		$tokens['[' . $this->options['id'] . '-stock_dbxref_id' . ']'] = t('Stock Database Reference ID');
-		$tokens['[' . $this->options['id'] . '-dbxref_id' . ']'] = t('Database Reference ID');
-		$tokens['[' . $this->options['id'] . '-is_current' . ']'] = t('Is Current');
-		$tokens['[' . $this->options['id'] . '-db_id' . ']'] = t('Database ID');
-		$tokens['[' . $this->options['id'] . '-db_name' . ']'] = t('Database Name');
-		$tokens['[' . $this->options['id'] . '-urlprefix' . ']'] = t('URL Prefix');
-		$tokens['[' . $this->options['id'] . '-accession' . ']'] = t('Accession');
-		$tokens['[' . $this->options['id'] . '-version' . ']'] = t('Version');
-		$tokens['[' . $this->options['id'] . '-description' . ']'] = t('Description');
+    $tokens['[' . $this->options['id'] . '-stock_dbxref_id' . ']'] = t('Stock Database Reference ID');
+    $tokens['[' . $this->options['id'] . '-dbxref_id' . ']'] = t('Database Reference ID');
+    $tokens['[' . $this->options['id'] . '-is_current' . ']'] = t('Is Current');
+    $tokens['[' . $this->options['id'] . '-db_id' . ']'] = t('Database ID');
+    $tokens['[' . $this->options['id'] . '-db_name' . ']'] = t('Database Name');
+    $tokens['[' . $this->options['id'] . '-urlprefix' . ']'] = t('URL Prefix');
+    $tokens['[' . $this->options['id'] . '-accession' . ']'] = t('Accession');
+    $tokens['[' . $this->options['id'] . '-version' . ']'] = t('Version');
+    $tokens['[' . $this->options['id'] . '-description' . ']'] = t('Description');
   }
 
   function add_self_tokens(&$tokens, $item) {
     $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = $item['stock_id'];
-		$tokens['[' . $this->options['id'] . '-stock_dbxref_id' . ']'] = $item['stock_dbxref_id'];
-		$tokens['[' . $this->options['id'] . '-dbxref_id' . ']'] =  $item['dbxref_id'];
-		$tokens['[' . $this->options['id'] . '-is_current' . ']'] = $item['is_current'];
-		$tokens['[' . $this->options['id'] . '-db_id' . ']'] = $item['db_id'];
-		$tokens['[' . $this->options['id'] . '-db_name' . ']'] = $item['db_name'];
-		$tokens['[' . $this->options['id'] . '-urlprefix' . ']'] = $item['urlprefix'];
-		$tokens['[' . $this->options['id'] . '-accession' . ']'] = $item['accession'];
-		$tokens['[' . $this->options['id'] . '-version' . ']'] = $item['version'];
-		$tokens['[' . $this->options['id'] . '-description' . ']'] = $item['description'];
+    $tokens['[' . $this->options['id'] . '-stock_dbxref_id' . ']'] = $item['stock_dbxref_id'];
+    $tokens['[' . $this->options['id'] . '-dbxref_id' . ']'] =  $item['dbxref_id'];
+    $tokens['[' . $this->options['id'] . '-is_current' . ']'] = $item['is_current'];
+    $tokens['[' . $this->options['id'] . '-db_id' . ']'] = $item['db_id'];
+    $tokens['[' . $this->options['id'] . '-db_name' . ']'] = $item['db_name'];
+    $tokens['[' . $this->options['id'] . '-urlprefix' . ']'] = $item['urlprefix'];
+    $tokens['[' . $this->options['id'] . '-accession' . ']'] = $item['accession'];
+    $tokens['[' . $this->options['id'] . '-version' . ']'] = $item['version'];
+    $tokens['[' . $this->options['id'] . '-description' . ']'] = $item['description'];
   }
 }
 

+ 25 - 24
tripal_views/views/handlers/views_handler_field_stockprop_all.inc

@@ -1,6 +1,7 @@
 <?php
 
 /**
+ * @file
  * Field handler allowing all properties for a given stock to be displayed in a single cell
  *
  * @ingroup tripal_stock
@@ -18,32 +19,32 @@ class views_handler_field_stockprop_all extends views_handler_field_prerender_li
     $this->add_additional_fields();
   }
 
-	function pre_render($values) {
-		$this->aliases['properties'] = 'properties';
-		$this->aliases['stock_id'] = 'stock_id';
-		$this->field_alias = $this->aliases['stock_id'];
-		
-		//for each stock in this view page
-		foreach ($values as $result) {
-			if (!empty($result->{$this->aliases['properties']})) {
-				
-				// all properties for the current stock
-				$properties = $result->{$this->aliases['properties']};
-				foreach ($properties as $property) {					
-					// Add property to the list of items to be rendered
-					$this->items[$property->stock_id][$property->stockprop_id]['stock_id'] = $property->stock_id;
-					$this->items[$property->stock_id][$property->stockprop_id]['stockprop_id'] = $property->stockprop_id;
-					$this->items[$property->stock_id][$property->stockprop_id]['type_id'] = $property->type_id;
-					$this->items[$property->stock_id][$property->stockprop_id]['type_name'] = check_plain($property->type_name);
-					$this->items[$property->stock_id][$property->stockprop_id]['value'] = check_plain($property->value);
-					$this->items[$property->stock_id][$property->stockprop_id]['rank'] = $property->rank;
-				}
-			}
-		}
-	}
+  function pre_render($values) {
+    $this->aliases['properties'] = 'properties';
+    $this->aliases['stock_id'] = 'stock_id';
+    $this->field_alias = $this->aliases['stock_id'];
+
+    //for each stock in this view page
+    foreach ($values as $result) {
+      if (!empty($result->{$this->aliases['properties']})) {
+
+        // all properties for the current stock
+        $properties = $result->{$this->aliases['properties']};
+        foreach ($properties as $property) {
+          // Add property to the list of items to be rendered
+          $this->items[$property->stock_id][$property->stockprop_id]['stock_id'] = $property->stock_id;
+          $this->items[$property->stock_id][$property->stockprop_id]['stockprop_id'] = $property->stockprop_id;
+          $this->items[$property->stock_id][$property->stockprop_id]['type_id'] = $property->type_id;
+          $this->items[$property->stock_id][$property->stockprop_id]['type_name'] = check_plain($property->type_name);
+          $this->items[$property->stock_id][$property->stockprop_id]['value'] = check_plain($property->value);
+          $this->items[$property->stock_id][$property->stockprop_id]['rank'] = $property->rank;
+        }
+      }
+    }
+  }
 
   function render_item($count, $item) {
-		return $item['value'].' ('.$item['type_name'].')';
+    return $item['value'] . ' (' . $item['type_name'] . ')';
   }
 
   function document_self_tokens(&$tokens) {

+ 18 - 15
tripal_views/views/handlers/views_handler_field_stockprop_by_type.inc

@@ -1,7 +1,8 @@
 <?php
 
 /**
- * Field handler allowing all properties of a specified type for a given stock to be displayed in a 
+ * @file
+ * Field handler allowing all properties of a specified type for a given stock to be displayed in a
  * single cell
  *
  * @ingroup tripal_stock
@@ -9,7 +10,7 @@
  */
 class views_handler_field_stockprop_by_type extends views_handler_field_prerender_list {
   function init(&$view, $options) {
-    parent::init($view, $options);    
+    parent::init($view, $options);
   }
 
   function option_definition() {
@@ -40,7 +41,7 @@ class views_handler_field_stockprop_by_type extends views_handler_field_prerende
       ),
       '#default_value' => array($this->options['stockprop_display_options']['type'], $this->options['stockprop_display_options']['value']),
     );
-    
+
     $options = tripal_cv_get_cvterm_options( variable_get('chado_stock_prop_types_cv', 'null') );
     $form['stockprop_type_ids'] = array(
       '#prefix' => '<div><div id="edit-options-stockprop_type_ids">',
@@ -51,7 +52,7 @@ class views_handler_field_stockprop_by_type extends views_handler_field_prerende
       '#default_value' => $this->options['stockprop_type_ids'],
     );
   }
-  
+
   /**
    * Add this term to the query
    */
@@ -63,11 +64,11 @@ class views_handler_field_stockprop_by_type extends views_handler_field_prerende
     $this->aliases['properties'] = 'properties';
     $this->aliases['stock_id'] = 'stock_id';
     $this->field_alias = $this->aliases['stock_id'];
-    
+
     //for each stock in this view page
     foreach ($values as $result) {
       if (!empty($result->{$this->aliases['properties']})) {
-        
+
         // all properties for the current stock
         $properties = $result->{$this->aliases['properties']};
         foreach ($properties as $property) {
@@ -78,7 +79,7 @@ class views_handler_field_stockprop_by_type extends views_handler_field_prerende
               continue;
             }
           }
-          
+
           // Add property to the list of items to be rendered
           $this->items[$property->stock_id][$property->stockprop_id]['stock_id'] = $property->stock_id;
           $this->items[$property->stock_id][$property->stockprop_id]['stockprop_id'] = $property->stockprop_id;
@@ -93,23 +94,25 @@ class views_handler_field_stockprop_by_type extends views_handler_field_prerende
 
   function render_item($count, $item) {
     $text = array();
-    
+
     if ($this->options['stockprop_display_options']['value']) {
       if ($item['value']) {
         $text[] =  $item['value'];
-      } else {
+      }
+      else {
         //display checkmark image
-        $image_path = drupal_get_path('module','tripal_core').'/images/checkmark.gif';
-        $text[] = '<img border="0" src="'.url($image_path).'" alt="checkmark" />';
+        $image_path = drupal_get_path('module', 'tripal_core') . '/images/checkmark.gif';
+        $text[] = '<img border="0" src="' . url($image_path) . '" alt="checkmark" />';
       }
-    } 
+    }
     if ($this->options['stockprop_display_options']['type']) {
       $text[] = $item['type_name'];
     }
-  
+
     if (sizeof($text) > 1) {
-      return $text[0].' ('.$text[1].')';
-    } else {
+      return $text[0] . ' (' . $text[1] . ')';
+    }
+    else {
       return $text[0];
     }
   }

+ 41 - 40
tripal_views/views/handlers/views_handler_field_stockrel_all.inc

@@ -1,6 +1,7 @@
 <?php
 
 /**
+ * @file
  * Field handler allowing all relationships for a given stock to be displayed in a single cell
  *
  * @ingroup tripal_stock
@@ -18,56 +19,56 @@ class views_handler_field_stockrel_all extends views_handler_field_prerender_lis
     $this->add_additional_fields();
   }
 
-	function pre_render($values) {
-		$this->aliases['relationships'] = 'relationships';
-		$this->aliases['stock_id'] = 'stock_id';
-		$this->field_alias = $this->aliases['stock_id'];
-		
-		//for each stock in this view page
-		foreach ($values as $result) {
-			if (!empty($result->{$this->aliases['relationships']})) {
-				
-				// all relationships including the current stock
-				$relationships = $result->{$this->aliases['relationships']};
-				foreach ($relationships as $relationship) {			
-					// Add relationship to the list of items to be rendered
-					$this->items[$relationship->stock_id][$relationship->stock_relationship_id]['stock_id'] = $relationship->stock_id;
-					$this->items[$relationship->stock_id][$relationship->stock_relationship_id]['stock_relationship_id'] = $relationship->stock_relationship_id;
-					$this->items[$relationship->stock_id][$relationship->stock_relationship_id]['subject_id'] = $relationship->subject_id;
-					$this->items[$relationship->stock_id][$relationship->stock_relationship_id]['subject_name'] = $relationship->subject_name;
-					$this->items[$relationship->stock_id][$relationship->stock_relationship_id]['object_id'] = $relationship->object_id;
-					$this->items[$relationship->stock_id][$relationship->stock_relationship_id]['object_name'] = $relationship->object_name;
-					$this->items[$relationship->stock_id][$relationship->stock_relationship_id]['type_id'] = $relationship->type_id;
-					$this->items[$relationship->stock_id][$relationship->stock_relationship_id]['type_name'] = $relationship->type_name;
-				}
-			}
-		}
-	}
+  function pre_render($values) {
+    $this->aliases['relationships'] = 'relationships';
+    $this->aliases['stock_id'] = 'stock_id';
+    $this->field_alias = $this->aliases['stock_id'];
+
+    //for each stock in this view page
+    foreach ($values as $result) {
+      if (!empty($result->{$this->aliases['relationships']})) {
+
+        // all relationships including the current stock
+        $relationships = $result->{$this->aliases['relationships']};
+        foreach ($relationships as $relationship) {
+          // Add relationship to the list of items to be rendered
+          $this->items[$relationship->stock_id][$relationship->stock_relationship_id]['stock_id'] = $relationship->stock_id;
+          $this->items[$relationship->stock_id][$relationship->stock_relationship_id]['stock_relationship_id'] = $relationship->stock_relationship_id;
+          $this->items[$relationship->stock_id][$relationship->stock_relationship_id]['subject_id'] = $relationship->subject_id;
+          $this->items[$relationship->stock_id][$relationship->stock_relationship_id]['subject_name'] = $relationship->subject_name;
+          $this->items[$relationship->stock_id][$relationship->stock_relationship_id]['object_id'] = $relationship->object_id;
+          $this->items[$relationship->stock_id][$relationship->stock_relationship_id]['object_name'] = $relationship->object_name;
+          $this->items[$relationship->stock_id][$relationship->stock_relationship_id]['type_id'] = $relationship->type_id;
+          $this->items[$relationship->stock_id][$relationship->stock_relationship_id]['type_name'] = $relationship->type_name;
+        }
+      }
+    }
+  }
 
   function render_item($count, $item) {
-		return $item['subject_name'].' '.$item['type_name'].' '.$item['object_name'];
+    return $item['subject_name'] . ' ' . $item['type_name'] . ' ' . $item['object_name'];
   }
 
   function document_self_tokens(&$tokens) {
     $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = t('The Stock ID.');
-		$tokens['[' . $this->options['id'] . '-stock_relationship_id' . ']'] = t('Relationship ID');
-		$tokens['[' . $this->options['id'] . '-subject_id' . ']'] = t('Subject ID');
-		$tokens['[' . $this->options['id'] . '-subject_name' . ']'] = t('Subject Name');
-		$tokens['[' . $this->options['id'] . '-object_id' . ']'] = t('Object ID');
-		$tokens['[' . $this->options['id'] . '-object_name' . ']'] = t('Object Name');
-		$tokens['[' . $this->options['id'] . '-type_id' . ']'] = t('Type ID');
-		$tokens['[' . $this->options['id'] . '-type_name' . ']'] = t('Type Name');
+    $tokens['[' . $this->options['id'] . '-stock_relationship_id' . ']'] = t('Relationship ID');
+    $tokens['[' . $this->options['id'] . '-subject_id' . ']'] = t('Subject ID');
+    $tokens['[' . $this->options['id'] . '-subject_name' . ']'] = t('Subject Name');
+    $tokens['[' . $this->options['id'] . '-object_id' . ']'] = t('Object ID');
+    $tokens['[' . $this->options['id'] . '-object_name' . ']'] = t('Object Name');
+    $tokens['[' . $this->options['id'] . '-type_id' . ']'] = t('Type ID');
+    $tokens['[' . $this->options['id'] . '-type_name' . ']'] = t('Type Name');
   }
 
   function add_self_tokens(&$tokens, $item) {
     $tokens['[' . $this->options['id'] . '-stock_id' . ']'] = $item['stock_id'];
-		$tokens['[' . $this->options['id'] . '-stock_relationship_id' . ']'] = $item['stock_relationship_id'];
-		$tokens['[' . $this->options['id'] . '-subject_id' . ']'] = $item['subject_id'];
-		$tokens['[' . $this->options['id'] . '-subject_name' . ']'] = $item['subject_name'];
-		$tokens['[' . $this->options['id'] . '-object_id' . ']'] = $item['object_id'];
-		$tokens['[' . $this->options['id'] . '-object_name' . ']'] = $item['object_name'];
-		$tokens['[' . $this->options['id'] . '-type_id' . ']'] = $item['type_id'];
-		$tokens['[' . $this->options['id'] . '-type_name' . ']'] = $item['type_name'];
+    $tokens['[' . $this->options['id'] . '-stock_relationship_id' . ']'] = $item['stock_relationship_id'];
+    $tokens['[' . $this->options['id'] . '-subject_id' . ']'] = $item['subject_id'];
+    $tokens['[' . $this->options['id'] . '-subject_name' . ']'] = $item['subject_name'];
+    $tokens['[' . $this->options['id'] . '-object_id' . ']'] = $item['object_id'];
+    $tokens['[' . $this->options['id'] . '-object_name' . ']'] = $item['object_name'];
+    $tokens['[' . $this->options['id'] . '-type_id' . ']'] = $item['type_id'];
+    $tokens['[' . $this->options['id'] . '-type_name' . ']'] = $item['type_name'];
 
   }
 }

+ 16 - 14
tripal_views/views/handlers/views_handler_field_stockrel_by_type.inc

@@ -1,7 +1,8 @@
 <?php
 
 /**
- * Field handler allowing all relationships of a specified type for a given stock to be displayed in 
+ * @file
+ * Field handler allowing all relationships of a specified type for a given stock to be displayed in
  * a single cell
  *
  * @ingroup tripal_stock
@@ -13,7 +14,7 @@ class views_handler_field_stockrel_by_type extends views_handler_field_prerender
 
     // Boolean to determine whether
     //    TRUE =>  value (property type)      -more than one property type displayed
-    //    FALSE => or just value is rendered  -only 1 porperty type is displayed    
+    //    FALSE => or just value is rendered  -only 1 porperty type is displayed
     $this->display_type = TRUE;
 
   }
@@ -21,7 +22,7 @@ class views_handler_field_stockrel_by_type extends views_handler_field_prerender
   function option_definition() {
     $options = parent::option_definition();
     $options['stockrel_type_ids'] = array('default' => array());
-    $options['stockrel_display_options'] = array('default' => array('subject','type','object'));
+    $options['stockrel_display_options'] = array('default' => array('subject', 'type', 'object'));
     return $options;
   }
 
@@ -45,7 +46,7 @@ class views_handler_field_stockrel_by_type extends views_handler_field_prerender
       ),
       '#default_value' => array($this->options['stockrel_display_parts']['subject'], $this->options['stockrel_display_parts']['type'], $this->options['stockrel_display_parts']['object']),
     );
-    
+
     $form['stockrel_display_rels'] = array(
       '#type' => 'radios',
       '#title' => t('Display Relationships Where'),
@@ -62,7 +63,7 @@ class views_handler_field_stockrel_by_type extends views_handler_field_prerender
       ),
       '#default_value' => $this->options['stockrel_display_rels'],
     );
-    
+
     $options = tripal_cv_get_cvterm_options( variable_get('chado_stock_relationship_cv', 'null') );
     $form['stockrel_type_ids'] = array(
       '#type' => 'checkboxes',
@@ -83,14 +84,14 @@ class views_handler_field_stockrel_by_type extends views_handler_field_prerender
     $this->aliases['relationships'] = 'relationships';
     $this->aliases['stock_id'] = 'stock_id';
     $this->field_alias = $this->aliases['stock_id'];
-    
+
     //for each stock in this view page
     foreach ($values as $result) {
       if (!empty($result->{$this->aliases['relationships']})) {
-          
+
         // all relationships including the current stock
         $relationships = $result->{$this->aliases['relationships']};
-        foreach ($relationships as $relationship) {      
+        foreach ($relationships as $relationship) {
           // perform filtering------
           //type
           if (!empty($this->options['stockrel_type_ids'])) {
@@ -99,18 +100,19 @@ class views_handler_field_stockrel_by_type extends views_handler_field_prerender
               continue;
             }
           }
-          
+
           //"Display Relationships Where" criteria
           if (preg_match('/subject/', $this->options['stockrel_display_rels'])) {
             if ($relationship->stock_id != $relationship->subject_id) {
               continue;
-            }      
-          } elseif (preg_match('/object/', $this->options['stockrel_display_rels'])) {
+            }
+          }
+          elseif (preg_match('/object/', $this->options['stockrel_display_rels'])) {
             if ($relationship->stock_id != $relationship->object_id) {
               continue;
             }
           }
-          
+
           // Add relationship to the list of items to be rendered
           $this->items[$relationship->stock_id][$relationship->stock_relationship_id]['stock_id'] = $relationship->stock_id;
           $this->items[$relationship->stock_id][$relationship->stock_relationship_id]['stock_relationship_id'] = $relationship->stock_relationship_id;
@@ -127,7 +129,7 @@ class views_handler_field_stockrel_by_type extends views_handler_field_prerender
 
   function render_item($count, $item) {
     $text = array();
-    
+
     // Render Parts
     if ($this->options['stockrel_display_parts']['subject']) {
       $text[] = $item['subject_name'];
@@ -138,7 +140,7 @@ class views_handler_field_stockrel_by_type extends views_handler_field_prerender
     if ($this->options['stockrel_display_parts']['object']) {
       $text[] = $item['object_name'];
     }
-    
+
     return implode(' ', $text);
   }
 

+ 33 - 30
tripal_views/views/handlers/views_handler_filter_stock_dbxref_id.inc

@@ -1,6 +1,7 @@
 <?php
 
 /**
+ * @file
  * Allows stocks to be filtered by associated database reference accession
  *
  * @ingroup tripal_stock
@@ -12,7 +13,7 @@ class views_handler_filter_stock_dbxref_id extends views_handler_filter {
     parent::init($view, $options);
     $this->db = $this->options['db'];
   }
-  
+
   function options_form(&$form, &$form_state) {
     if ($this->can_expose()) {
       $this->show_expose_button($form, $form_state);
@@ -33,32 +34,34 @@ class views_handler_filter_stock_dbxref_id extends views_handler_filter {
 
   }
 
-	function query () {
-		$this-> db = array_filter($this->db);
-		
-		if (preg_match('/IS NOT NULL/', $this->options['operator'])) {
-			$new_where_sql = "stock.stock_id IN "
-			."(SELECT stock_dbxref.stock_id FROM stock_dbxref, dbxref WHERE stock_dbxref.dbxref_id=dbxref.dbxref_id AND dbxref.db_id IN (".implode(', ',$this->db)."))";
-			$this->query->add_where($this->options['group'], $new_where_sql);
-		} elseif (preg_match('/IS NULL/', $this->options['operator'])) {
-			$new_where_sql = "stock.stock_id NOT IN "
-			."(SELECT stock_dbxref.stock_id FROM stock_dbxref, dbxref WHERE stock_dbxref.dbxref_id=dbxref.dbxref_id AND dbxref.db_id IN (".implode(', ',$this->db)."))";
-			$this->query->add_where($this->options['group'], $new_where_sql);
-		} else {
-			if (!empty($this->value)) {
-				$new_where_sql = "stock.stock_id IN "
-					."(SELECT stock_dbxref.stock_id FROM stock_dbxref, dbxref WHERE stock_dbxref.dbxref_id=dbxref.dbxref_id "
-					."AND dbxref.db_id IN (".implode(', ',$this->db).") AND dbxref.accession".$this->operator."'".$this->value."')";
-				$this->query->add_where($this->options['group'], $new_where_sql);
-			}
-		}
-	}
-  
+  function query() {
+    $this-> db = array_filter($this->db);
+
+    if (preg_match('/IS NOT NULL/', $this->options['operator'])) {
+      $new_where_sql = "stock.stock_id IN "
+      ."(SELECT stock_dbxref.stock_id FROM stock_dbxref, dbxref WHERE stock_dbxref.dbxref_id=dbxref.dbxref_id AND dbxref.db_id IN (" . implode(', ', $this->db) . "))";
+      $this->query->add_where($this->options['group'], $new_where_sql);
+    }
+    elseif (preg_match('/IS NULL/', $this->options['operator'])) {
+      $new_where_sql = "stock.stock_id NOT IN "
+      ."(SELECT stock_dbxref.stock_id FROM stock_dbxref, dbxref WHERE stock_dbxref.dbxref_id=dbxref.dbxref_id AND dbxref.db_id IN (" . implode(', ', $this->db) . "))";
+      $this->query->add_where($this->options['group'], $new_where_sql);
+    }
+    else {
+      if (!empty($this->value)) {
+        $new_where_sql = "stock.stock_id IN "
+          ."(SELECT stock_dbxref.stock_id FROM stock_dbxref, dbxref WHERE stock_dbxref.dbxref_id=dbxref.dbxref_id "
+          ."AND dbxref.db_id IN (" . implode(', ', $this->db) . ") AND dbxref.accession" . $this->operator . "'" . $this->value . "')";
+        $this->query->add_where($this->options['group'], $new_where_sql);
+      }
+    }
+  }
+
   /////////// Form Parts/////////////////////////
   function types_form(&$form, &$form_state) {
-  
+
     $db_options = tripal_db_get_db_options();
-	  ksort($db_options);
+    ksort($db_options);
     $form['db'] = array(
       '#type' => 'checkboxes',
       '#title' => t('Databases'),
@@ -72,10 +75,10 @@ class views_handler_filter_stock_dbxref_id extends views_handler_filter {
 
   function value_form(&$form, &$form_state) {
     parent::value_form($form, $form_state);
-    
-		$form['value'] = array(
-  	  '#type' => 'textfield',
-    	'#title' => t('Accession'),
+
+    $form['value'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Accession'),
       '#default_value' => $this->value,
     );
   }
@@ -105,7 +108,7 @@ class views_handler_filter_stock_dbxref_id extends views_handler_filter {
         '#type' => 'select',
         '#title' => t('Database References'),
         '#options' => $this->type_options(),
-        '#default_value' => $this->type,  
+        '#default_value' => $this->type,
       );
 
       if (isset($form[$type]['#title'])) {
@@ -230,7 +233,7 @@ class views_handler_filter_stock_dbxref_id extends views_handler_filter {
         '#value' => '',
       );
     }
-    
+
     $form['expose']['optional'] = array(
       '#type' => 'checkbox',
       '#title' => t('Optional'),

+ 105 - 84
tripal_views/views/handlers/views_handler_filter_stock_relationship_id.inc

@@ -1,112 +1,125 @@
 <?php
 
+/**
+ * @file
+ * Filter stocks via stock_relationships
+ */
 class views_handler_filter_stock_relationship_id extends views_handler_filter {
 
-	function query () {
-	  if ($this->value) {
-	  
+  function query() {
+    if ($this->value) {
+
       // get variable position
       if ($this->options['fixed_position'] == 'subject_id') {
         $this->options['variable_position'] = 'object_id';
-      } else {
+      }
+      else {
         $this->options['variable_position'] = 'subject_id';
       }
-        
-	    // determine if just checking presence
-	    if (preg_match('/NULL/', $this->operator)) {
+
+      // determine if just checking presence
+      if (preg_match('/NULL/', $this->operator)) {
           $where = 'stock.stock_id IN ('
-            .'SELECT '.$this->options['variable_position'].' FROM stock_relationship '
-            .'WHERE '.$this->options['fixed_position'].' '.$this->operator.' AND type_id = '.$this->options['type']
+            .'SELECT ' . $this->options['variable_position'] . ' FROM stock_relationship '
+            .'WHERE ' . $this->options['fixed_position'] . ' ' . $this->operator . ' AND type_id = ' . $this->options['type']
           .')';
-          $this->query->add_where($this->options['group'], $where);	      
-	    } else {
-        
+          $this->query->add_where($this->options['group'], $where);
+      }
+      else {
+
         // determine whether regex was requested
         if ($this->operator == '~') {
-          $search_options = array('regex_columns' => array('name','uniquename'));
+          $search_options = array('regex_columns' => array('name', 'uniquename'));
           $this->operator = '=';
-        } elseif ($this->operator == '!~') {
-          $search_options = array('regex_columns' => array('name','uniquename'));
+        }
+        elseif ($this->operator == '!~') {
+          $search_options = array('regex_columns' => array('name', 'uniquename'));
           $this->operator = '!=';
-        } else {
+        }
+        else {
           $search_options = array();
         }
-        
+
         // get fixed stock id(s)
-        $fixed_stock = tripal_core_chado_select('stock',array('stock_id'),array('uniquename' => $this->value), $search_options);
+        $fixed_stock = tripal_core_chado_select('stock', array('stock_id'), array('uniquename' => $this->value), $search_options);
         $fixed_stock_ids = array();
         if ($fixed_stock[0]->stock_id) {
           $fixed_stock_ids[] = $fixed_stock[0]->stock_id;
-        } else {
-          $fixed_stock = tripal_core_chado_select('stock',array('stock_id'),array('name' => $this->value), $search_options);
+        }
+        else {
+          $fixed_stock = tripal_core_chado_select('stock', array('stock_id'), array('name' => $this->value), $search_options);
           if (sizeof($fixed_stock) > 1) {
             foreach ($fixed_stock as $s) {
               $fixed_stock_ids[] = $s->stock_id;
             }
-          } elseif (sizeof($fixed_stock) == 1) {
+          }
+          elseif (sizeof($fixed_stock) == 1) {
             $fixed_stock_ids[] = $fixed_stock[0]->stock_id;
           }
         }
-        
+
         // determine operator
         if ($this->operator == '=' && sizeof($fixed_stock_ids) > 1) {
           $this->operator = 'IN';
-        } elseif ($this->operator == '!=' && sizeof($fixed_stock_ids) > 1) {
+        }
+        elseif ($this->operator == '!=' && sizeof($fixed_stock_ids) > 1) {
           $this->operator = 'NOT IN';
         }
-        
+
         //generate where
         if (sizeof($fixed_stock_ids) == 1) {
           $where = 'stock.stock_id IN ('
-            .'SELECT '.$this->options['variable_position'].' FROM stock_relationship '
-            .'WHERE '.$this->options['fixed_position'].' '.$this->operator.' '.$fixed_stock_ids[0].' AND type_id = '.$this->options['type']
+            .'SELECT ' . $this->options['variable_position'] . ' FROM stock_relationship '
+            .'WHERE ' . $this->options['fixed_position'] . ' ' . $this->operator . ' ' . $fixed_stock_ids[0] . ' AND type_id = ' . $this->options['type']
           .')';
           $this->query->add_where($this->options['group'], $where);
-        } elseif (sizeof($fixed_stock_ids) > 1) {
+        }
+        elseif (sizeof($fixed_stock_ids) > 1) {
           $where = 'stock.stock_id IN ('
-            .'SELECT '.$this->options['variable_position'].' FROM stock_relationship '
-            .'WHERE '.$this->options['fixed_position'].' '.$this->operator.' ('.implode(', ',$fixed_stock_ids).') AND type_id = '.$this->options['type']
+            .'SELECT ' . $this->options['variable_position'] . ' FROM stock_relationship '
+            .'WHERE ' . $this->options['fixed_position'] . ' ' . $this->operator . ' (' . implode(', ', $fixed_stock_ids) . ') AND type_id = ' . $this->options['type']
           .')';
           $this->query->add_where($this->options['group'], $where);
-        } else {
-          drupal_set_message('No stock with the name or uniquename '.$this->value.' was found -No filtering done.','error');
+        }
+        else {
+          drupal_set_message(t('No stock with the name or uniquename %value was found -No filtering done.', array('%value' => $this->value)), 'error');
         }
       } //end of not just checking presence
     }
-	}
-	
+  }
+
   function options_form(&$form, &$form_state) {
-  	
+
     if ($this->can_expose()) {
       $this->show_expose_button($form, $form_state);
     }
 
-  	$instructions = 'This filter allows you to enter a stock, the position of that stock in the '
-  		.'relationship and relationship type and only stocks with a relationship of the type described '
-  		.'will be shown. For example, if you want all stocks where Fred is_paternal_parent_of, then '
-  		.'you would enter Fred as the value, select is_paternal_parent_of as the Relationship Type '
-  		.'and subject as the Fixed Position.';
-  	$form['instructions'] = array(
-  		'#type' => 'item',
-  		'#value' => t($instructions)
-  	);
-  	
+    $instructions = 'This filter allows you to enter a stock, the position of that stock in the '
+      .'relationship and relationship type and only stocks with a relationship of the type described '
+      .'will be shown. For example, if you want all stocks where Fred is_paternal_parent_of, then '
+      .'you would enter Fred as the value, select is_paternal_parent_of as the Relationship Type '
+      .'and subject as the Fixed Position.';
+    $form['instructions'] = array(
+      '#type' => 'item',
+      '#value' => t($instructions)
+    );
+
     $form['op_val_start'] = array('#value' => '<div class="clear-block">');
 
     // left side
-    
+
     $this->types_form($form, $form_state);
-		$form['type']['#prefix'] = '<div class="views-left-50">';
-		$form['type']['#suffix'] = '</div>';
+    $form['type']['#prefix'] = '<div class="views-left-50">';
+    $form['type']['#suffix'] = '</div>';
 
     $this->show_operator_form($form, $form_state);
     $form['operator']['#prefix'] = '<div class="views-right-50">';
-		$form['operator']['#suffix'] = '</div>';
-		
-		$this->show_value_form($form, $form_state);
-		$form['value']['#prefix'] = '<div class="views-right-50">';
-		$form['value']['#suffix'] = '</div>';
-		
+    $form['operator']['#suffix'] = '</div>';
+
+    $this->show_value_form($form, $form_state);
+    $form['value']['#prefix'] = '<div class="views-right-50">';
+    $form['value']['#suffix'] = '</div>';
+
     // right side
 
 
@@ -114,11 +127,11 @@ class views_handler_filter_stock_relationship_id extends views_handler_filter {
     $form['fixed_position']['#prefix'] = '<div class="views-right-50">';
     $form['fixed_position']['#suffix'] = '</div>';
 
-		
+
     if ($this->can_expose()) {
       $this->show_expose_form($form, $form_state);
     }
-    
+
     $form['op_val_start'] = array('#value' => '</div>');
 
   }
@@ -126,29 +139,37 @@ class views_handler_filter_stock_relationship_id extends views_handler_filter {
   function value_form(&$form, &$form_state) {
     parent::value_form($form, $form_state);
 
-		$form['value'] = array(
-			'#type' => 'textfield',
-			'#title' => ($this->options['label']) ? $this->options['label'] : t('Stock Name'),
-			'#default_value' => $this->value,
-			'#size' => 40,
-		);
-    	
+    if (!$this->options['label']) {
+      $label = 'Stock Name';
+    }
+    else {
+      $label = $this->options['label'];
+    }
+    $form['value'] = array(
+      '#type' => 'textfield',
+      '#title' => t('%label', array('%label' => $label)),
+      '#default_value' => $this->value,
+      '#size' => 40,
+    );
+
   }
 
-  function type_options () {
+  function type_options() {
 
     $previous_db = tripal_db_set_active('chado');
     $result = db_query("SELECT cvt.cvterm_id as type_id, cvt.name FROM cvterm cvt WHERE cvt.cvterm_id IN (SELECT type_id FROM stock_relationship)");
     tripal_db_set_active($previous_db);
 
     $types = array();
-    while ($r = db_fetch_object($result)) { $types[$r->type_id] = $r->name; }
-    
+    while ($r = db_fetch_object($result)) {
+      $types[$r->type_id] = $r->name;
+    }
+
     return $types;
   }
-  
+
   function types_form(&$form, &$form_state) {
-  	
+
     $form['type'] = array(
       '#type' => count($options) < 10 ? 'radios' : 'select',
       '#title' => t('Relationship Types'),
@@ -157,21 +178,21 @@ class views_handler_filter_stock_relationship_id extends views_handler_filter {
     );
 
   }
-  
-  function fixed_position_form (&$form, &$form_state) {
-  
-  	$form['fixed_position'] = array(
-  		'#type' => 'radios',
-  		'#title' => 'Position of Stock to Filter on',
-  		'#description' => t('Where a relationship consists of a subject type object, this field indicates '
-  			.'what position in the relationship remains fixed (is the stock entered as the value).'),
-  		'#options' => array(
-  			'subject_id' => 'Subject',
-  			'object_id' => 'Object'
-  		),
-  		'#default_value' => ($this->options['fixed_position']) ? $this->options['fixed_position'] : 'subject_id',
-  	);
-  	
+
+  function fixed_position_form(&$form, &$form_state) {
+
+    $form['fixed_position'] = array(
+      '#type' => 'radios',
+      '#title' => 'Position of Stock to Filter on',
+      '#description' => t('Where a relationship consists of a subject type object, this field indicates '
+        .'what position in the relationship remains fixed (is the stock entered as the value).'),
+      '#options' => array(
+        'subject_id' => 'Subject',
+        'object_id' => 'Object'
+      ),
+      '#default_value' => ($this->options['fixed_position']) ? $this->options['fixed_position'] : 'subject_id',
+    );
+
   }
 
   function operator_options() {
@@ -247,7 +268,7 @@ class views_handler_filter_stock_relationship_id extends views_handler_filter {
       '#size' => 40,
       '#description' => t('This will appear in the URL after the ? to identify this filter. Cannot be blank.'),
     );
-    
+
   }
 
   function expose_form_right(&$form, &$form_state) {
@@ -285,7 +306,7 @@ class views_handler_filter_stock_relationship_id extends views_handler_filter {
         '#value' => '',
       );
     }
-    
+
     $form['expose']['optional'] = array(
       '#type' => 'checkbox',
       '#title' => t('Optional'),

+ 59 - 52
tripal_views/views/handlers/views_handler_filter_stockprop_id.inc

@@ -1,6 +1,7 @@
 <?php
 
 /**
+ * @file
  * Allows stocks to be filtered by proeprty values
  *
  * @ingroup tripal_stock
@@ -36,46 +37,51 @@ class views_handler_filter_stockprop_id extends views_handler_filter {
   function options_validate(&$form, &$form_state) {
     parent::options_validate($form, $form_state);
 
-    if (preg_match('/NULL/',$form_state['values']['options']['operator'])) {
+    if (preg_match('/NULL/', $form_state['values']['options']['operator'])) {
       $value = $form_state['values']['options']['value'];
       if (!empty($value)) {
-        drupal_set_message('The Value ('.$value.') will be IGNORED when the Operator is set to "Is Present" or Is Absent".', 'warning');
+        drupal_set_message(t('The Value (%value) will be IGNORED when the Operator is set to "Is Present" or Is Absent".', array('%value' => $value)), 'warning');
       }
-    } else {
+    }
+    else {
       $value = $form_state['values']['options']['value'];
       if (empty($value)) {
         form_error($form['value'], t('Value required. The value will be used in conjunction with the operator. For example, if the '
-				   .'operator="Is equal to" and the value="2010" then only properties with a value of 2010 and the type specified will be displayed.'));
+           .'operator="Is equal to" and the value="2010" then only properties with a value of 2010 and the type specified will be displayed.'));
       }
     }
 
     if (empty($form_state['values']['options']['type'])) {
-      drupal_set_message('No Property Type was choosen. As such, any property type whose value '
-      			     .$form_state['values']['options']['operator'].' '.$form_state['values']['options']['value'].' will be displayed', 'warning');
+      drupal_set_message(t('No Property Type was choosen. As such, any property type whose value %op %value will be displayed.',
+        array('%op' => $form_state['values']['options']['operator'], '%value' => $form_state['values']['options']['value'])), 'warning');
     }
   }
 
-	function query () {
-		if (preg_match('/IS NOT NULL/', $this->options['operator'])) {
-			$new_where_sql = "stock.stock_id IN (SELECT stockprop.stock_id FROM stockprop WHERE stockprop.type_id=".$this->type.")";
-			$this->query->add_where($this->options['group'], $new_where_sql);
-		} elseif (preg_match('/IS NULL/', $this->options['operator'])) {
-			$new_where_sql = "stock.stock_id NOT IN (SELECT stockprop.stock_id FROM stockprop WHERE stockprop.type_id=".$this->type.")";
-			$this->query->add_where($this->options['group'], $new_where_sql);
-		} elseif ($this->value) {
-			$new_where_sql = "stock.stock_id IN (SELECT stockprop.stock_id FROM stockprop WHERE stockprop.type_id=".$this->type." AND stockprop.value".$this->operator."'".$this->value."')";
-			$this->query->add_where($this->options['group'], $new_where_sql);
-		}
-		
-	}
-	
+  function query() {
+    if (preg_match('/IS NOT NULL/', $this->options['operator'])) {
+      $new_where_sql = "stock.stock_id IN (SELECT stockprop.stock_id FROM stockprop WHERE stockprop.type_id=" . $this->type . ")";
+      $this->query->add_where($this->options['group'], $new_where_sql);
+    }
+    elseif (preg_match('/IS NULL/', $this->options['operator'])) {
+      $new_where_sql = "stock.stock_id NOT IN (SELECT stockprop.stock_id FROM stockprop WHERE stockprop.type_id=" . $this->type . ")";
+      $this->query->add_where($this->options['group'], $new_where_sql);
+    }
+    elseif ($this->value) {
+      $new_where_sql = "stock.stock_id IN (SELECT stockprop.stock_id FROM stockprop WHERE stockprop.type_id=" . $this->type . " AND stockprop.value" . $this->operator . "'" . $this->value . "')";
+      $this->query->add_where($this->options['group'], $new_where_sql);
+    }
+
+  }
+
   function types_form(&$form, &$form_state) {
     $previous_db = tripal_db_set_active('chado');
     $result = db_query("SELECT cvt.cvterm_id as type_id, cvt.name FROM cvterm cvt WHERE cvt.cvterm_id IN (SELECT type_id FROM stockprop)");
     tripal_db_set_active($previous_db);
 
     $types = array();
-    while ($r = db_fetch_object($result)) { $types[$r->type_id] = $r->name; }
+    while ($r = db_fetch_object($result)) {
+      $types[$r->type_id] = $r->name;
+    }
 
     $form['type'] = array(
       '#type' => count($options) < 10 ? 'radios' : 'select',
@@ -90,28 +96,29 @@ class views_handler_filter_stockprop_id extends views_handler_filter {
 
   function value_form(&$form, &$form_state) {
     parent::value_form($form, $form_state);
-	
-		if ($this->options['expose']['display_type'] == 'select') {
-		
-			// Get options
-			$previous_db = tripal_db_set_active('chado');
-			$resource = db_query("SELECT value FROM stockprop WHERE type_id=".$this->type." ORDER BY value");
-		 tripal_db_set_active($previous_db);
-			while ($r = db_fetch_object($resource)) {
-				$options[$r->value] = $r->value;
-			}
-			$form['value'] = array(
+
+    if ($this->options['expose']['display_type'] == 'select') {
+
+      // Get options
+      $previous_db = tripal_db_set_active('chado');
+      $resource = db_query("SELECT value FROM stockprop WHERE type_id=" . $this->type . " ORDER BY value");
+      tripal_db_set_active($previous_db);
+      while ($r = db_fetch_object($resource)) {
+        $options[$r->value] = $r->value;
+      }
+      $form['value'] = array(
         '#type' => 'select',
-        '#title' => $this->options['label'],
+        '#title' => t('%label', array('%label' => $this->options['label'])),
         '#options' => $options,
         '#default_value' => $this->value,
       );
-		} else {
-			$form['value'] = array(
-  	    '#type' => 'textfield',
-    	  '#title' => t('Value'),
-      	'#default_value' => $this->value,
-    	);
+    }
+    else {
+      $form['value'] = array(
+        '#type' => 'textfield',
+        '#title' => t('Value'),
+        '#default_value' => $this->value,
+      );
     }
   }
 
@@ -140,7 +147,7 @@ class views_handler_filter_stockprop_id extends views_handler_filter {
         '#type' => 'select',
         '#title' => t('Property Types'),
         '#options' => $this->type_options(),
-        '#default_value' => $this->type,  
+        '#default_value' => $this->type,
       );
 
       if (isset($form[$type]['#title'])) {
@@ -202,16 +209,16 @@ class views_handler_filter_stockprop_id extends views_handler_filter {
       '#size' => 40,
       '#description' => t('This will appear in the URL after the ? to identify this filter. Cannot be blank.'),
     );
-    
+
     $form['expose']['display_type'] = array(
-    	'#type' => 'radios',
-    	'#default_value' => $this->options['expose']['display_type'],
-    	'#title' => t('Display Type'),
-    	'#description' => t('This will change the form item type of the exposed value form. ie: it can be used to let the user select the property value from a select box rather than a textfield.'),
-			'#options' => array(
-				'textfield' => 'Text Field',
-				'select' => 'Drop Down',
-			),
+      '#type' => 'radios',
+      '#default_value' => $this->options['expose']['display_type'],
+      '#title' => t('Display Type'),
+      '#description' => t('This will change the form item type of the exposed value form. ie: it can be used to let the user select the property value from a select box rather than a textfield.'),
+      '#options' => array(
+        'textfield' => 'Text Field',
+        'select' => 'Drop Down',
+      ),
     );
   }
 
@@ -275,7 +282,7 @@ class views_handler_filter_stockprop_id extends views_handler_filter {
         '#value' => '',
       );
     }
-    
+
     $form['expose']['optional'] = array(
       '#type' => 'checkbox',
       '#title' => t('Optional'),
@@ -283,6 +290,6 @@ class views_handler_filter_stockprop_id extends views_handler_filter {
       '#default_value' => $this->options['expose']['optional'],
     );
   }
-  
-  
+
+
 }

+ 79 - 69
tripal_views/views/handlers/views_handler_join_chado_aggregator.inc

@@ -42,79 +42,84 @@ class views_handler_join_chado_aggregator extends views_join {
    */
   function join($table, &$query) {
     $output = array();
-    
+
     // Create the table SQL (used in join) -------
     // query creating one-to-one table using array_agg
-    
+
     // Only aggregate each field if it the join table hadn't been pre-aggregated
     // Example where it might be pre-aggregated: Materialized view
     if (!$this->definition['pre-aggregated']) {
       // Determine Order BY's for aggregates
       $order_by = array();
-      if (!is_array($this->sort)) { $this->sort = array(); }
+      if (!is_array($this->sort)) {
+        $this->sort = array();
+      }
       foreach ($this->sort as $s) {
-        $order_by[] = $s['table'].'.'.$s['field'].' '.$s['order'];
+        $order_by[] = $s['table'] . '.' . $s['field'] . ' ' . $s['order'];
       }
-        
+
       // get table description (if defined via schema api)
-      $table_desc = module_invoke_all('chado_'.$this->definition['table'].'_schema');
+      $table_desc = module_invoke_all('chado_' . $this->definition['table'] . '_schema');
       $select_fields[ $this->definition['table'] ] = $table_desc['fields'];
-      
+
       if (!empty($table_desc)) {
         // Add joins to tables with a foreign key in this table
         // (ie: add join to cvterm if this table has a type_id
         $joins = array();
-        foreach($table_desc['foreign keys'] as $defn) {
+        foreach ($table_desc['foreign keys'] as $defn) {
           if ($defn['table'] != $this->left_table) {
-            foreach( $defn['columns'] as $left => $right) {
-              $left = $this->definition['table'] .'.'. $left;
-              $right = $defn[table] .'.'. $right;
+            foreach ( $defn['columns'] as $left => $right) {
+              $left = $this->definition['table'] . '.' . $left;
+              $right = $defn['table'] . '.' . $right;
               $joins[] = "LEFT JOIN $defn[table] $defn[table] ON $left=$right";
             }
-            
+
             // Fields to be selected from joined table
-            $join_table = module_invoke_all('chado_'.$defn['table'].'_schema');
+            $join_table = module_invoke_all('chado_' . $defn['table'] . '_schema');
             $select_fields[ $defn['table'] ] = $join_table['fields'];
-          } 
+          }
         }
-        
+
         // Fields to be selected
         foreach ($select_fields as $table => $table_fields) {
           foreach ($table_fields as $fname => $f) {
             $alias = '';
             if ($table != $this->definition['table']) {
-              $alias = $table .'_';
+              $alias = $table . '_';
             }
-            
+
             if ($fname != $this->definition['field']) {
               // Add sort to aggregate field if postgreSQL 9.0+
               if ($this->postgresql_9up && !empty($order_by)) {
-                $fields[] = 'array_agg('.$table.'.'.$fname.' ORDER BY '.implode(',',$order_by).') as '.$alias.$fname;
-              } else {
-                $fields[] = 'array_agg('.$table.'.'.$fname.') as '.$alias.$fname;
+                $fields[] = 'array_agg(' . $table . '.' . $fname . ' ORDER BY ' . implode(',', $order_by) . ') as ' . $alias . $fname;
+              }
+              else {
+                $fields[] = 'array_agg(' . $table . '.' . $fname . ') as '. $alias . $fname;
               }
-              $composite_field_parts[] = "'".$alias.$fname."::' ||".$table.'.'.$fname;
-            } else {
+              $composite_field_parts[] = "'" . $alias . $fname . "::' ||" . $table . '.' . $fname;
+            }
+            else {
               $fields[] = $fname;
-              $composite_field_parts[] = "'".$alias.$fname."::' ||".$table.'.'.$fname;
+              $composite_field_parts[] = "'" . $alias . $fname . "::' ||" . $table . '.' . $fname;
             }
           }
         }
-      
+
       // There is no definition in schema api
       // then use postgresql select
-      } else {
-        
+      }
+      else {
+
         // No known foreign key reelationships
         $joins = array();
-        
+
         // Fields to be selected
-        $sql = "SELECT 
-                  attname as column, 
-                  format_type(atttypid, atttypmod) as datatype 
-                FROM pg_attribute, pg_type 
-                WHERE typname='nd_genotype_experiment' 
-                  AND attrelid=typrelid 
+        $sql = "SELECT
+                  attname as column,
+                  format_type(atttypid, atttypmod) as datatype
+                FROM pg_attribute, pg_type
+                WHERE typname='nd_genotype_experiment'
+                  AND attrelid=typrelid
                   AND attname NOT IN ('cmin','cmax','ctid','oid','tableoid','xmin','xmax')";
         $previous_db = tripal_db_set_active('chado');
         $resource = db_query($sql);
@@ -123,44 +128,47 @@ class views_handler_join_chado_aggregator extends views_join {
           $table = $this->definition['table'];
           $alias = ''; //no alias needed if table is current table (only option if no schema api definition)
           $fname = $r->column;
-          
+
           if ($fname != $this->definition['field']) {
             // Add sort to aggregate field if postgreSQL 9.0+
             if ($this->postgresql_9up && !empty($order_by)) {
-              $fields[] = 'array_agg('.$table.'.'.$fname.' ORDER BY '.implode(',',$order_by).') as '.$alias.$fname;
-            } else {
-              $fields[] = 'array_agg('.$table.'.'.$fname.') as '.$alias.$fname;
+              $fields[] = 'array_agg(' . $table . '.' . $fname . ' ORDER BY ' . implode(',', $order_by) . ') as ' . $alias . $fname;
             }
-            $composite_field_parts[] = "'".$alias.$fname."::' ||".$table.'.'.$fname;
-          } else {
+            else {
+              $fields[] = 'array_agg(' . $table . '.' . $fname . ') as ' . $alias . $fname;
+            }
+            $composite_field_parts[] = "'" . $alias . $fname . "::' ||" . $table . '.' . $fname;
+          }
+          else {
             $fields[] = $fname;
-            $composite_field_parts[] = "'".$alias.$fname."::' ||".$table.'.'.$fname;
+            $composite_field_parts[] = "'" . $alias . $fname . "::' ||" . $table . '.' . $fname;
           }
         }
-        
+
       }
-      
-      // composite field 
+
+      // composite field
       // (combines all other fields before aggregating)
       // Add sort to aggregate field if postgreSQL 9.0+
       if ($this->postgresql_9up && !empty($order_by)) {
-        $composite_field = "array_agg('{'||".implode(" || ',' || ",$composite_field_parts)."||'}' ORDER BY ".implode(',',$order_by).") as all";
-      } else {
-        $composite_field = "array_agg('{'||".implode(" || ',' || ",$composite_field_parts)."||'}') as all";
+        $composite_field = "array_agg('{'||" . implode(" || ',' || ", $composite_field_parts) . "||'}' ORDER BY " . implode(',', $order_by) . ") as all";
+      }
+      else {
+        $composite_field = "array_agg('{'||" . implode(" || ',' || ", $composite_field_parts) . "||'}') as all";
       }
       $fields[] = $composite_field;
-        
+
       // SQL to use in the join
-      $sql = 'SELECT '.implode(', ',$fields)
-        .' FROM '.$this->definition['table']
-        .' '.implode(' ',$joins);
-   
+      $sql = 'SELECT ' . implode(', ', $fields)
+        .' FROM ' . $this->definition['table']
+        .' ' . implode(' ', $joins);
+
       if (!empty($this->filter)) {
-        $sql .= ' WHERE '.implode(', ', $this->filter);
+        $sql .= ' WHERE ' . implode(', ', $this->filter);
       }
-      
-      $sql .= ' GROUP BY '.$this->definition['field'];
-      
+
+      $sql .= ' GROUP BY ' . $this->definition['field'];
+
       // Create the join (full SQL) ----------------
       $output[] = $this->create_single_join(
         $query,
@@ -176,10 +184,11 @@ class views_handler_join_chado_aggregator extends views_join {
         ),
         'LEFT'
       );
-    
+
     // Otherwise the table has been pre-aggregated
     // Then only need to do a regular join with any in where
-    } else {
+    }
+    else {
 
       // Create the join
 
@@ -192,7 +201,7 @@ class views_handler_join_chado_aggregator extends views_join {
         'table' => $this->definition['left_table'],
         'field' => $this->definition['left_field'],
       );
-      
+
       switch ($this->definition['table_aggregated']) {
         default:
         case 'CURRENT':
@@ -202,7 +211,7 @@ class views_handler_join_chado_aggregator extends views_join {
           $left_table_spec['pre-aggregated'] = TRUE;
         break;
       }
-      
+
       $output[] = $this->create_single_join(
         $query,
         $current_table_spec,
@@ -210,8 +219,8 @@ class views_handler_join_chado_aggregator extends views_join {
         'LEFT'
       );
     }
-    
-    return implode("\n",$output);
+
+    return implode("\n", $output);
   }
 
   /**
@@ -230,10 +239,10 @@ class views_handler_join_chado_aggregator extends views_join {
 
       // Add any() around field if already aggregated
       if ($right_spec['pre-aggregated']) {
-        $right_field = "any(".$right_field.")";
+        $right_field = "any(" . $right_field . ")";
       }
-      
-      // Add drupal { } around table 
+
+      // Add drupal { } around table
       if ($right_spec['is_drupal']) {
         $right_table = '{' . $right_spec['table'] . '}';
       }
@@ -256,16 +265,17 @@ class views_handler_join_chado_aggregator extends views_join {
 
     // Add any() around field if already aggregated
     if ($left_spec['pre-aggregated']) {
-      $left_field = "any(".$left_field.")";
+      $left_field = "any(" . $left_field . ")";
     }
-    
+
     // Concatenate parts together to form join sql
-    if (!empty($right_spec[table_sql])) {
+    if (!empty($right_spec['table_sql'])) {
       $output = " $join_type JOIN ($right_spec[table_sql]) $right[alias] ON $left_field = $right_field";
-    } else {
+    }
+    else {
       $output = " $join_type JOIN $right_spec[table] $right[alias] ON $left_field = $right_field";
     }
-    
+
     return $output;
   }