Skip to content

Commit

Permalink
Ensured the right stock - genus when inserting a row - Issue #12 Stoc…
Browse files Browse the repository at this point in the history
…k name lookup
  • Loading branch information
reynoldtan committed May 29, 2017
1 parent b20203c commit becd1ab
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion include/rawpheno.upload.excel.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit becd1ab

Please sign in to comment.