Skip to content

Commit

Permalink
Merge pull request #1168 from dsenalik/20210211sbo__relationship
Browse files Browse the repository at this point in the history
20210211sbo  relationship
  • Loading branch information
spficklin committed Mar 8, 2021
2 parents ec877e1 + 6909e0d commit a4f88da
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tripal_chado/api/modules/tripal_chado.pub.api.inc
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function chado_autocomplete_pub($string = '') {
";
$pubs = chado_query($sql, [':str' => $string . '%']);
while ($pub = $pubs->fetchObject()) {
$val = $pub->title . " [id:" . $pub->pub_id . "]";
$val = $pub->title . " [id: " . $pub->pub_id . "]";
$items[$val] = $pub->title;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,20 @@ class sbo__relationship extends ChadoField {
case 'quantification_relationship':
case 'element_relationship':
case 'project_relationship':
$this->base_name_columns = ['name'];
$this->base_type_column = 'table_name';
break;

case 'pub_relationship':
$this->base_name_columns = ['title'];
$this->base_type_column = 'table_name';
$this->base_name_columns = ['name'];
break;
break;

case 'organism_relationship':
$this->base_name_columns = ['genus', 'species'];
$this->base_type_column = 'table_name';
break;

case 'phylonode_relationship':
$this->base_name_columns = ['label'];
$this->base_type_column = 'table_name';
Expand All @@ -266,6 +271,7 @@ class sbo__relationship extends ChadoField {
$this->base_name_columns = ['name'];
$this->base_type_column = 'type_id';
break;

default:
// @todo update this to use the schema.
$this->base_name_columns = ['name'];
Expand Down Expand Up @@ -419,6 +425,13 @@ class sbo__relationship extends ChadoField {
// @todo grab these separately like it was before.
$subject_pkey = $object_pkey = $this->base_schema['primary key'][0];

// A publication title can exceed the character limit for chado_expand_var()
// so make sure it has been added.
// TODO Should this step be generalized to other content type that could have a long name?
if (in_array('pub.title', $relationship->expandable_fields)) {
$relationship = chado_expand_var($relationship, 'field', 'pub.title', []);
}

$entity->{$field_name}['und'][$delta]['value'] = [
'local:relationship_subject' => $this->getRelationshipSubject($relationship),
'local:relationship_type' => $relationship->type_id->name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class schema__publication_widget extends ChadoFieldWidget {
$pub_id = tripal_get_field_item_keyval($items, $delta, $pub_item_id, $pub_id);
if ($pub_id) {
$pub = chado_get_publication(['pub_id' => $pub_id]);
$title = $pub->title . ' [id:' . $pub->pub_id . ']';
$title = $pub->title . ' [id: ' . $pub->pub_id . ']';
}
}

Expand Down Expand Up @@ -122,7 +122,7 @@ class schema__publication_widget extends ChadoFieldWidget {
$title = $form_state['values'][$field_name]['und'][$delta]['pub_title'];
if ($title) {
$matches = [];
if (preg_match('/^.*\[id:(\d+)]$/', $title, $matches)) {
if (preg_match('/^.*\[id: (\d+)]$/', $title, $matches)) {
$pub_id = $matches[1];
$pub = chado_generate_var('pub', ['pub_id' => $pub_id]);
$form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__pub_id'] = $pub->pub_id;
Expand Down

0 comments on commit a4f88da

Please sign in to comment.