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 7e57853..a7c71bf 100644 --- a/includes/TripalFields/ncit__raw_data/ncit__raw_data_formatter.inc +++ b/includes/TripalFields/ncit__raw_data/ncit__raw_data_formatter.inc @@ -75,7 +75,7 @@ class ncit__raw_data_formatter extends TripalFieldFormatter { sprintf($img, '', $theme_path . 'icon-download-all.jpg', 'Download all for this trait'), 'Trait', 'Filter by:', - sprintf($img, '', $theme_path . 'icon-download.jpg', 'Download Location + Experiment') + sprintf($img, '', $theme_path . 'icon-download.jpg', 'Download') ); // 2 select fields are required: diff --git a/includes/rawpheno.download.form.inc b/includes/rawpheno.download.form.inc index 3de7765..8ef6748 100644 --- a/includes/rawpheno.download.form.inc +++ b/includes/rawpheno.download.form.inc @@ -28,20 +28,29 @@ function rawpheno_download($form, &$form_state) { if ($vars) { parse_str($vars, $query_vars); - $param_experiment = (int) $query_vars['p']; + $param_experiment = $query_vars['p']; global $user; $user_experiment = rawpheno_function_user_project($user->uid); $user_experiment = array_keys($user_experiment); + $allowed_experiment = array(); - if (in_array($param_experiment, $user_experiment)) { + $experiments = explode('+', $param_experiment); + foreach($experiments as $exp) { + if (in_array($exp, $user_experiment)) { + $allowed_experiment[] = $exp; + } + } + + if (count($allowed_experiment) > 0) { $param_location = $query_vars['l']; + // Expected single value only for trait and germplasm. $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&g=' . $param_stock; + $query_string = 'p=' . implode('+', $allowed_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)))); } } diff --git a/includes/rawpheno.tripaldownload.inc b/includes/rawpheno.tripaldownload.inc index a3b3c33..aa6fa1c 100644 --- a/includes/rawpheno.tripaldownload.inc +++ b/includes/rawpheno.tripaldownload.inc @@ -54,7 +54,7 @@ function rawpheno_trpdownload_summarize_download($vars) { list($project, $location, $traits, $r_version, $envdata, $envfile) = explode('&', $q); $tmp = trim(str_replace('p=', '', $project)); - $project = explode(',', $tmp); + $project = explode('+', $tmp); $sql = "SELECT name FROM {project} WHERE project_id IN (:project)"; $args = array(':project' => $project); @@ -210,11 +210,10 @@ function rawpheno_trpdownload_generate_file($variables, $job_id = NULL) { $q = base64_decode($code); list($project, $location, $traits, $r_version,,,$germplasm) = explode('&', $q); - // Projects: $tmp = trim(str_replace('p=', '', $project)); $project = explode('+', $tmp); - + // Locations: $location = trim(str_replace('l=', '', $location)); @@ -283,11 +282,16 @@ function rawpheno_trpdownload_generate_file($variables, $job_id = NULL) { // Add Name/Stock name column headers array. $header = array('A0' => 'Name'); + // Filter by germplasm. if ($stock_id != '' && (int) $stock_id > 0) { + // Additional filter to limit datapoints to only those that match stock/germplasm. $limit_stock = "AND plant_id IN (SELECT plant_id FROM pheno_plant WHERE stock_id = :stock_id)"; $arr_q_string[':stock_id'] = $stock_id; - // Add experiment to header if request comes from field. + // Experiment name is added to the result as export from multiple + // experiments is supported by the field. + + // Query below is also updated to correspond to this header. $header['E0'] = 'Experiment'; } @@ -344,6 +348,18 @@ function rawpheno_trpdownload_generate_file($variables, $job_id = NULL) { // Sort array by key. ksort($header); + // Filter by germplasm. + $sql_experiment = ''; + if ($stock_id != '' && (int) $stock_id > 0) { + // Include a query to mark datapoints at to which experiment to correspond + // to experiment header. + $sql_experiment = " + SELECT t1.plant_id AS id, 0 AS tid, 'e' AS def, t2.name AS value, 'E' AS grp + FROM {pheno_plant_project} AS t1 + INNER JOIN {chado.project} AS t2 ON t1.project_id = t2.project_id + WHERE plant_id IN" . $sub_sql . "UNION "; + } + // Query to join data from different tables. // Result: plant_id, trait_id, definition, data, and a grouping string // The result is sorted by plant_id and the grouping string ensuring that the first @@ -351,14 +367,7 @@ function rawpheno_trpdownload_generate_file($variables, $job_id = NULL) { // The result will be sorted into standard order: plot,entry,name,rep,location,traits..... // Thus first we select experiment and name. Note that the tid is 0 because this doesn't have a cvterm (ie: not a trait). - $sql = "SELECT t1.plant_id AS id, 0 AS tid, 'e' AS def, t2.name AS value, 'E' AS grp - FROM {pheno_plant_project} AS t1 - INNER JOIN {chado.project} AS t2 ON t1.project_id = t2.project_id - WHERE plant_id IN" . $sub_sql - - // Name - stock or germplasm. - - . "UNION + $sql = "%s SELECT t2.plant_id AS id, '0' AS tid, 'Name' AS def, t1.name AS value, 'A' AS grp FROM {chado.stock} AS t1 INNER JOIN {pheno_plant} AS t2 USING(stock_id) @@ -383,7 +392,8 @@ function rawpheno_trpdownload_generate_file($variables, $job_id = NULL) { // Lastly we order the results by plant_id and grouping string, and tid. . "GROUP BY t1.plant_id, t1.type_id, t2.name ORDER BY id, grp, tid ASC"; - + + $sql = sprintf($sql, $sql_experiment); $results = db_query($sql, $arr_q_string); if ($results) { diff --git a/theme/css/rawpheno.germplasmfield.style.css b/theme/css/rawpheno.germplasmfield.style.css index e75b291..a0491a5 100644 --- a/theme/css/rawpheno.germplasmfield.style.css +++ b/theme/css/rawpheno.germplasmfield.style.css @@ -112,6 +112,7 @@ position: relative; padding: 0; margin: 0; + min-width: 450px; height: 238px; overflow-y: scroll; border: none; diff --git a/theme/js/rawpheno.germplasmfield.script.js b/theme/js/rawpheno.germplasmfield.script.js index e3c9146..975e008 100644 --- a/theme/js/rawpheno.germplasmfield.script.js +++ b/theme/js/rawpheno.germplasmfield.script.js @@ -45,7 +45,7 @@ imgOpacity = '1'; var params = selectValue.split('#'); // Project id & location & trait. - downloadLink = 't=' + params[0] + '&p=' + params[1] + '&l=' + params[2] + '&g=' + params[3]; + downloadLink = $.param({t:params[0], p:params[1], l:params[2], g:Drupal.settings.rawpheno.germ}); } $('#' + selectId + '-img').css('opacity', imgOpacity); @@ -57,7 +57,7 @@ if (imgOpacity == 1) { window.open( - Drupal.settings.rawpheno.exportLink + '?code=' + encodeURIComponent(btoa(downloadLink)), + Drupal.settings.rawpheno.exportLink + '?code=' + btoa(downloadLink), '_blank' ); } @@ -78,7 +78,7 @@ .filter(function(e) { return e['phenotype_customfield_terms:user_experiment'] == 1 }); // Experiments. - var exp = row.map(e => e['phenotype_customfield_terms:id']) + var exp = row.map(e => e['phenotype_customfield_terms:id'].toString()) .filter((value, index, self) => self.indexOf(value) === index); // Locations. @@ -87,10 +87,10 @@ if (exp.length > 0) { // Export all. - var downloadLink = 't=' + i[4] + '&p=' + exp.join('%2B') + '&l=' + loc.join('%2B') + '&g=' + Drupal.settings.rawpheno.germ; + downloadLink = $.param({t:i[4], p:exp.join('+'), l:loc.join('+'), g:Drupal.settings.rawpheno.germ}); window.open( - Drupal.settings.rawpheno.exportLink + '?code=' + encodeURIComponent(btoa(downloadLink)), + Drupal.settings.rawpheno.exportLink + '?code=' + btoa(downloadLink), '_blank' ); } @@ -249,7 +249,7 @@ $.each(value, function(i, v) { var disabled = v['phenotype_customfield_terms:user_experiment'] == 1 ? '' : 'disabled'; element.append($('