Skip to content

Commit

Permalink
Merge pull request #1535 from reynoldtan/tv4g2-issue1534-chadoCvtermA…
Browse files Browse the repository at this point in the history
…utocompleteUpdate

Tv4g2 issue1534 chado cvterm autocomplete update
  • Loading branch information
laceysanderson committed Jun 2, 2023
2 parents a07fea6 + b9a93dd commit 73c091e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tripal_chado/src/Controller/ChadoCVTermAutocompleteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,38 @@ public static function getCVtermId(string $term): int {

return $id;
}

/**
* Given a cvterm id number, return the matching cvterm record using
* the format cvterm name (db.name:dbxref.accession).
*
* @param integer $id
* Cvterm id number to match.
*
* @return string
* Cvterm record in cvterm name (db.name:dbxref.accession) format.
*/
public static function formatCVterm(int $id) {
$term = null;

if ($id > 0) {
$sql = "
SELECT CONCAT(ct.name, ' (', db.name, ':', dx.accession, ')')
FROM {1:cvterm} AS ct
LEFT JOIN {1:dbxref} AS dx USING(dbxref_id)
LEFT JOIN {1:db} USING(db_id)
WHERE ct.cvterm_id = :cvterm_id
LIMIT 1
";

$connection = \Drupal::service('tripal_chado.database');
$result = $connection->query($sql, [':cvterm_id' => $id]);

if($result) {
$term = $result->fetchField();
}
}

return $term;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,18 @@ public function testAutocompleteCvterm() {
$id = $autocomplete->getCVtermId($i);
$this->assertEquals($id, 0);
}


// Test format CVterm method.
foreach(json_decode($suggest) as $item) {
// ChadoCVTermAutocompleteController::getCVtermId()
$id = $autocomplete->getCVtermId($item->value);
// Reverse value - get formatted term.
$term = $autocomplete->formatCVterm($id);

$this->assertNotNull($term);
$this->assertIsString($term);
$this->assertEquals($term, $item->value);
}
}
}

0 comments on commit 73c091e

Please sign in to comment.