|
@@ -45,7 +45,6 @@ class tripal_views_handler_filter_select_cvterm extends tripal_views_handler_fil
|
|
|
.' 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) {
|
|
@@ -62,51 +61,12 @@ class tripal_views_handler_filter_select_cvterm extends tripal_views_handler_fil
|
|
|
}
|
|
|
else {
|
|
|
|
|
|
+ $where_clauses = $this->get_select_option_where();
|
|
|
$where = '';
|
|
|
- if ($this->options['exposed']) {
|
|
|
- // 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
|
|
|
- // we only want to use non-exposed fields because these are not
|
|
|
- // available to the user to edit--they're fixed.
|
|
|
- $filters = (is_array($this->view->filter)) ? $this->view->filter : array();
|
|
|
- foreach ($filters as $filter_name => $details) {
|
|
|
- // we only want to inclue non-exposed filters
|
|
|
- if ($details->options['exposed'] == FALSE) {
|
|
|
- $value = $details->value;
|
|
|
- if (is_array($details->value) AND isset($details->value['value'])) {
|
|
|
- $value = $details->value['value'];
|
|
|
- }
|
|
|
-
|
|
|
- $field = $details->field;
|
|
|
- if (($this->table == $this->view->base_table) AND ($details->field == 'type_id')) {
|
|
|
- $field = 'cvterm_id';
|
|
|
- }
|
|
|
-
|
|
|
- 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 .= "$field IN (" . implode(', ', $value) . ')';
|
|
|
- $where .= ' AND ';
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- // we only want to filter on the table we're getting the list from
|
|
|
- if (strcmp($details->table, 'cvterm')==0 AND !empty($value)) {
|
|
|
- $where .= "$field $details->operator " . $value;
|
|
|
- $where .= ' AND ';
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if ($where) {
|
|
|
- $where = ' AND ' . $where;
|
|
|
- $where = substr($where, 0, -5); # remove the final ' AND '
|
|
|
- }
|
|
|
+ if (!empty($where_clauses)) {
|
|
|
+ $where = ' AND ' . implode(' AND ', $where_clauses);
|
|
|
}
|
|
|
|
|
|
- // @coder-ignore: non-drupal schema therefore table prefixing does not apply
|
|
|
- // D7 TODO: Check DBTNG changes work
|
|
|
$sql = "SELECT cvterm_id, name FROM {cvterm} WHERE cvterm_id IN (SELECT distinct(" . $this->field . ") FROM {" . $this->table . "}) " . $where . ' ORDER BY cvterm.name ASC';
|
|
|
$resource = chado_query($sql);
|
|
|
$cvterms = array();
|
|
@@ -126,6 +86,52 @@ class tripal_views_handler_filter_select_cvterm extends tripal_views_handler_fil
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * For the SQL generating the options, determine the WHERE clauses
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ * An array of full qualified where clauses (ie: table.myfield = 'fred')
|
|
|
+ */
|
|
|
+ function get_select_option_where() {
|
|
|
+ $where = array();
|
|
|
+
|
|
|
+ // 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
|
|
|
+ // we only want to use non-exposed fields because these are not
|
|
|
+ // available to the user to edit--they're fixed.
|
|
|
+ $filters = (is_array($this->view->filter)) ? $this->view->filter : array();
|
|
|
+ foreach ($filters as $filter_name => $details) {
|
|
|
+ // we only want to inclue non-exposed filters
|
|
|
+ if ($details->options['exposed'] == FALSE) {
|
|
|
+ $value = $details->value;
|
|
|
+ if (is_array($details->value) AND isset($details->value['value'])) {
|
|
|
+ $value = $details->value['value'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $field = $details->field;
|
|
|
+ if (($this->table == $this->view->base_table) AND ($details->field == 'type_id')) {
|
|
|
+ $field = 'cvterm_id';
|
|
|
+ }
|
|
|
+
|
|
|
+ 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[] = "$field IN (" . implode(', ', $value) . ')';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // we only want to filter on the table we're getting the list from
|
|
|
+ if (strcmp($details->table, 'cvterm')==0 AND !empty($value)) {
|
|
|
+ $where[] = "$field $details->operator " . $value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $where;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* {@inheritdoc}
|
|
|
*/
|