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 22, 2021
1 parent d5f9ff4 commit fe6bc13
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class ncit__raw_data_formatter extends TripalFieldFormatter {
foreach($germplasm_raw_phenotypes['traits'] as $trait => $exp_loc) {
list($trait_id, $trait_name) = explode('_', $trait);

$select = $this->create_select($exp_loc, $germplasm_raw_phenotypes['user']['experiments']);
$select = $this->create_select($germplasm_raw_phenotypes['germplasm']['id'], $exp_loc, $germplasm_raw_phenotypes['user']['experiments']);
$table_row[ $id ] = array(sprintf($icon_img, '', $germplasm_raw_phenotypes['icons']['leaf']) . ucfirst($trait_name), $select, sprintf($icon_img, $trait_id, $germplasm_raw_phenotypes['icons']['export']));
$id++;
}
Expand Down Expand Up @@ -126,20 +126,20 @@ class ncit__raw_data_formatter extends TripalFieldFormatter {
/**
* Create select field.
*
* @param $id
* Id attribute of the final select field.
* @param $germplasm
* Stock id number.
* @param $items
* Associative array, where each item will be rendered as an option
* with key as the value and value as text.
* @param $disable
* Array of items to match an item if it should be disabled.
*/
public function create_select($items, $disable) {
public function create_select($germplasm, $items, $disable) {
$option = array();
$cache_exp = [];
foreach($items as $loc_exp) {
list($trait_id, $project_id, $project_name, $location) = explode('#', $loc_exp);
$select_value = $trait_id . '#' . $project_id . '#' . $location;
$select_value = $trait_id . '#' . $project_id . '#' . $location . '#' . $germplasm;
$cache_exp[] = $project_id;

$disabled = (in_array($project_id, $disable)) ? '' : 'disabled';
Expand Down
5 changes: 3 additions & 2 deletions includes/rawpheno.download.form.inc
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ function rawpheno_download($form, &$form_state) {
if (in_array($param_experiment, $user_experiment)) {
$param_location = $query_vars['l'];
$param_trait = (int) $query_vars['t'];
$param_stock = (int) $query_vars['g'];

if ($param_experiment > 0 && $param_location && $param_trait > 0) {
// Create query string.
$query_string = 'p=' . $param_experiment . '&l=' . $param_location . '&t=' . $param_trait . '&r=0&e=0&file=0';
$query_string = 'p=' . $param_experiment . '&l=' . $param_location . '&t=' . $param_trait . '&r=0&e=0&file=0&g=' . $param_stock;
drupal_goto('/phenotypes/raw/csv', array('query' => array('code' => base64_encode($query_string))));
}
}
Expand Down Expand Up @@ -390,7 +391,7 @@ function rawpheno_download_submit($form, &$form_state) {

// Contain all query parameters/string into one string.
// Decode first when reading this string using base64_decode() function.
$url = 'p=' . $prj . '&l=' . $loc . '&t=' . $trt . '&r=' . $rvr . '&e=' . $env . '&file=' . $env_filename;
$url = 'p=' . $prj . '&l=' . $loc . '&t=' . $trt . '&r=' . $rvr . '&e=' . $env . '&file=' . $env_filename . '&g=0';

// Format url for redirect.
$form_state['redirect'] = array(
Expand Down
28 changes: 22 additions & 6 deletions includes/rawpheno.tripaldownload.inc
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function rawpheno_trpdownload_generate_file($variables, $job_id = NULL) {
}

$q = base64_decode($code);
list($project, $location, $traits, $r_version,,) = explode('&', $q);
list($project, $location, $traits, $r_version,,,$germplasm) = explode('&', $q);

// Projects:
$tmp = trim(str_replace('p=', '', $project));
Expand Down Expand Up @@ -261,14 +261,30 @@ function rawpheno_trpdownload_generate_file($variables, $job_id = NULL) {
}
}

// Sub-query to select plant_id given a location and project.
// NOTE: leading and trailing spaces are required.
$sub_sql = " (SELECT plant_id
// Germplasm/Stock id - request from germplasm field.
$germplasm = trim(str_replace('g=', '', $germplasm));

if ($germplasm != '' && $gemplasm > 0) {
// Sub-query to select plant_id given a location and project and germplasm.
// 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))
AND plant_id IN (SELECT plant_id FROM pheno_plant WHERE stock_id = :stock_id) ";

// Query values required by sub query.
$arr_q_string = array(':project' => $project, ':location' => $location, ':traits' => $traits, ':stock_id' => $germplasm);
}
else {
// 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)) ";

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

// 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,
Expand Down
2 changes: 1 addition & 1 deletion theme/js/rawpheno.germplasm.field.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
imgOpacity = '1';
var params = selectValue.split('#');
// Project id & location & trait.
downloadLink = 'p=' + params[1] + '&l=' + params[2] + '&t=' + params[0];
downloadLink = 't=' + params[0] + '&p=' + params[1] + '&l=' + params[2] + '&g=' + params[3];
}

$('#' + selectId + '-img').css('opacity', imgOpacity);
Expand Down

0 comments on commit fe6bc13

Please sign in to comment.