From becd1ab20909849229b4f13759f9dfa370f08a8d Mon Sep 17 00:00:00 2001 From: Reynold Tan Date: Mon, 29 May 2017 10:25:33 -0600 Subject: [PATCH] Ensured the right stock - genus when inserting a row - Issue #12 Stock name lookup --- include/rawpheno.upload.excel.inc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/include/rawpheno.upload.excel.inc b/include/rawpheno.upload.excel.inc index 1217d42..db63de0 100755 --- a/include/rawpheno.upload.excel.inc +++ b/include/rawpheno.upload.excel.inc @@ -82,6 +82,10 @@ function rawpheno_load_spreadsheet($project_id, $arr_newheaders, $fid, $plantpro // print "\nNow parsing each row and saving it to the database...\nNumber of rows saved: \n"; $i = 0; + // Limit the stocks for comparison/validation to just the organism that matched the project genus. + $project_prop = rawpheno_function_project_organism($project_id, 'full'); + $project_genus_organism_ids = array_keys($project_prop['organism']); + // Each row in the spreadsheet. foreach ($xls_obj as $row) { // Create progress update by computing the number of rows saved in percent. @@ -131,8 +135,15 @@ function rawpheno_load_spreadsheet($project_id, $arr_newheaders, $fid, $plantpro // Process the name column first since we need a plant_id before we can insert any more data. // Name column header goes into pheno_plant. // Check if stock name exists. + + // Limit the name search to just stocks in project organism. $stock_id = NULL; - $r = chado_query('SELECT stock_id FROM {stock} WHERE name=:name', array(':name' => trim($row[$name_index]))); + + // Limit the stocks for comparison/validation to just the organism defined in the project. + $sql = "SELECT stock_id FROM {stock} WHERE name = :name AND organism_id IN (:project_organism_ids)"; + $args = array(':name' => trim($row[$name_index]), ':project_organism_ids' => $project_genus_organism_ids); + + $r = chado_query($sql, $args); if ($r) $stock_id = $r->fetchField(); // Determine if name has a stock id number.