Skip to content

Commit

Permalink
Filters resultset to match stock id
Browse files Browse the repository at this point in the history
  • Loading branch information
reynoldtan committed Dec 23, 2021
1 parent 5541a67 commit 158c27e
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions includes/rawpheno.tripaldownload.inc
Original file line number Diff line number Diff line change
Expand Up @@ -263,21 +263,24 @@ function rawpheno_trpdownload_generate_file($variables, $job_id = NULL) {

// Germplasm/Stock id - request from germplasm field.
$stock_id = trim(str_replace('g=', '', $germplasm));
$stock_name = '';
if ($stock_id != '' && $stock_id > 0) {
$stock_name = chado_query("SELECT name FROM {stock} WHERE stock_id = :stock_id", array(':stock_id' => $stock_id))
->fetchField();
}
$limit_stock = '';

// Sub-query to select plant_id given a location and project.
// NOTE: leading and trailing spaces are required.
$sub_sql = " (SELECT plant_id
FROM {pheno_plantprop} INNER JOIN {pheno_plant_project} USING(plant_id)
WHERE value IN (:location) AND project_id IN (:project)) ";
WHERE value IN (:location) AND project_id IN (:project) %s) ";

// Query values required by sub query.
$arr_q_string = array(':project' => $project, ':location' => $location, ':traits' => $traits);

if ($stock_id != '' && (int) $stock_id > 0) {
$limit_stock = "AND plant_id IN (SELECT plant_id FROM pheno_plant WHERE stock_id = :stock_id)";
$arr_q_string[':stock_id'] = $stock_id;
}

$sub_sql = sprintf($sub_sql, $limit_stock);

// First we need to get the header. This will allow us to ensure that the data
// downloaded all matches up with the trait it is associated with. Furthermore,
// it will allow us to handle missing data.
Expand Down Expand Up @@ -370,12 +373,7 @@ function rawpheno_trpdownload_generate_file($variables, $job_id = NULL) {
// Note: this first array will not have any missing data cells filled in.
$rows = array();
foreach($results as $r) {
if ($stock_name != '' && $r->value == $stock_name) {
$rows[ $r->id ][ $r->grp . $r->tid ] = $r->value;
}
else {
$rows[ $r->id ][ $r->grp . $r->tid ] = $r->value;
}
$rows[ $r->id ][ $r->grp . $r->tid ] = $r->value;
}

// Total lines;
Expand Down

0 comments on commit 158c27e

Please sign in to comment.