diff --git a/includes/TripalFields/ncit__raw_data/ncit__raw_data_formatter.inc b/includes/TripalFields/ncit__raw_data/ncit__raw_data_formatter.inc index 5f420de..32ca6ab 100644 --- a/includes/TripalFields/ncit__raw_data/ncit__raw_data_formatter.inc +++ b/includes/TripalFields/ncit__raw_data/ncit__raw_data_formatter.inc @@ -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++; } @@ -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'; diff --git a/includes/rawpheno.download.form.inc b/includes/rawpheno.download.form.inc index b786474..3de7765 100644 --- a/includes/rawpheno.download.form.inc +++ b/includes/rawpheno.download.form.inc @@ -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)))); } } @@ -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( diff --git a/includes/rawpheno.tripaldownload.inc b/includes/rawpheno.tripaldownload.inc index 41b7fb5..1e6184e 100644 --- a/includes/rawpheno.tripaldownload.inc +++ b/includes/rawpheno.tripaldownload.inc @@ -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)); @@ -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, diff --git a/theme/js/rawpheno.germplasm.field.js b/theme/js/rawpheno.germplasm.field.js index 4727617..dedcc47 100644 --- a/theme/js/rawpheno.germplasm.field.js +++ b/theme/js/rawpheno.germplasm.field.js @@ -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);