Skip to content

Commit

Permalink
Merge pull request #1396 from tripal/1266-tv3-part2_use-pull-1328
Browse files Browse the repository at this point in the history
Use new api function chado_get_organism_id_from_scientific_name
  • Loading branch information
spficklin committed Feb 14, 2023
2 parents 8fd59e9 + 72c70a0 commit 4fbc231
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -421,14 +421,21 @@ class sbo__relationship_widget extends ChadoFieldWidget {
}
// Otherwise we need to look it up using the name field determined in the
// constructor for the current field. There may be more than one name field
// (e.g. organism: genus + species) so we want to check both.
// so we want to check all. Special case for organism where lookup is complicated.
else {
$sql = 'SELECT ' . $fkey_rcolumn . ' FROM {' . $base_table . '} WHERE ' . implode("||' '||", $this->base_name_columns) . '=:keyword';
$subject = chado_query($sql, [':keyword' => $subject_name])->fetchAll();
if (count($subject) == 1) {
$subject_id = $subject[0]->$fkey_rcolumn;
}
else {
// Handle special case of looking up organism by its scientific name.
if ((!$subject_id) and ($base_table == 'organism')) {
$organism_id = chado_get_organism_id_from_scientific_name($subject_name, []);
if (count($organism_id) == 1) {
$subject_id = $organism_id[0];
}
}
if (!$subject_id) {
form_set_error('sbo__relationship][' . $langcode . '][' . $delta . '][subject_name', 'The subject does not exist');
}
}
Expand All @@ -449,14 +456,21 @@ class sbo__relationship_widget extends ChadoFieldWidget {
}
// Otherwise we need to look it up using the name field determined in the
// constructor for the current field. There may be more than one name field
// (e.g. organism: genus + species) so we want to check both.
elseif ($object_name) {
// so we want to check all. Special case for organism where lookup is complicated.
else {
$sql = 'SELECT ' . $fkey_rcolumn . ' FROM {' . $base_table . '} WHERE ' . implode("||' '||", $this->base_name_columns) . '=:keyword';
$object = chado_query($sql, [':keyword' => $object_name])->fetchAll();
if (count($object) == 1) {
$object_id = $object[0]->$fkey_rcolumn;
}
else {
// Handle special case of looking up organism by its scientific name.
if ((!$object_id) and ($base_table == 'organism')) {
$organism_id = chado_get_organism_id_from_scientific_name($object_name, []);
if (count($organism_id) == 1) {
$object_id = $organism_id[0];
}
}
if (!$object_id) {
form_set_error('sbo__relationship][' . $langcode . '][' . $delta . '][object_name', 'The object does not exist');
}
}
Expand Down

0 comments on commit 4fbc231

Please sign in to comment.