浏览代码

Merge branch '7.x-2.x' of git.drupal.org:project/tripal into 7.x-2.x

Stephen Ficklin 9 年之前
父节点
当前提交
072e1f27ed

+ 5 - 0
tripal_analysis/tripal_analysis.views_default.inc

@@ -217,6 +217,11 @@ function tripal_analysis_defaultvalue_admin_analysis() {
   $handler->display->display_options['fields']['nothing']['label'] = '';
   $handler->display->display_options['fields']['nothing']['alter']['text'] = '[edit_node]   [delete_node]';
   $handler->display->display_options['fields']['nothing']['element_label_colon'] = FALSE;
+  /* Sort criterion: Chado Analysis: Analysis Id */
+  $handler->display->display_options['sorts']['analysis_id']['id'] = 'analysis_id';
+  $handler->display->display_options['sorts']['analysis_id']['table'] = 'analysis';
+  $handler->display->display_options['sorts']['analysis_id']['field'] = 'analysis_id';
+  $handler->display->display_options['sorts']['analysis_id']['order'] = 'DESC';
   /* Filter criterion: Chado Analysis: Name */
   $handler->display->display_options['filters']['name']['id'] = 'name';
   $handler->display->display_options['filters']['name']['table'] = 'analysis';

+ 5 - 0
tripal_contact/tripal_contact.views_default.inc

@@ -208,6 +208,11 @@ function tripal_contact_defaultview_admin_contacts() {
   $handler->display->display_options['fields']['nothing']['label'] = '';
   $handler->display->display_options['fields']['nothing']['alter']['text'] = '[edit_node]  [delete_node]';
   $handler->display->display_options['fields']['nothing']['element_label_colon'] = FALSE;
+  /* Sort criterion: Chado Analysis: Contact Id */
+  $handler->display->display_options['sorts']['contact_id']['id'] = 'contact_id';
+  $handler->display->display_options['sorts']['contact_id']['table'] = 'contact';
+  $handler->display->display_options['sorts']['contact_id']['field'] = 'contact_id';
+  $handler->display->display_options['sorts']['contact_id']['order'] = 'DESC';
   /* Filter criterion: Chado Contact: Type Id */
   $handler->display->display_options['filters']['type_id']['id'] = 'type_id';
   $handler->display->display_options['filters']['type_id']['table'] = 'contact';

+ 53 - 0
tripal_core/api/tripal_core.d3js.api.inc

@@ -0,0 +1,53 @@
+<?php
+/**
+ *
+ */
+
+/**
+ * Implements hook_libraries_info().
+ */
+function tripal_core_libraries_info() {
+  $libraries = array();
+  $libraries['d3'] = array(
+    'name' => 'D3.js',
+    'vendor url' => 'http://d3js.org/',
+    'download url' => 'https://github.com/mbostock/d3',
+    'version arguments' => array(
+      'file' => 'd3.js',
+      'pattern' => '/\s*version: "(\d+\.\d+\.\d+)"/',
+    ),
+    'files' => array(
+      'js' => array(
+        'd3.min.js',
+      ),
+    ),
+  );
+
+  return $libraries;
+}
+
+/**
+ * Load D3.js releated javascripts for the current page.
+ */
+function tripal_add_d3js() {
+  $library = array('loaded' => FALSE);
+
+  // First try to load d3.js using the libraries API.
+  // This will work if the site admin has saved d3.js in their libraries folder.
+  if (module_exists('libraries_api')) {
+    $library = libraries_load('d3');
+  }
+
+  // If we were not able to load d3.js using the libraries API
+  // then revert to loading the remote files manually.
+  if (!isset($library['loaded']) OR !$library['loaded']) {
+
+    // If SSL is being used then use a secure CDN for d3.js
+    if (isset($_SERVER['HTTPS'])) {
+      drupal_add_js('https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js');
+    }
+    else {
+      drupal_add_js('http://d3js.org/d3.v3.min.js');
+    }
+  }
+}

+ 1 - 1
tripal_core/tripal_core.module

@@ -34,7 +34,7 @@ require_once 'api/tripal_core.files.api.inc';
 require_once 'api/tripal_core.jobs.api.inc';
 require_once 'api/tripal_core.tripal.api.inc';
 require_once 'api/tripal_core.tripal_variables.api.inc';
-
+require_once 'api/tripal_core.d3js.api.inc';
 require_once 'api/tripal_core.DEPRECATED.inc';
 
 // INCLUDES

+ 106 - 0
tripal_feature/includes/tripal_feature.admin.inc

@@ -36,6 +36,103 @@ function tripal_feature_admin_feature_view() {
     $output .= '</ul>';
   }
 
+  // Add a summary chart.
+  //-----------------------------------
+  // We are using the organism_feature_count materialized view as the source for our data.
+  // Thus grab all the records from this materialized view.
+  $organism_feature_count = chado_select_record(
+    'organism_feature_count',
+    array('*'),
+    array(),
+    array('order_by' => array('genus' => 'ASC', 'species' => 'ASC', 'feature_type' => 'ASC', 'num_features' => 'DESC'))
+  );
+
+  // Initialize variables.
+  $chart = array();
+  $type_names = array();
+  $organism_names = array();
+
+  // Process each row of the materialzied view into the chart array.
+  // Note: it's first keyed by type since each type will be a bar. Each type will have
+  // a "bars" array with the start (y0) and end (y1) height on the bar for a given
+  // organism. Finally we keep a record of the names of the types & organisms
+  // for axis' and legend generation respectively.
+  foreach ($organism_feature_count as $row) {
+
+    // Build up the easy details for the current row's type. These will be overridden
+    // multiple times but that's more efficient than checking each time.
+    $chart[$row->cvterm_id]['cvterm_id'] = $row->cvterm_id;
+    $chart[$row->cvterm_id]['name'] = $row->feature_type;
+
+    // Save the name of the type and organism into their respective arrays
+    // for generation of axis' and legends for the chart.
+    $type_names[$row->cvterm_id] = $row->feature_type;
+    $organism_names[$row->organism_id] = $row->genus . ' ' . $row->species;
+
+    // Save information about the current organism. This isn't actually used by the
+    // chart but can be used to debug the bar generation to follow.
+    $chart[$row->cvterm_id]['organisms'][] = array(
+      'name' => $row->genus . ' ' . $row->species,
+      'value' => (int) $row->num_features
+    );
+
+    // Now to build the bar array with the start (y0) and end (y1) height on the
+    // bar for a given organism.
+    // NOTE: we cannot assume the types are all in order so store y0 & y1 in the
+    // $chart[type] array.
+    // If y0 has not yet been set for this type then we're starting with the first
+    // chunk (organism) on the bar.
+    if (!isset($chart[$row->cvterm_id]['y0'])) {
+      $chart[$row->cvterm_id]['y0'] = 0;
+      $chart[$row->cvterm_id]['y1'] = $row->num_features;
+    }
+    // Otherwise, add the next chunk (organism) on top of the pre-existing bar.
+    else {
+      $chart[$row->cvterm_id]['y0'] = $chart[$row->cvterm_id]['y1'];
+      $chart[$row->cvterm_id]['y1'] = $chart[$row->cvterm_id]['y0'] + $row->num_features;
+    }
+    // Now save the bar chunk we just determined.
+    $chart[$row->cvterm_id]['bars'][] = array(
+      'name' => $row->genus . ' ' . $row->species,
+      'y0' => $chart[$row->cvterm_id]['y0'],
+      'y1' => $chart[$row->cvterm_id]['y1'],
+    );
+
+    // We also need to keep track of the total number of features for a single bar (Type).
+    $chart[$row->cvterm_id]['total_features'] = $chart[$row->cvterm_id]['y1'];
+  }
+
+  // Sort based on the total number of features.
+  // NOTE: This changes the keys so it's no longer the organism/type_id.
+  usort($chart, 'tripal_feature_admin_summary_sort');
+  sort($type_names);
+  sort($organism_names);
+
+  // We also need to add information about the materialized views
+  // so that admin can update it and know how recent the data is.
+  $mview = db_query('
+    SELECT mview_id, name, last_update
+    FROM tripal_mviews
+    WHERE mv_table=:mv_table',
+    array(':mv_table' => 'organism_feature_count')
+  )->fetchObject();
+
+  // Save everything we just determined as a Drupal JS settings so that we have access to
+  // it in our js script.
+  drupal_add_js(array('tripalFeature' => array('admin' => array(
+    'summary' => $chart,
+    'types' => $type_names,
+    'organisms' => $organism_names,
+    'mviewUrl' => url('admin/tripal/schema/mviews/update/' . $mview->mview_id),
+    'mviewUable' => $mview->name,
+    'mviewLastUpdate' => format_date($mview->last_update),
+  ))), 'setting');
+
+  // Finally add all the javascript and css needed to render the chart.
+  tripal_add_d3js();
+  drupal_add_css(drupal_get_path('module','tripal_feature') . '/theme/css/tripal_feature.css');
+  drupal_add_js(drupal_get_path('module','tripal_feature') . '/theme/js/tripalFeature.adminChart.js');
+
   return $output;
 }
 
@@ -159,3 +256,12 @@ function tripal_feature_admin_validate($form, &$form_state) {
   }
 
 }
+
+/**
+ * USort function for the admin summary chart.
+ * Not meant to be called directly.
+ */
+function tripal_feature_admin_summary_sort($a, $b) {
+  if ($a['total_features'] == $b['total_features']) return 0;
+  return $b['total_features'] - $a['total_features'];
+}

+ 23 - 5
tripal_feature/theme/css/tripal_feature.css

@@ -11,7 +11,7 @@
 pre.tripal_feature-sequence {
   color: #000000;
   height: 300px;
-  overflow: scroll; 
+  overflow: scroll;
   border: 1px solid #DDDDDD;
   max-width: 500px;
   white-space: normal;
@@ -52,23 +52,23 @@ span.tripal_feature-featureloc_sequence-exon {
 
 span.tripal_feature-featureloc_sequence-intron {
    background-image: url('../images/type_color6.png');
- 
+
 }
 
-/* 
+/*
  * Sequence Retrieval Form
  */
 #tripal-feature-seq-extract-form-table {
   border-collapse: collapse;
   border: 0px solid #DDDDDD;
-  border-spacing: 0;  
+  border-spacing: 0;
   margin: 1em 0;
   width: auto;
 }
 #tripal-feature-seq-extract-form-table tr {
   background-color: transparent;
   border: 0px solid #CCCCCC;
-  padding: 0.1em 0.6em;  
+  padding: 0.1em 0.6em;
 }
 #tripal-feature-seq-extract-form-table td {
   border: 0px solid #DDDDDD;
@@ -77,4 +77,22 @@ span.tripal_feature-featureloc_sequence-intron {
 }
 #tripal-feature-seq-extract-form-table .form-item {
   white-space: normal;
+}
+
+/*
+ * Admin Summary Charts
+ */
+.tripal-admin-summary {
+  border: 1px solid #ccc;
+  padding: 15px;
+  margin-bottom: 15px;
+}
+.tripal-admin-summary .axis {
+  font: 10px sans-serif;
+}
+.tripal-admin-summary .axis path,
+.tripal-admin-summary .axis line {
+  fill: none;
+  stroke: #000;
+  shape-rendering: crispEdges;
 }

+ 183 - 0
tripal_feature/theme/js/tripalFeature.adminChart.js

@@ -0,0 +1,183 @@
+Drupal.behaviors.tripalFeature_adminSummaryChart = {
+  attach: function (context, settings) {
+
+    // First add the container after the view header.
+    var container = d3.select('#tripal-feature-admin-summary');
+    if (container.empty) {
+      container = d3.select('.view-header').append('div')
+        .attr('id', 'tripal-feature-admin-summary')
+        .classed('tripal-admin-summary',true);
+    }
+
+    // Set-up the dimensions for our chart canvas.
+    var margin = {top: 20, right: 20, bottom: 100, left: 100},
+        width = 960 - margin.left - margin.right,
+        height = 500 - margin.top - margin.bottom;
+
+    var color = d3.scale.ordinal()
+        .range(["#a6cee3","#1f78b4","#b2df8a","#33a02c","#fb9a99","#e31a1c","#fdbf6f","#ff7f00","#cab2d6","#6a3d9a","#ffff99","#b15928"]);
+
+    var formatNum = d3.format("0,000");
+
+    // Set-up the scales of the chart.
+    var x0 = d3.scale.ordinal()
+        .rangeRoundBands([0, width], .1);
+    var x1 = d3.scale.ordinal();
+    var y = d3.scale.linear()
+        .range([height, 0]);
+
+    // Now set-up the axis functions.
+    var xAxis = d3.svg.axis()
+        .scale(x0)
+        .orient('bottom');
+    var yAxis = d3.svg.axis()
+        .scale(y)
+        .orient('left')
+        .ticks(10, '');
+
+    // Create our chart canvas.
+    var svg = d3.select('#tripal-feature-admin-summary').append('svg')
+        .attr('width', width + margin.left + margin.right)
+        .attr('height', height + margin.top + margin.bottom)
+      .append('g')
+        .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
+
+    // The data was parsed and saved into tripalFeature.admin.summary
+    // in the preprocess function for this template.
+    if (Drupal.settings.tripalFeature.admin.summary) {
+
+      // map the data to the x & y axis' of our chart.
+      data = Drupal.settings.tripalFeature.admin.summary;
+      x0.domain(data.map(function(d) { return d.name; }));
+      x1.domain(Drupal.settings.tripalFeature.admin.organisms).rangeRoundBands([0, x0.rangeBand()]);
+      //y.domain([0, d3.max(data, function(d) { return d3.max(d.organisms, function(d) { return d.value; }); })]);
+      y.domain([0, d3.max(data, function(d) { return d.total_features; })]);
+
+      // Create the x-axis.
+      var xaxis = svg.append('g')
+          .attr('class', 'x axis')
+          .attr('transform', 'translate(0,' + height + ')')
+          .call(xAxis);
+
+      // Wrap the scientific names so they fit better.
+      xaxis.selectAll(".tick text")
+          .call(wrap, x0.rangeBand());
+
+      // Label the  x-axis.
+      xaxis.append('g')
+        .attr('class', 'axis-label')
+          .attr('transform', 'translate(' + width/2 + ',60)')
+        .append('text')
+          .attr('font-size', '16px')
+          .attr('dy', '.71em')
+          .style('text-anchor', 'middle')
+          .text('Types of Features');
+
+      // Create the y-axis.
+      var yaxis = svg.append('g')
+          .attr('class', 'y axis')
+          .call(yAxis);
+
+      // Label the y-axis.
+      yaxis.append('g')
+        .attr('class', 'axis-label')
+          .attr('transform', 'translate(-70,' + height/2 + ')')
+        .append('text')
+          .attr('transform', 'rotate(-90)')
+          .attr('font-size', '16px')
+          .attr('dy', '.71em')
+          .style('text-anchor', 'middle')
+          .text('Total Number of Features');
+
+      // Add a g element to contain each set of bars (1 per type).
+      var type = svg.selectAll(".type")
+          .data(data)
+        .enter().append("g")
+          .attr("class", "g")
+          .attr("transform", function(d) { return "translate(" + x0(d.name) + ",0)"; });
+
+      // Now add the bars :)
+      // Keep in mind some processing was done in the preprocess function to
+      // generate the bars array based on the organisms array
+      // and pre-calculated the y0 & y1 used here.
+      type.selectAll("rect")
+          .data(function(d) { return d.bars; })
+        .enter().append("rect")
+          .attr("width", x0.rangeBand())
+          .attr("y", function(d) { return y(d.y1); })
+          .attr("height", function(d) { return y(d.y0) - y(d.y1); })
+          .style("fill", function(d) { return color(d.name); })
+        .append("svg:title")
+          .text(function(d) { return formatNum(d.y1 - d.y0); });
+
+      // Add the total to the top of the bar.
+      svg.selectAll("g.bar-totals")
+        .data(data)
+      .enter().append('g')
+        .classed('bar-totals', true)
+      .append("text")
+        .attr("class", "bar-label")
+        .attr("text-anchor", "middle")
+        .attr("x", function(d) { return x0(d.name) + x0.rangeBand()/2; })
+        .attr("y", function(d) { return y(d.total_features) -5; })
+        .text(function(d) { return formatNum(d.total_features); });
+
+      // Finally add in a simple legend.
+      var legend = svg.selectAll(".legend")
+          .data(Drupal.settings.tripalFeature.admin.organisms.slice().reverse())
+        .enter().append("g")
+          .attr("class", "legend")
+          .attr("transform", function(d, i) { return "translate(0," + i * 20 + ")"; });
+      legend.append("rect")
+          .attr("x", width - 18)
+          .attr("width", 18)
+          .attr("height", 18)
+          .style("fill", color);
+      legend.append("text")
+          .attr("x", width - 24)
+          .attr("y", 9)
+          .attr("dy", ".35em")
+          .style("text-anchor", "end")
+          .attr('font-style','italic')
+          .text(function(d) { return d; });
+
+      // Add a small blurb mentioning this is from an mview and you should update ;).
+      var blurb = svg.append('g')
+          .classed('figure-legend', true)
+          .attr("transform", function(d, i) { return "translate(" + (width - 18) + "," + (height + 50) + ")"; });
+
+      blurb.append("svg:a")
+        .attr("xlink:href", Drupal.settings.tripalFeature.admin.mviewUrl)
+        .append('text')
+          .attr('font-style','italic')
+          .style("fill", '#7F7F7F')
+          .style("font-size","10px")
+          .style("text-anchor", "end")
+          .text("Update Materialized View");
+      blurb.append('text')
+        .attr('x', 0)
+        .attr('y', 20)
+        .attr('font-style','italic')
+        .style("fill", '#7F7F7F')
+        .style("font-size","10px")
+        .style("text-anchor", "end")
+        .text('Updated on ' + Drupal.settings.tripalFeature.admin.mviewLastUpdate);
+
+      function wrap(text, width) {
+        text.each(function() {
+          var text = d3.select(this),
+              words = text.text().split(/[\s_]+/).reverse(),
+              word,
+              lineNumber = 0,
+              lineHeight = 1.1, // ems
+              y = text.attr("y"),
+              dy = parseFloat(text.attr("dy")),
+              tspan = text.text(null).append("tspan").attr("x", 0).attr("y", y).attr("dy", dy + "em");
+          while (word = words.pop()) {
+            tspan = text.append("tspan").attr("x", 0).attr("y", y).attr("dy", ++lineNumber * lineHeight + dy + "em").text(word);
+          }
+        });
+      }
+    }
+  }
+};

+ 5 - 12
tripal_feature/tripal_feature.views_default.inc

@@ -475,18 +475,11 @@ function tripal_feature_defaultview_admin_features() {
   $handler->display->display_options['fields']['nothing']['label'] = '';
   $handler->display->display_options['fields']['nothing']['alter']['text'] = '[edit_node]   [delete_node]';
   $handler->display->display_options['fields']['nothing']['element_label_colon'] = FALSE;
-  /* Sort criterion: Chado Organism: Common Name */
-  $handler->display->display_options['sorts']['common_name']['id'] = 'common_name';
-  $handler->display->display_options['sorts']['common_name']['table'] = 'organism';
-  $handler->display->display_options['sorts']['common_name']['field'] = 'common_name';
-  /* Sort criterion: Chado Cvterm: Name */
-  $handler->display->display_options['sorts']['name']['id'] = 'name';
-  $handler->display->display_options['sorts']['name']['table'] = 'cvterm';
-  $handler->display->display_options['sorts']['name']['field'] = 'name';
-  /* Sort criterion: Chado Feature: Name */
-  $handler->display->display_options['sorts']['name_1']['id'] = 'name_1';
-  $handler->display->display_options['sorts']['name_1']['table'] = 'feature';
-  $handler->display->display_options['sorts']['name_1']['field'] = 'name';
+  /* Sort criterion: Chado Feature: Feature Id */
+  $handler->display->display_options['sorts']['feature_id']['id'] = 'feature_id';
+  $handler->display->display_options['sorts']['feature_id']['table'] = 'feature';
+  $handler->display->display_options['sorts']['feature_id']['field'] = 'feature_id';
+  $handler->display->display_options['sorts']['feature_id']['order'] = 'DESC';
   /* Filter criterion: Chado Organism: Common Name */
   $handler->display->display_options['filters']['common_name']['id'] = 'common_name';
   $handler->display->display_options['filters']['common_name']['table'] = 'organism';

+ 5 - 4
tripal_featuremap/tripal_featuremap.views_default.inc

@@ -213,10 +213,11 @@ function tripal_featuremap_defaultview_admin_featuremaps() {
   $handler->display->display_options['fields']['nothing']['label'] = '';
   $handler->display->display_options['fields']['nothing']['alter']['text'] = '[edit_node]   [delete_node]';
   $handler->display->display_options['fields']['nothing']['element_label_colon'] = FALSE;
-  /* Sort criterion: Chado Featuremap: Name */
-  $handler->display->display_options['sorts']['name']['id'] = 'name';
-  $handler->display->display_options['sorts']['name']['table'] = 'featuremap';
-  $handler->display->display_options['sorts']['name']['field'] = 'name';
+  /* Sort criterion: Chado Featuremap: Id */
+  $handler->display->display_options['sorts']['featuremap_id']['id'] = 'featuremap_id';
+  $handler->display->display_options['sorts']['featuremap_id']['table'] = 'featuremap';
+  $handler->display->display_options['sorts']['featuremap_id']['field'] = 'featuremap_id';
+  $handler->display->display_options['sorts']['featuremap_id']['order'] = 'DESC';
   /* Filter criterion: Chado Featuremap: Name */
   $handler->display->display_options['filters']['name_1']['id'] = 'name_1';
   $handler->display->display_options['filters']['name_1']['table'] = 'featuremap';

+ 5 - 0
tripal_genetic/tripal_genetic.views_default.inc

@@ -140,6 +140,11 @@ function tripal_genetic_defaultviews_admin_genotypes() {
   $handler->display->display_options['fields']['description']['id'] = 'description';
   $handler->display->display_options['fields']['description']['table'] = 'genotype';
   $handler->display->display_options['fields']['description']['field'] = 'description';
+  /* Sort criterion: Chado Genotype: Id */
+  $handler->display->display_options['sorts']['genotype_id']['id'] = 'genotype_id';
+  $handler->display->display_options['sorts']['genotype_id']['table'] = 'genotype';
+  $handler->display->display_options['sorts']['genotype_id']['field'] = 'genotype_id';
+  $handler->display->display_options['sorts']['genotype_id']['order'] = 'DESC';
   /* Filter criterion: Chado Genotype: Uniquename */
   $handler->display->display_options['filters']['uniquename']['id'] = 'uniquename';
   $handler->display->display_options['filters']['uniquename']['table'] = 'genotype';

+ 5 - 4
tripal_library/tripal_library.views_default.inc

@@ -237,10 +237,11 @@ function tripal_library_admin_defaultviews_library() {
   $handler->display->display_options['fields']['nothing']['label'] = '';
   $handler->display->display_options['fields']['nothing']['alter']['text'] = '[edit_node]   [delete_node]';
   $handler->display->display_options['fields']['nothing']['element_label_colon'] = FALSE;
-  /* Sort criterion: Chado Library: Name */
-  $handler->display->display_options['sorts']['name']['id'] = 'name';
-  $handler->display->display_options['sorts']['name']['table'] = 'library';
-  $handler->display->display_options['sorts']['name']['field'] = 'name';
+  /* Sort criterion: Chado Library: Id */
+  $handler->display->display_options['sorts']['library_id']['id'] = 'library_id';
+  $handler->display->display_options['sorts']['library_id']['table'] = 'library';
+  $handler->display->display_options['sorts']['library_id']['field'] = 'library_id';
+  $handler->display->display_options['sorts']['library_id']['order'] = 'DESC';
   /* Filter criterion: Chado Organism: Common Name */
   $handler->display->display_options['filters']['common_name']['id'] = 'common_name';
   $handler->display->display_options['filters']['common_name']['table'] = 'organism';

+ 20 - 8
tripal_natural_diversity/tripal_natural_diversity.views_default.inc

@@ -101,14 +101,11 @@ function tripal_natural_diversity_defaultview_admin_natdiv_exp() {
   $handler->display->display_options['fields']['description']['table'] = 'nd_geolocation';
   $handler->display->display_options['fields']['description']['field'] = 'description';
   $handler->display->display_options['fields']['description']['label'] = 'Location Experiment Performed';
-  /* Sort criterion: Chado Cvterm: Name */
-  $handler->display->display_options['sorts']['name']['id'] = 'name';
-  $handler->display->display_options['sorts']['name']['table'] = 'cvterm';
-  $handler->display->display_options['sorts']['name']['field'] = 'name';
-  /* Sort criterion: Chado Nd Geolocation: Description */
-  $handler->display->display_options['sorts']['description']['id'] = 'description';
-  $handler->display->display_options['sorts']['description']['table'] = 'nd_geolocation';
-  $handler->display->display_options['sorts']['description']['field'] = 'description';
+  /* Sort criterion: Chado Nd Experiment: Id */
+  $handler->display->display_options['sorts']['nd_experiment_id']['id'] = 'nd_experiment_id';
+  $handler->display->display_options['sorts']['nd_experiment_id']['table'] = 'nd_experiment';
+  $handler->display->display_options['sorts']['nd_experiment_id']['field'] = 'nd_experiment_id';
+  $handler->display->display_options['sorts']['nd_experiment_id']['order'] = 'DESC';
   /* Filter criterion: Chado Nd Experiment: Type Id */
   $handler->display->display_options['filters']['type_id']['id'] = 'type_id';
   $handler->display->display_options['filters']['type_id']['table'] = 'nd_experiment';
@@ -251,6 +248,11 @@ function tripal_natural_diversity_defaultview_admin_geolocations() {
   $handler->display->display_options['fields']['geodetic_datum']['id'] = 'geodetic_datum';
   $handler->display->display_options['fields']['geodetic_datum']['table'] = 'nd_geolocation';
   $handler->display->display_options['fields']['geodetic_datum']['field'] = 'geodetic_datum';
+  /* Sort criterion: Chado Nd Geolocation: Id */
+  $handler->display->display_options['sorts']['nd_geolocation_id']['id'] = 'nd_geolocation_id';
+  $handler->display->display_options['sorts']['nd_geolocation_id']['table'] = 'nd_geolocation';
+  $handler->display->display_options['sorts']['nd_geolocation_id']['field'] = 'nd_geolocation_id';
+  $handler->display->display_options['sorts']['nd_geolocation_id']['order'] = 'DESC';
   /* Filter criterion: Chado Nd Geolocation: Geodetic Datum */
   $handler->display->display_options['filters']['geodetic_datum']['id'] = 'geodetic_datum';
   $handler->display->display_options['filters']['geodetic_datum']['table'] = 'nd_geolocation';
@@ -384,6 +386,11 @@ function tripal_natural_diversity_defaultview_admin_reagents() {
   $handler->display->display_options['fields']['name']['table'] = 'cvterm';
   $handler->display->display_options['fields']['name']['field'] = 'name';
   $handler->display->display_options['fields']['name']['label'] = 'Type';
+  /* Sort criterion: Chado Nd Reagent: Id */
+  $handler->display->display_options['sorts']['nd_reagent_id']['id'] = 'nd_reagent_id';
+  $handler->display->display_options['sorts']['nd_reagent_id']['table'] = 'nd_reagent';
+  $handler->display->display_options['sorts']['nd_reagent_id']['field'] = 'nd_reagent_id';
+  $handler->display->display_options['sorts']['nd_reagent_id']['order'] = 'DESC';
   /* Filter criterion: Chado Nd Reagent: Type Id */
   $handler->display->display_options['filters']['type_id']['id'] = 'type_id';
   $handler->display->display_options['filters']['type_id']['table'] = 'nd_reagent';
@@ -495,6 +502,11 @@ function tripal_natural_diversity_defaultview_admin_protocols() {
   $handler->display->display_options['fields']['name']['id'] = 'name';
   $handler->display->display_options['fields']['name']['table'] = 'nd_protocol';
   $handler->display->display_options['fields']['name']['field'] = 'name';
+  /* Sort criterion: Chado Nd Protocol: Id */
+  $handler->display->display_options['sorts']['nd_protocol_id']['id'] = 'nd_protocol_id';
+  $handler->display->display_options['sorts']['nd_protocol_id']['table'] = 'nd_protocol';
+  $handler->display->display_options['sorts']['nd_protocol_id']['field'] = 'nd_protocol_id';
+  $handler->display->display_options['sorts']['nd_protocol_id']['order'] = 'DESC';
   /* Filter criterion: Chado Nd Protocol: Name */
   $handler->display->display_options['filters']['name']['id'] = 'name';
   $handler->display->display_options['filters']['name']['table'] = 'nd_protocol';

+ 5 - 0
tripal_phenotype/tripal_phenotype.views_default.inc

@@ -177,6 +177,11 @@ function tripal_phenotype_defaultview_admin_phenotypes() {
   $handler->display->display_options['fields']['name']['field'] = 'name';
   $handler->display->display_options['fields']['name']['relationship'] = 'assay_id_to_cvterm';
   $handler->display->display_options['fields']['name']['label'] = 'Evidence Type';
+  /* Sort criterion: Chado Phenotype: Id */
+  $handler->display->display_options['sorts']['phenotype_id']['id'] = 'phenotype_id';
+  $handler->display->display_options['sorts']['phenotype_id']['table'] = 'phenotype';
+  $handler->display->display_options['sorts']['phenotype_id']['field'] = 'phenotype_id';
+  $handler->display->display_options['sorts']['phenotype_id']['order'] = 'DESC';
   /* Filter criterion: Chado Phenotype: Attr Id */
   $handler->display->display_options['filters']['attr_id']['id'] = 'attr_id';
   $handler->display->display_options['filters']['attr_id']['table'] = 'phenotype';

+ 5 - 0
tripal_project/tripal_project.views_default.inc

@@ -223,6 +223,11 @@ function tripal_project_defaultview_admin_projects() {
   $handler->display->display_options['fields']['nothing']['element_class'] = 'short-column';
   $handler->display->display_options['fields']['nothing']['element_label_class'] = 'short-column';
   $handler->display->display_options['fields']['nothing']['element_label_colon'] = FALSE;
+  /* Sort criterion: Chado Project: Id */
+  $handler->display->display_options['sorts']['project_id']['id'] = 'project_id';
+  $handler->display->display_options['sorts']['project_id']['table'] = 'project';
+  $handler->display->display_options['sorts']['project_id']['field'] = 'project_id';
+  $handler->display->display_options['sorts']['project_id']['order'] = 'DESC';
   /* Filter criterion: Chado Project: Name */
   $handler->display->display_options['filters']['name']['id'] = 'name';
   $handler->display->display_options['filters']['name']['table'] = 'project';

+ 5 - 12
tripal_pub/tripal_pub.views_default.inc

@@ -152,18 +152,11 @@ function tripal_pub_defaultview_admin_publications() {
   $handler->display->display_options['fields']['type']['table'] = 'cvterm';
   $handler->display->display_options['fields']['type']['field'] = 'name';
   $handler->display->display_options['fields']['type']['label'] = 'Type';
-  /* Sort criterion: Chado Pub: Pyear */
-  $handler->display->display_options['sorts']['pyear']['id'] = 'year';
-  $handler->display->display_options['sorts']['pyear']['table'] = 'pub';
-  $handler->display->display_options['sorts']['pyear']['field'] = 'pyear';
-  /* Sort criterion: Chado Pub: Title */
-  $handler->display->display_options['sorts']['title']['id'] = 'title';
-  $handler->display->display_options['sorts']['title']['table'] = 'pub';
-  $handler->display->display_options['sorts']['title']['field'] = 'title';
-  /* Sort criterion: Chado Cvterm: Name */
-  $handler->display->display_options['sorts']['type']['id'] = 'type';
-  $handler->display->display_options['sorts']['type']['table'] = 'cvterm';
-  $handler->display->display_options['sorts']['type']['field'] = 'name';
+  /* Sort criterion: Chado Pub: Id */
+  $handler->display->display_options['sorts']['pub_id']['id'] = 'pub_id';
+  $handler->display->display_options['sorts']['pub_id']['table'] = 'pub';
+  $handler->display->display_options['sorts']['pub_id']['field'] = 'pub_id';
+  $handler->display->display_options['sorts']['pub_id']['order'] = 'DESC';
   /* Filter criterion: Chado Pub: Title */
   $handler->display->display_options['filters']['title']['id'] = 'title';
   $handler->display->display_options['filters']['title']['table'] = 'pub';

+ 5 - 8
tripal_stock/tripal_stock.views_default.inc

@@ -233,14 +233,11 @@ function tripal_stock_defaultview_admin_stocks() {
   $handler->display->display_options['fields']['nothing']['label'] = '';
   $handler->display->display_options['fields']['nothing']['alter']['text'] = '[edit_node]   [delete_node]';
   $handler->display->display_options['fields']['nothing']['element_label_colon'] = FALSE;
-  /* Sort criterion: Chado Organism: Common Name */
-  $handler->display->display_options['sorts']['common_name']['id'] = 'common_name';
-  $handler->display->display_options['sorts']['common_name']['table'] = 'organism';
-  $handler->display->display_options['sorts']['common_name']['field'] = 'common_name';
-  /* Sort criterion: Chado Stock: Uniquename */
-  $handler->display->display_options['sorts']['uniquename']['id'] = 'uniquename';
-  $handler->display->display_options['sorts']['uniquename']['table'] = 'stock';
-  $handler->display->display_options['sorts']['uniquename']['field'] = 'uniquename';
+  /* Sort criterion: Chado Stock: Id */
+  $handler->display->display_options['sorts']['stock_id']['id'] = 'stock_id';
+  $handler->display->display_options['sorts']['stock_id']['table'] = 'stock';
+  $handler->display->display_options['sorts']['stock_id']['field'] = 'stock_id';
+  $handler->display->display_options['sorts']['stock_id']['order'] = 'DESC';
   /* Filter criterion: Chado Organism: Common Name */
   $handler->display->display_options['filters']['common_name']['id'] = 'common_name';
   $handler->display->display_options['filters']['common_name']['table'] = 'organism';

+ 78 - 26
tripal_views/views/handlers/tripal_views_handler_filter_select_cvterm.inc

@@ -33,15 +33,25 @@ class tripal_views_handler_filter_select_cvterm extends tripal_views_handler_fil
       // we can't assume that tripal admin won't do this) then we only need
       // to make one-hop to the cv table.
       if ($this->table == 'cvterm') {
+
+        $return = $this->get_select_option_where($this->table);
+        $where_clauses = $return['where_clauses'];
+        $arguements = $return['arguements'];
+        $base_where = '';
+        if (!empty($where_clauses)) {
+          $base_where = implode(' AND ', $where_clauses);
+        }
+
         // Using a "Loose Index Scan" to get a list of all the cvs used
         // in the cvterm table (ie: all the cv's with at least one term).
         // See https://wiki.postgresql.org/wiki/Loose_indexscan
         $sql = "
           WITH RECURSIVE t AS (
             SELECT MIN(cv_id) AS col FROM {!table}
+              " . ($base_where == '' ? '' : "WHERE " . $base_where) . "
             UNION ALL
-            SELECT (SELECT MIN(cv_id) FROM {!table} WHERE cv_id > col)
-            FROM t WHERE col IS NOT NULL
+            SELECT (SELECT MIN(cv_id) FROM {!table} WHERE cv_id > col " . ($base_where == '' ? '' : " AND " . $base_where) . ")
+              FROM t WHERE col IS NOT NULL
           )
           SELECT cv_id, name
             FROM {cv}
@@ -52,6 +62,30 @@ class tripal_views_handler_filter_select_cvterm extends tripal_views_handler_fil
       // Otherwise, (most often the case) we need to make two-hops
       // to the cv table through the cvterm table.
       else {
+
+        // There are actually two sets of conditions we care about and of course
+        // they are placed in different places in the query :p.
+        // 1. Restrictions on the cvterm table. This lets users specify: only
+        // show these exact types.
+        $return = $this->get_select_option_where('cvterm');
+        $where_clauses = $return['where_clauses'];
+        $cvterm_args = $return['arguements'];
+        $cvterm_where = '';
+        if (!empty($where_clauses)) {
+          $cvterm_where = implode(' AND ', $where_clauses);
+        }
+        // 2. Restrictions on the filter table Since those affect which types
+        // have been used.
+        $return = $this->get_select_option_where($this->table);
+        $where_clauses = $return['where_clauses'];
+        $base_args = $return['arguements'];
+        $base_where = '';
+        if (!empty($where_clauses)) {
+          $base_where = implode(' AND ', $where_clauses);
+        }
+        // We only supply one set or arguements those so merge the two.
+        $arguements = array_merge($cvterm_args, $base_args);
+
         // Using a "Loose Index Scan" to get a list of all the cvs used
         // in the table the drop-down filter is from.
         // See https://wiki.postgresql.org/wiki/Loose_indexscan
@@ -60,34 +94,29 @@ class tripal_views_handler_filter_select_cvterm extends tripal_views_handler_fil
             SELECT MIN(cvterm.cv_id) AS col
               FROM {!table} filter_table
               LEFT JOIN {cvterm} ON filter_table.!field=cvterm.cvterm_id
+              " . ($base_where == '' ? '' : "WHERE " . $base_where) . "
             UNION ALL
             SELECT (
                 SELECT MIN(cv_id)
                 FROM {!table} filter_table
                 LEFT JOIN {cvterm} ON filter_table.!field=cvterm.cvterm_id
-                WHERE cv_id > col
+                WHERE cv_id > col " . ($base_where == '' ? '' : " AND " . $base_where) . "
               )
               FROM t WHERE col IS NOT NULL
           )
-          SELECT cv_id, name
-            FROM chado.cv
-            WHERE cv_id IN (SELECT col FROM t where col IS NOT NULL)
-            ORDER BY cv.name ASC";
+          SELECT cvterm_id, name
+            FROM {cvterm}
+            WHERE cv_id IN (SELECT col FROM t where col IS NOT NULL) " . ($cvterm_where == '' ? '' : " AND " . $cvterm_where) . "
+            ORDER BY cvterm.name ASC";
         $sql = format_string($sql, array('!table' => $this->table, '!field' => $this->field));
       }
-      $resource = chado_query($sql);
+      $resource = chado_query($sql, $arguements);
 
       // Now actually gerenate the select list
       // based on the results from the above query.
       $cvterms = array();
       foreach ($resource as $r) {
-        $results = chado_select_record('cvterm', array('cvterm_id', 'name'), array('cv_id' => $r->cv_id));
-        if (empty($results)) {
-          $results = array();
-        }
-        foreach ($results as $c) {
-          $cvterms[$c->cvterm_id] = $c->name;
-        }
+        $cvterms[$r->cvterm_id] = $r->name;
       }
 
     }
@@ -95,28 +124,50 @@ class tripal_views_handler_filter_select_cvterm extends tripal_views_handler_fil
     // the base table.
     else {
 
-      $where_clauses = $this->get_select_option_where();
-      $where = '';
+      // There are actually two sets of conditions we care about and of course
+      // they are placed in different places in the query :p.
+      // 1. Restrictions on the cvterm table. This lets users specify: only
+      // show these exact types.
+      $return = $this->get_select_option_where('cvterm');
+      $where_clauses = $return['where_clauses'];
+      $cvterm_args = $return['arguements'];
+      $cvterm_where = '';
+      if (!empty($where_clauses)) {
+        $cvterm_where = implode(' AND ', $where_clauses);
+      }
+      // 2. Restrictions on the filter table Since those affect which types
+      // have been used.
+      $return = $this->get_select_option_where($this->table);
+      $where_clauses = $return['where_clauses'];
+      $base_args = $return['arguements'];
+      $base_where = '';
       if (!empty($where_clauses)) {
-        $where = ' AND ' . implode(' AND ', $where_clauses);
+        $base_where = implode(' AND ', $where_clauses);
       }
+      // We only supply one set or arguements those so merge the two.
+      $arguements = array_merge($cvterm_args, $base_args);
 
       // Using a "Loose Index Scan" to get a list of all the cvterms used
       // in the base table. See https://wiki.postgresql.org/wiki/Loose_indexscan
       $sql = "
         WITH RECURSIVE t AS (
-          SELECT MIN(!field) AS col FROM {!table} " . ($where == '' ? '' : "WHERE " . $where) . "
+          SELECT MIN(!field) AS col FROM {!table}
+            " . ($base_where == '' ? '' : "WHERE " . $base_where) . "
           UNION ALL
-          SELECT (SELECT MIN(!field) FROM {!table} WHERE !field > col " . $where . ")
+          SELECT (
+            SELECT MIN(!field)
+            FROM {!table}
+            WHERE !field > col " . ($base_where == '' ? '' : " AND " . $base_where) . "
+          )
           FROM t WHERE col IS NOT NULL
         )
         SELECT cvterm_id, name
           FROM {cvterm}
-          WHERE cvterm_id IN (SELECT col FROM t where col IS NOT NULL)
+          WHERE cvterm_id IN (SELECT col FROM t where col IS NOT NULL) " . ($cvterm_where == '' ? '' : " AND " . $cvterm_where) . "
           ORDER BY cvterm.name ASC";
       $sql = format_string($sql, array('!table' => $this->table, '!field' => $this->field));
 
-      $resource = chado_query($sql);
+      $resource = chado_query($sql, $arguements);
       $cvterms = array();
 
       // Add an "- Any - " option to allow a type to not be set by default.
@@ -141,9 +192,10 @@ class tripal_views_handler_filter_select_cvterm extends tripal_views_handler_fil
    * @return
    *   An array of full qualified where clauses (ie: table.myfield = 'fred')
    */
-  function get_select_option_where() {
-    $where = array();
-
+  function get_select_option_where($table = NULL, $generic_placeholder = TRUE) {
+    return parent::get_select_option_where($table, $generic_placeholder);
+  }
+/*
     // build a where clause that will filter the list in the drop box
     // using fields that are not exposed and that are for the table
     // from whcih the values in the drop box will be slected and
@@ -180,7 +232,7 @@ class tripal_views_handler_filter_select_cvterm extends tripal_views_handler_fil
 
     return $where;
   }
-
+*/
   /**
    * {@inheritdoc}
    */

+ 63 - 51
tripal_views/views/handlers/tripal_views_handler_filter_select_id.inc

@@ -34,59 +34,75 @@ class tripal_views_handler_filter_select_id extends tripal_views_handler_filter_
    */
   function get_select_options() {
 
-    if (isset($this->options['show_all'])) {
-      $cv_id = variable_get('chado_' . $this->view->base_table . '_cv', NULL);
-      if ($cv_id) {
-        $results = chado_select_record('cvterm', array('cvterm_id', 'name'), array('cv_id' => $cv_id));
-        if (empty($results)) {
-          $results = array();
-        }
-        foreach ($results as $c) {
-          $cvterms[$c->cvterm_id] = $c->name;
-        }
-      }
-      else {
-        //get a list of cvs currently used
-        if ($this->view->base_table == 'cvterm') {
-          $sql = 'SELECT distinct(cv.cv_id) FROM chado.' . $this->view->base_table
-            .' LEFT JOIN chado.cv cv ON cv.cv_id=cvterm.cv_id';
-        }
-        else {
-          $sql = 'SELECT distinct(cv.cv_id) FROM chado.' . $this->view->base_table
-            .' LEFT JOIN chado.cvterm cvterm ON cvterm.cvterm_id=' . $this->view->base_table . '.type_id '
-            .'LEFT JOIN chado.cv cv ON cv.cv_id=cvterm.cv_id';
-        }
-        // D7 TODO: Check DBTNG changes work
-        $resource = chado_query($sql);
-        $cvterms = array();
-        foreach ($resource as $r) {
-          $results = chado_select_record('cvterm', array('cvterm_id', 'name'), array('cv_id' => $r->cv_id));
-          if (empty($results)) {
-            $results = array();
-          }
-          foreach ($results as $c) {
-            $cvterms[$c->cvterm_id] = $c->name;
-          }
-        }
-      }// end of if variable not defined
+    // @TODO: Make name field configurable.
+    $name_field = 'common_name';
+
+    // First check that this table has a name field.
+    $table_desc = chado_get_schema($this->parent_table);
+    if (!isset($table_desc['fields'][$name_field])) {
+      return array();
+    }
+
+    // If the "Show All" options is set then show all the "names" from
+    // the table referenced by the foreign key constraint.
+    if (isset($this->options['show_all']) AND $this->options['show_all'] == TRUE) {
+
+      // We still want to use any hidden fitlers on the parent table
+      // but the arguements will need to be field names rather than
+      // generic placeholders so we need to tell get_select_option_where() that.
+      $return = $this->get_select_option_where($this->parent_table, FALSE);
+      $args = $return['arguements'];
 
+      // Simply grab all the values from the table referenced by
+      // the foreign key constraint. Since we use the id as the key of
+      // the options there is no need to use DISTRINCT in the query.
+      $resource = chado_select_record($this->parent_table, array($this->field, $name_field), $args);
+      $options = array();
+      foreach ($resource as $r) {
+        $options[$r->{$this->field}] = $r->{$name_field};
+      }
     }
+    // Otherwise, only show those that are actually used in the base table.
     else {
 
-      $where_clauses = $this->get_select_option_where();
+      $return = $this->get_select_option_where($this->parent_table);
+      $where_clauses = $return['where_clauses'];
+      $arguements = $return['arguements'];
       $where = '';
       if (!empty($where_clauses)) {
-        $where = ' AND ' . implode(' AND ', $where_clauses);
+        $where = implode(' AND ', $where_clauses);
       }
 
-      $sql = "SELECT PARENT.%field as id, PARENT.name as name
-              FROM {%parent_table} PARENT
-                LEFT JOIN {%table} CHILD ON CHILD.%field = PARENT.%field
-              WHERE CHILD.%field IS NOT NULL $where
-              GROUP BY PARENT.%field
-              ORDER BY name";
-      $sql = str_replace(array('%field', '%table','%parent_table'),array($this->field, $this->table, $this->parent_table), $sql);
-      $resource = chado_query($sql);
+
+      // Using a "Loose Index Scan" to get a list of all the unique values for
+      // the name in the table referenced by the foreign key constraint.
+      // See https://wiki.postgresql.org/wiki/Loose_indexscan
+      $sql = "WITH RECURSIVE t AS (
+            SELECT MIN(filter_table.!id_field) AS col
+              FROM {!filter_table} filter_table
+              LEFT JOIN {!foreign_table} foreign_table ON filter_table.!id_field=foreign_table.!id_field
+              " . ($where == '' ? '' : "WHERE " . $where) . "
+            UNION ALL
+            SELECT (
+                SELECT MIN(filter_table.!id_field)
+                FROM {!filter_table} filter_table
+                LEFT JOIN {!foreign_table} foreign_table ON filter_table.!id_field=foreign_table.!id_field
+                WHERE filter_table.!id_field > col " . ($where == '' ? '' : " AND " . $where) . "
+              )
+              FROM t WHERE col IS NOT NULL
+          )
+          SELECT !id_field as id, !name_field as name
+            FROM {!foreign_table}
+            WHERE !id_field IN (SELECT col FROM t where col IS NOT NULL)
+            ORDER BY !name_field ASC";
+      $sql = format_string($sql, array(
+        '!filter_table' => $this->table,
+        '!foreign_table' => $this->parent_table,
+        '!id_field' => $this->field,
+        '!name_field' => $name_field
+      ));
+
+      $resource = chado_query($sql, $arguements);
       $options = array();
 
       if ($this->options['select_optional']) {
@@ -97,8 +113,6 @@ class tripal_views_handler_filter_select_id extends tripal_views_handler_filter_
         $options[$r->id] = $r->name;
       }
     }
-    //sort options by name (case insensitive)
-    natcasesort($options);
 
     return $options;
 
@@ -110,10 +124,8 @@ class tripal_views_handler_filter_select_id extends tripal_views_handler_filter_
    * @return
    *   An array of full qualified where clauses (ie: table.myfield = 'fred')
    */
-  function get_select_option_where() {
-    $where = parent::get_select_option_where();
-
-    return $where;
+  function get_select_option_where($table = NULL, $generic_placeholder = TRUE) {
+    return parent::get_select_option_where($table, $generic_placeholder);
   }
 
   /**

+ 47 - 13
tripal_views/views/handlers/tripal_views_handler_filter_select_string.inc

@@ -64,6 +64,11 @@ class tripal_views_handler_filter_select_string extends views_handler_filter_str
       'bool' => TRUE,
       'export' => TRUE
     );
+    $options['show_all'] = array(
+      'default' => FALSE,
+      'bool' => TRUE,
+      'export' => TRUE
+    );
     $options['max_length'] = array(
       'default' => 40,
       'export' => TRUE
@@ -81,7 +86,9 @@ class tripal_views_handler_filter_select_string extends views_handler_filter_str
    */
   function get_select_options() {
 
-    $where_clauses = $this->get_select_option_where();
+    $return = $this->get_select_option_where();
+    $where_clauses = $return['where_clauses'];
+    $arguements = $return['arguements'];
     $where = '';
     if (!empty($where_clauses)) {
       $where = ' WHERE ' . implode(' AND ', $where_clauses);
@@ -89,7 +96,7 @@ class tripal_views_handler_filter_select_string extends views_handler_filter_str
 
     // get the values from the table
     $sql = 'SELECT ' . $this->real_field . ' FROM {' . $this->table . '} ' . $where . ' ORDER BY ' . $this->field . ' ASC';
-    $results = chado_query($sql);
+    $results = chado_query($sql, $arguements);
 
     // Build the select box options
     $max_length = (isset($this->options['max_length'])) ? $this->options['max_length'] : 40;
@@ -118,8 +125,11 @@ class tripal_views_handler_filter_select_string extends views_handler_filter_str
    * @return
    *   An array of full qualified where clauses (ie: table.myfield = 'fred')
    */
-  function get_select_option_where() {
+  function get_select_option_where($table = NULL, $generic_placeholder = TRUE) {
     $where = array();
+    $values = array();
+
+    $table = (is_null($table)) ? $this->table : $table;
 
     // build a where clause that will filter the list in the drop box
     // using fields that are not exposed and that are for the table
@@ -128,32 +138,47 @@ class tripal_views_handler_filter_select_string extends views_handler_filter_str
     // available to the user to edit--they're fixed.
     $where = array();
     $filters = (is_array($this->view->filter)) ? $this->view->filter : array();
+    $placeholder_prefix = 'arg';
+    $i = 0;
     foreach ($filters as $filter_name => $details) {
       // we only want to inclue non-exposed filters
       if ($details->options['exposed'] == FALSE) {
+        $i++;
 
         $value = $details->value;
         if (is_array($details->value) AND isset($details->value['value'])) {
          $value = $details->value['value'];
         }
 
-        if (is_array($value)) {
-          // we only want to filter on the table we're getting the list from
-          if (strcmp($details->table, $this->table)==0 AND !empty($value)) {
-            $where[] = "$details->field IN (" . implode(', ', $value) . ')';
-          }
-
+        // Generate the current placeholder.
+        if ($generic_placeholder) {
+          $placeholder = ':'.$placeholder_prefix.$i;
         }
         else {
-          // we only want to filter on the table we're getting the list from
-          if (strcmp($details->table, $this->table)==0 AND !empty($value)) {
-            $where[] = "$details->field $details->operator " . $value;
+          $placeholder = $details->real_field;
+        }
+
+        // we only want to filter on the table we're getting the list from
+        if (strcmp($details->table, $table)==0 AND !empty($value)) {
+
+          // If the value is an array then use IN instead of the choosen operator.
+          if (is_array($value)) {
+              $where[] = "$details->field IN ($placeholder)";
+              $values[$placeholder] = $value;
+          }
+          // Otherwise, just use the operator choosen by the admin.
+          else {
+            $where[] = "$details->field $details->operator $placeholder";
+            $values[$placeholder] = $value;
           }
         }
       }
     }
 
-    return $where;
+    return array(
+      'where_clauses' => $where,
+      'arguements' => $values
+    );
   }
 
   /**
@@ -172,6 +197,13 @@ class tripal_views_handler_filter_select_string extends views_handler_filter_str
       '#default_value' => $this->options['values_form_type'],
     );
 
+    $form['show_all'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Show All'),
+      '#description' => t('When selected all terms from the controlled vocaulbary used by the table will be shown where the default is to only show those that are used.'),
+      '#default_value' => $this->options['show_all'],
+    );
+
     $form['select_multiple'] = array(
       '#type' => 'checkbox',
       '#title' => t('Select Multiple'),
@@ -212,6 +244,7 @@ class tripal_views_handler_filter_select_string extends views_handler_filter_str
     $this->options['select_multiple'] = $form_state['values']['options']['select_multiple'];
     $this->options['select_optional'] = $form_state['values']['options']['select_optional'];
     $this->options['max_length'] = $form_state['values']['options']['max_length'];
+    $this->options['show_all'] = $form_state['values']['options']['show_all'];
   }
 
   /**
@@ -222,6 +255,7 @@ class tripal_views_handler_filter_select_string extends views_handler_filter_str
     $this->options['select_multiple'] = FALSE;
     $this->options['select_optional'] = FALSE;
     $this->options['max_length'] = 40;
+    $this->options['show_all'] = FALSE;
   }
 
   /**