|
@@ -438,7 +438,6 @@ function tripal_chado_field_storage_query($query) {
|
|
|
$cquery = chado_db_select($data_table, 'base');
|
|
|
$cquery->fields('base', array($pkey));
|
|
|
|
|
|
-
|
|
|
// Iterate through all the conditions and add to the filters array
|
|
|
// a chado_select_record compatible set of filters.
|
|
|
foreach ($query->fieldConditions as $index => $condition) {
|
|
@@ -490,8 +489,9 @@ function tripal_chado_field_storage_query($query) {
|
|
|
$cquery->condition('base.' . $base_field , $condition['value'], $condition['operator']);
|
|
|
}
|
|
|
if ($chado_table != $base_table) {
|
|
|
- // TODO: I don't think we'll get here but just in case here's a
|
|
|
- // note to handle it.
|
|
|
+ // TODO: I don't think we'll get here because linker fields will
|
|
|
+ // always have a custom field that should implement a query()
|
|
|
+ // function. But just in case here's a note to handle it.
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -576,6 +576,9 @@ function tripal_chado_field_storage_query($query) {
|
|
|
} // end if ($sort['type'] == 'field') {
|
|
|
} // end foreach ($query->order as $index => $sort) {
|
|
|
|
|
|
+ //print_r($cquery->__toString());
|
|
|
+ //print_r($cquery->getArguments());
|
|
|
+
|
|
|
$records = $cquery->execute();
|
|
|
|
|
|
$result = array();
|
|
@@ -585,138 +588,3 @@ function tripal_chado_field_storage_query($query) {
|
|
|
}
|
|
|
return $result;
|
|
|
}
|
|
|
-
|
|
|
-/**
|
|
|
- * @return
|
|
|
- * An array containing the chado_select_record() compatible array.
|
|
|
- */
|
|
|
-function tripal_chado_field_storage_query_build_sql(&$sql, $prev_table, $prev_column, $prev_term, $chado_table, $query_terms, $condition, $value, $depth = 0) {
|
|
|
-
|
|
|
- // Get schema information for the previous (linker) Chado table.
|
|
|
- $pschema = chado_get_schema($prev_table);
|
|
|
- $ppkey = $pschema['primary key'][0];
|
|
|
- $pfkeys = $pschema['foreign keys'];
|
|
|
-
|
|
|
- // Get schema information for the current Chado table.
|
|
|
- $schema = chado_get_schema($chado_table);
|
|
|
- $pkey = $schema['primary key'][0];
|
|
|
- $fkeys = $schema['foreign keys'];
|
|
|
-
|
|
|
- // Get the first query term from the list and find out what column this
|
|
|
- // term maps to in the Chado table.
|
|
|
- $term = array_shift($query_terms);
|
|
|
- $chado_column = tripal_get_chado_semweb_column($chado_table, $term);
|
|
|
- if (!$chado_column) {
|
|
|
- // TODO: we could get to this point because a field has a value that
|
|
|
- // doesn't map to a database column but is a manually created
|
|
|
- // element. How do we deal with those?
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
-
|
|
|
- // reformat that term so it's compatible with SQL
|
|
|
- $term = preg_replace('/[^\w]/', '_', $term);
|
|
|
-
|
|
|
- // A query can be an array of column names separated by a period. We
|
|
|
- // want to split them apart and just deal with the column at the head
|
|
|
- // of the array. But before dealing with that head, we will recurse so that
|
|
|
- // we build our filters array from the bottom up.
|
|
|
- if (count($query_terms) > 0) {
|
|
|
- // Since the $query_terms is not a single element that implies this
|
|
|
- // query term represents a foreign key.
|
|
|
- // We don't know which direction the foreign key is going, so we'll have
|
|
|
- // to check both the previous and current tables to build the join
|
|
|
- // statement correctly.
|
|
|
- if (array_key_exists($prev_table, $fkeys) and
|
|
|
- array_key_exists($chado_column, $fkeys[$prev_table]['columns'])) {
|
|
|
- $fkey = $fkeys[$prev_table]['columns'][$chado_column];
|
|
|
- $sql['join'][] = 'INNER JOIN {' . $chado_table . '} ' . $term . ' ON ' . $prev_term . '.' . $fkey . ' = ' . $term . '.' . $chado_column;
|
|
|
- }
|
|
|
- else {
|
|
|
- $sql['join'][] = 'INNER JOIN {' . $chado_table . '} ' . $term . ' ON ' . $prev_term . '.' . $prev_column . ' = ' . $term . '.' . $chado_column;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // Get the table that this foreign key links to.
|
|
|
- $next_table = '';
|
|
|
- foreach ($fkeys as $fktable_name => $fk_details) {
|
|
|
- foreach ($fk_details['columns'] as $lfkey => $rfkey) {
|
|
|
- if ($lfkey == $chado_column) {
|
|
|
- $next_table = $fktable_name;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if ($next_table) {
|
|
|
- tripal_chado_field_storage_query_build_sql($sql, $chado_table, $chado_column, $term, $next_table, $query_terms, $condition, $value, $depth++);
|
|
|
- }
|
|
|
- else {
|
|
|
- // TODO: we could get to this point because a field has a value that
|
|
|
- // doesn't map to a database column but is a manually created
|
|
|
- // element. How do we deal with those?
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
- return FALSE;
|
|
|
- }
|
|
|
-
|
|
|
- // We don't know which direction the foreign key is going, so we'll have
|
|
|
- // to check both the previous and current tables to build the join
|
|
|
- // statement correctly.
|
|
|
- if (array_key_exists($prev_table, $fkeys) and
|
|
|
- array_key_exists($chado_column, $fkeys[$prev_table]['columns'])) {
|
|
|
- $fkey = $fkeys[$prev_table]['columns'][$chado_column];
|
|
|
- $sql['join'][] = 'INNER JOIN {' . $chado_table . '} ' . $term . ' ON ' . $prev_term . '.' . $fkey . ' = ' . $term . '.' . $chado_column;
|
|
|
- }
|
|
|
- else {
|
|
|
- $sql['join'][] = 'INNER JOIN {' . $chado_table . '} ' . $term . ' ON ' . $prev_term . '.' . $prev_column . ' = ' . $term . '.' . $chado_column;
|
|
|
- }
|
|
|
-
|
|
|
- // Use the appropriate operator.
|
|
|
- $operator = $condition['operator'] ? $condition['operator'] : '=';
|
|
|
- switch ($operator) {
|
|
|
- case '=':
|
|
|
- $sql['where'][] = "$term.$chado_column = :value";
|
|
|
- $sql['args'][':value'] = $value;
|
|
|
- break;
|
|
|
- case '>':
|
|
|
- case '>=':
|
|
|
- case '<':
|
|
|
- case '<=':
|
|
|
- $sql['where'][] = "$term.$chado_column $op :value";
|
|
|
- $sql['args'][':value'] = $value;
|
|
|
- break;
|
|
|
- case '<>':
|
|
|
- $sql['where'][] = "$term.$chado_column $op :value";
|
|
|
- $sql['args'][':value'] = $value;
|
|
|
- break;
|
|
|
- case 'CONTAINS':
|
|
|
- $sql['where'][] = "$term.$chado_column LIKE :value";
|
|
|
- $sql['args'][':value'] = '%' . $value . '%';
|
|
|
- break;
|
|
|
- case 'NOT':
|
|
|
- $subfilters[$chado_column] = array(
|
|
|
- 'op' => 'NOT LIKE',
|
|
|
- 'data' => '%' . $value . '%',
|
|
|
- );
|
|
|
- $sql['where'][] = "$term.$chado_column NOT LIKE :value";
|
|
|
- $sql['args'][':value'] = '%' . $value . '%';
|
|
|
- break;
|
|
|
- case 'STARTS WITH':
|
|
|
- $sql['where'][] = "$term.$chado_column LIKE :value";
|
|
|
- $sql['args'][':value'] = $value . '%';
|
|
|
- break;
|
|
|
- case 'NOT STARTS':
|
|
|
- $sql['where'][] = "$term.$chado_column NOT LIKE :value";
|
|
|
- $sql['args'][':value'] = $value . '%';
|
|
|
- break;
|
|
|
- case 'ENDS WITH':
|
|
|
- $sql['where'][] = "$term.$chado_column LIKE :value";
|
|
|
- $sql['args'][':value'] = '%' . $value;
|
|
|
- break;
|
|
|
- case 'NOT ENDS':
|
|
|
- $sql['where'][] = "$term.$chado_column NOT LIKE :value";
|
|
|
- $sql['args'][':value'] = '%' . $value;
|
|
|
- break;
|
|
|
- default:
|
|
|
- // unrecognized operation.
|
|
|
- break;
|
|
|
- }
|
|
|
-}
|