Browse Source

Tweaks to the relationship chado=>node and an api function to add them

Lacey Sanderson 12 years ago
parent
commit
b209bc15e9

+ 38 - 13
tripal_views/api/tripal_views.api.inc

@@ -144,7 +144,19 @@ function tripal_views_integration_add_entry($defn_array) {
       }
   }
   if ($view_record['name'] && $view_record['comment']) {
-    $status = drupal_write_record('tripal_views', $view_record);
+    if ($defn_array['additional_content']) {
+      $setup = db_fetch_object(db_query("SELECT * FROM {tripal_views} WHERE table_name='%s' AND priority=%d",$view_record['table_name'], $view_record['priority']));
+      if (empty($setup->setup_id)) {
+        $status = drupal_write_record('tripal_views', $view_record);
+      }
+      else {
+        $view_record['setup_id'] = $setup->setup_id;
+        $status = drupal_write_record('tripal_views', $view_record, 'setup_id');
+      }
+    }
+    else {
+      $status = drupal_write_record('tripal_views', $view_record);
+    }
   }
   else {
     $status = FALSE;
@@ -173,7 +185,18 @@ function tripal_views_integration_add_entry($defn_array) {
         'type' => $field['type'],
       );
       if ($view_record['setup_id'] && $field['name'] && $field['title'] && $field['description'] && $field['type']) {
-        $status = drupal_write_record('tripal_views_field', $field_record);
+        if ($defn_array['additional_content']) {
+          $is = db_fetch_object(db_query("SELECT true as present FROM {tripal_views_field} WHERE column_name='%s' AND setup_id=%d",$field_record['column_name'], $field_record['setup_id']));
+          if (!$is->present) {
+            $status = drupal_write_record('tripal_views_field', $field_record);
+          }
+          else {
+            $status = drupal_write_record('tripal_views_field', $field_record, array('setup_id', 'column_name'));
+          }
+        }
+        else {
+          $status = drupal_write_record('tripal_views_field', $field_record);
+        }
       }
       else {
         drupal_set_message(t('Unable to integrate %name field due to missing required fields.', array('%name' => $field['name'])), 'error');
@@ -527,7 +550,7 @@ function tripal_views_add_node_relationship_to_chado_table_integration($defn_arr
   $integrations[$chado_linking] = array(
     'table' => $chado_linking,
     'type' => 'drupal',
-    'name' => 'Chado ' . $defn_array['table'] . ' to Node',
+    'name' => 'Chado ' . $defn_array['table'] . ' Node',
     'description' => 'Links chado content to its drupal node counterpart',
     'priority' => $defn_array['priority'],
     'base_table' => FALSE,
@@ -549,8 +572,16 @@ function tripal_views_add_node_relationship_to_chado_table_integration($defn_arr
         'name' => 'nid',
         'title' => 'Node ID',
         'type' => 'int',
-        'description' => 'The primary key of the drupal node table',
-        'handlers' => array(),
+        'description' => 'Link ' . ucfirst($defn_array['table']) . ' to it\'s node',
+        'handlers' => array(
+          'relationship' => array(
+            'name' => 'chado_views_handler_relationship_to_node',
+            'title' => ucfirst($defn_array['table']) . ' to Node',
+            'label' => ucfirst($defn_array['table']) . ' to Node',
+            'base table' => $defn_array['table'],
+            'base field' => $primary_key
+          )
+        ),
         'joins' => array(
           'node' => array(
             'table' => 'node',
@@ -567,20 +598,14 @@ function tripal_views_add_node_relationship_to_chado_table_integration($defn_arr
     'name' => 'Node',
     'description' => 'Primary Drupal Content',
     'priority' => $defn_array['priority'],
+    'additional_content' => TRUE, // Allows multiple modules to add to the node setup
     'fields' => array(
       'nid' => array(
         'name' => 'nid',
         'title' => 'Node ID',
         'type' => 'int',
         'description' => 'the primary key of the drupal node table',
-        'handlers' => array(
-          'relationship' => array(
-            'name' => 'chado_views_handler_relationship_to_node',
-            'label' => 'Node => Chado ' . ucwords($defn_array['table']),
-            'base table' => $defn_array['table'],
-            'base field' => $primary_key
-          )
-        ),
+        'handlers' => array(),
         'joins' => array(
           $defn_array['table'] => array(
             'table' => $defn_array['table'],

+ 4 - 2
tripal_views/views/handlers/chado_views_handler_relationship_to_node.inc

@@ -30,9 +30,11 @@ class chado_views_handler_relationship_to_node extends views_handler_relationshi
     // The drupal linking table
     $chado_table = 'chado_' . $base_table;
 
-    // Need to remove the incorrectly added node join
+    // Need to remove the incorrectly added node & chado_table join
     unset($this->query->table_queue['node'],
-      $this->query->tables['stock']['node']);
+      $this->query->tables['stock']['node'],
+      $this->query->table_queue[$chado_table],
+      $this->query->tables['stock'][$chado_table]);
 
     // First add base => chado_base join
     $def = array();