Prechádzať zdrojové kódy

Fixed more remaining uniquename assumptions.

Lacey Sanderson 6 rokov pred
rodič
commit
d251c1942e

+ 23 - 14
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship.inc

@@ -72,7 +72,7 @@ class sbo__relationship extends ChadoField {
   protected $instance;
 
   // An array of columns to use as the "name" of the subject and object.
-  // For example, for the feature table, this will be the uniquename,
+  // For example, for the feature table, this will be the name,
   // whereas, for the organism table this will be the genus & species.
   protected $base_name_columns;
 
@@ -260,12 +260,16 @@ class sbo__relationship extends ChadoField {
         $this->base_type_column = 'table_name';
         break;
       case 'pub_relationship':
-        $this->base_name_columns = ['uniquename'];
+        $this->base_name_columns = ['name'];
         $this->base_type_column = 'table_name';
         break;
+      case 'contact':
+        $this->base_name_columns = ['name'];
+        $this->base_type_column = 'type_id';
+        break;
       default:
         // @todo update this to use the schema.
-        $this->base_name_columns = ['uniquename'];
+        $this->base_name_columns = ['name'];
         $this->base_type_column = 'type_id';
     }
   }
@@ -280,6 +284,7 @@ class sbo__relationship extends ChadoField {
       $name[] = $relationship->{$this->subject_id_column}->{$column};
     }
 
+    // Retrieve the type.
     $type = $this->instance['settings']['base_table'];
     if ((!$this->base_type_column == 'table_name') AND isset($relationship->{$this->subject_id_column}->{$this->base_type_column})) {
       $type_object = $relationship->{$this->subject_id_column}->{$this->base_type_column};
@@ -298,7 +303,7 @@ class sbo__relationship extends ChadoField {
       //'entity' => 'TripalEntity:' . $entity->id,
     ];
 
-    // If the object has a unqiuename then add that in for refernce.
+    // If the object has a uniquename then add that in for refernce.
     if (property_exists($relationship->{$this->subject_id_column}, 'uniquename')) {
       $record['data:0842'] = $relationship->{$this->subject_id_column}->uniquename;
     }
@@ -324,10 +329,12 @@ class sbo__relationship extends ChadoField {
   private function getRelationshipObject($relationship) {
     $name = [];
 
+    // Retrieve the name (may be multiple parts).
     foreach ($this->base_name_columns as $column) {
       $name[] = $relationship->{$this->object_id_column}->{$column};
     }
 
+    // Retrieve the Type.
     $type = $this->instance['settings']['base_table'];
     if ((!$this->base_type_column == 'table_name') AND isset($relationship->{$this->object_id_column}->{$this->base_type_column})) {
       $type_object = $relationship->{$this->object_id_column}->{$this->base_type_column};
@@ -563,16 +570,18 @@ class sbo__relationship extends ChadoField {
     }
 
     // Filter by unique name of the subject or object.
-    /* @uniquename there is not always a uniquename! */
-    if ($condition['column'] == $rel_subject_identifier) {
-      $this->queryJoinOnce($query, $chado_table, $alias, "base.$bpkey = $alias.object_id");
-      $this->queryJoinOnce($query, $base_table, 'base2', "base2.$bpkey = $alias.subject_id");
-      $query->condition("base2.uniquename", $condition['value'], $operator);
-    }
-    if ($condition['column'] == $rel_object_identifier) {
-      $this->queryJoinOnce($query, $chado_table, $alias, "base.$bpkey = $alias.subject_id");
-      $this->queryJoinOnce($query, $base_table, 'base2', "base2.$bpkey = $alias.object_id");
-      $query->condition("base2.uniquename", $condition['value'], $operator);
+    // If this table has a uniquename!
+    if (isset($this->schema['fields']['uniquename'])) {
+      if ($condition['column'] == $rel_subject_identifier) {
+        $this->queryJoinOnce($query, $chado_table, $alias, "base.$bpkey = $alias.object_id");
+        $this->queryJoinOnce($query, $base_table, 'base2', "base2.$bpkey = $alias.subject_id");
+        $query->condition("base2.uniquename", $condition['value'], $operator);
+      }
+      if ($condition['column'] == $rel_object_identifier) {
+        $this->queryJoinOnce($query, $chado_table, $alias, "base.$bpkey = $alias.subject_id");
+        $this->queryJoinOnce($query, $base_table, 'base2', "base2.$bpkey = $alias.object_id");
+        $query->condition("base2.uniquename", $condition['value'], $operator);
+      }
     }
 
     // Filter by the type of the subject or object

+ 9 - 9
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship_widget.inc

@@ -25,7 +25,7 @@ class sbo__relationship_widget extends ChadoFieldWidget {
   protected $object_id_column;
 
   // An array of columns to use as the "name" of the subject and object.
-  // For example, for the feature table, this will be the uniquename,
+  // For example, for the feature table, this will be the name,
   // whereas, for the organism table this will be the genus & species.
   protected $base_name_columns;
 
@@ -95,8 +95,8 @@ class sbo__relationship_widget extends ChadoFieldWidget {
     $type_id = '';
     $value = '';
     $rank = '';
-    $subject_uniquename = '';
-    $object_uniquename = '';
+    $subject_label = '';
+    $object_label = '';
     $type = '';
 
     // If the field already has a value then it will come through the $items
@@ -124,8 +124,8 @@ class sbo__relationship_widget extends ChadoFieldWidget {
         }
 
         // Get element values added to help support insert/updates.
-        $object_uniquename = tripal_get_field_item_keyval($items, $delta, 'object_name', $object_uniquename);
-        $subject_uniquename = tripal_get_field_item_keyval($items, $delta, 'subject_name', $subject_uniquename);
+        $object_label = tripal_get_field_item_keyval($items, $delta, 'object_name', $object_label);
+        $subject_label = tripal_get_field_item_keyval($items, $delta, 'subject_name', $subject_label);
         $type = tripal_get_field_item_keyval($items, $delta, 'type_name', $type);
 
         //@debug dpm(array($subject_id, $type_id, $object_id), 'have an item!');
@@ -145,8 +145,8 @@ class sbo__relationship_widget extends ChadoFieldWidget {
       if (array_key_exists('rank', $this->schema['fields'])) {
         $rank = $form_state['values'][$field_name]['und'][$delta]['chado-' . $field_table . '__rank'];
       }
-      $object_uniquename = $form_state['values'][$field_name]['und'][$delta]['object_name'];
-      $subject_uniquename = $form_state['values'][$field_name]['und'][$delta]['subject_name'];
+      $object_label = $form_state['values'][$field_name]['und'][$delta]['object_name'];
+      $subject_label = $form_state['values'][$field_name]['und'][$delta]['subject_name'];
       $type = $form_state['values'][$field_name]['und'][$delta]['type_name'];
 
       //@debug dpm(array($subject_id, $type_id, $object_id), 'have an item (AJAX)!');
@@ -222,7 +222,7 @@ class sbo__relationship_widget extends ChadoFieldWidget {
     $widget['subject_name'] = array(
       '#type' => 'textfield',
       '#title' => t('Subject'),
-      '#default_value' => $subject_uniquename,
+      '#default_value' => $subject_label,
       '#required' => $element['#required'],
       '#maxlength' => array_key_exists($subject_id_key, $this->schema['fields']) && array_key_exists('length', $this->schema['fields'][$subject_id_key]) ? $this->schema['fields'][$subject_id_key]['length'] : 255,
       '#size' => 35,
@@ -300,7 +300,7 @@ class sbo__relationship_widget extends ChadoFieldWidget {
     $widget['object_name'] = array(
       '#type' => 'textfield',
       '#title' => t('Object'),
-      '#default_value' => $object_uniquename,
+      '#default_value' => $object_label,
       '#required' => $element['#required'],
       '#maxlength' => array_key_exists($object_id_key, $this->schema['fields']) && array_key_exists('length', $this->schema['fields'][$object_id_key]) ? $this->schema['fields'][$object_id_key]['length'] : 255,
       '#size' => 35,