Skip to content

Commit

Permalink
Merge pull request #1257 from dsenalik/1138-tv3-sbo__database_cross_r…
Browse files Browse the repository at this point in the history
…eference

Issue #1138 repair damage to sbo__database_cross_reference widget
  • Loading branch information
spficklin committed Mar 14, 2022
2 parents 064de3c + eb40e7e commit d3123a7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class sbo__database_cross_reference extends ChadoField {
// The number of items to show on a page.
'items_per_page' => 10,
// Limit to the number of items to show in cases of large number of cross references.
'max_items' => 10000,
'max_items' => 1000,
];

// The default widget for this field.
Expand Down Expand Up @@ -129,6 +129,7 @@ class sbo__database_cross_reference extends ChadoField {
$schema = chado_get_schema($field_table);
$pkey = $schema['primary key'][0];
$fkey_lcolumn = key($schema['foreign keys'][$base_table]['columns']);
$fkey_lcolumn_id = $entity->{'chado_record_id'};
$fkey_rcolumn = $schema['foreign keys'][$base_table]['columns'][$fkey_lcolumn];

$dbname_term = chado_get_semweb_term('db', 'name');
Expand All @@ -143,9 +144,10 @@ class sbo__database_cross_reference extends ChadoField {
$linker_table = $base_table . '_dbxref';
$options = ['return_array' => 1];

// Build the SQL to find records associated with this publication.
$max_items = array_key_exists('max_items', $this->instance['settings']) ? $this->instance['settings']['max_items'] : 10000;
$sql = "SELECT REF.accession, DB.name, DB.urlprefix "
// Build the SQL to find records associated with this entity.
// Note that there is no rank column in the xxx_dbxref tables, so the order part of the widget will not be functional
$max_items = array_key_exists('max_items', $this->instance['settings']) ? $this->instance['settings']['max_items'] : 1000;
$sql = "SELECT LINK.".$linker_table."_id AS pkey_id, REF.dbxref_id, REF.accession, DB.db_id, DB.name, DB.urlprefix "
. "FROM {".$linker_table."} LINK "
. "INNER JOIN {dbxref} REF on LINK.dbxref_id = REF.dbxref_id "
. "INNER JOIN {db} DB on REF.db_id = DB.db_id "
Expand All @@ -155,7 +157,7 @@ class sbo__database_cross_reference extends ChadoField {
. "AND NOT DB.name = 'GFF_source' "
. "ORDER BY REF.accession " // if we hit the limit, the subset should be consistent
. "LIMIT :limit";
$args = [':id' => $entity->{'chado_record_id'},
$args = [':id' => $fkey_lcolumn_id,
':limit' => $max_items + 1];
$records = chado_query($sql, $args);

Expand All @@ -164,10 +166,18 @@ class sbo__database_cross_reference extends ChadoField {
while($record = $records->fetchObject()) {
// Need this check to detect the case where the limit exactly equals the number of records
if ($delta < $max_items) {
$entity->{$field_name}['und'][$delta] = [];
$entity->{$field_name}['und'][$delta]['value'][$dbname_term] = $record->name;
$entity->{$field_name}['und'][$delta]['value'][$accession_term] = $record->accession;
$entity->{$field_name}['und'][$delta]['value'][$dburl_term] = $record->urlprefix;
$entity->{$field_name}['und'][$delta] = [
'value' => [
$dbname_term => $record->name,
$accession_term => $record->accession,
$dburl_term => $record->urlprefix,
],
'chado-' . $field_table . '__' . $pkey => $record->pkey_id,
'chado-' . $field_table . '__' . $fkey_lcolumn => $fkey_lcolumn_id,
'chado-' . $field_table . '__dbxref_id' => $record->dbxref_id,
'db_id' => $record->db_id,
'accession' => $record->accession,
];
}
$delta++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class sbo__database_cross_reference_widget extends ChadoFieldWidget {
// The list of field types for which this formatter is appropriate.
public static $field_types = ['sbo__database_cross_reference'];

// The widget may either display ORDER for setting row weights, or allow rearranging, but
// the various xxx_dbxref tables do not have rank columns, so this part is non-functional.
// We may be able to disable rearranging in a later version of Drupal, but not 7.x

/**
*
* @see TripalFieldWidget::form()
Expand Down

0 comments on commit d3123a7

Please sign in to comment.