Bläddra i källkod

Pub: Added relationships to node form. Currently uses title which is not feasible for long titles

Lacey Sanderson 11 år sedan
förälder
incheckning
a08eac1253

+ 11 - 4
tripal_project/tripal_project.install

@@ -50,6 +50,7 @@ function tripal_project_install() {
   // create the module's data directory
   tripal_create_moddir('tripal_project');
 
+  tripal_project_add_cvs();
   tripal_project_add_cvterms();
 }
 
@@ -87,10 +88,16 @@ function tripal_project_schema() {
 }
 
 /**
- * 
+ *
  */
 function tripal_project_add_cvs() {
   tripal_cv_add_cv('project_property', 'Contains properties for projects');
+
+  // Add cv for relationship types
+  tripal_cv_add_cv(
+    'project_relationship_types',
+    'Contains Types of relationships between projects.'
+  );
 }
 /**
  *
@@ -102,12 +109,12 @@ function tripal_project_add_cvterms() {
   // description in the projectprop table.
   tripal_cv_add_cvterm(
     array(
-      'name' => 'Project Description', 
+      'name' => 'Project Description',
       'def'  => 'Description of a project'
     ),
     'project_property', 0, 1, 'tripal'
   );
-  
+
   tripal_cv_add_cvterm(
     array(
       'name' => 'Project Type',
@@ -146,7 +153,7 @@ function tripal_project_update_7000() {
   if (!$success) {
     throw new DrupalUpdateException('Failed to move project properties to new project_property CV.');
   }
-  
+
   // add in new CVterms
   tripal_project_add_cvterms();
 }

+ 80 - 46
tripal_pub/includes/tripal_pub.chado_node.inc

@@ -245,19 +245,41 @@ function chado_pub_form($node, $form_state) {
     }
   }
 
-  // D7 @TODO: Properties API doesn't handle exclude
-  $exclude = array("Citation");
-
   $details = array(
     'property_table' => 'pubprop',
     'base_foreign_key' => 'pub_id',
     'base_key_value' => $pub_id,
     'cv_name' => 'tripal_pub',
     'select_options' => $select_options,
-    'exclude'=> array('Citation')
   );
   chado_node_properties_form($form, $form_state, $details);
 
+  // RELATIONSHIPS FORM
+  //---------------------------------------------
+  // We want to use the contact_relationship_types cv if there are any terms available
+  // and if not, to default to the relationship ontology
+  $cv_result = tripal_core_chado_select('cv',array('cv_id'),array('name' => 'pub_relationship_types'));
+  $cv_id = $cv_result[0]->cv_id;
+  $select_options = tripal_cv_get_cvterm_options($cv_id);
+  if (empty($select_options)) {
+    $cv_result = tripal_core_chado_select('cv',array('cv_id'),array('name' => 'relationship'));
+    $cv_id = $cv_result[0]->cv_id;
+    $select_options = tripal_cv_get_cvterm_options($cv_id);
+  }
+  // D7 @TODO: tell tripal admin's about this
+
+  $details = array(
+    'relationship_table' => 'pub_relationship', // the name of the _relationship table
+    'base_table' => 'pub',                      // the name of your chado base table
+    'base_foreign_key' => 'pub_id',             // the name of the key in your base chado table
+    'base_key_value' => $pub_id,                // the value of example_id for this record
+    'nodetype' => 'pub',                        // the human-readable name of your node type
+    'cv_name' => 'pub_relationship_types',      // the cv.name of the cv governing example_relationship.type_id
+    'base_name_field' => 'title',               // the base table field you want to be used as the name
+    'select_options' => $select_options
+  );
+  // Adds the form elements to your current form
+  chado_node_relationships_form($form, $form_state, $details);
   return $form;
 
 }
@@ -537,7 +559,6 @@ function chado_pub_insert($node) {
 
     // get the properties from the form
     $properties = chado_node_properties_form_retreive($node);
-    ddl($properties, 'clean properties');
 
     // get the list of properties for easy lookup (without doing lots of database queries
     $properties_list = array();
@@ -655,7 +676,6 @@ function chado_pub_insert($node) {
 
     // now add in the properties
     // Only adds in those not used in the pub record
-    ddl($properties, 'properties before update');
     $details = array(
       'property_table' => 'pubprop',
       'base_table' => 'pub',
@@ -664,6 +684,13 @@ function chado_pub_insert($node) {
     );
     chado_node_properties_form_update_properties($node, $details, $properties);
 
+    // * Relationships Form *
+    $details = array(
+      'relationship_table' => 'pub_relationship',  // name of the _relationship table
+      'foreignkey_value' => $pub_id                // value of the pub_id key
+    );
+    chado_node_relationships_form_update_relationships($node, $details);
+
     // add in any database cross-references
     foreach ($cross_refs as $index => $ref) {
       $pub_dbxref = tripal_pub_add_pub_dbxref($pub['pub_id'], trim($ref));
@@ -851,6 +878,13 @@ function chado_pub_update($node) {
   );
   chado_node_properties_form_update_properties($node, $details, $properties);
 
+  // * Relationships Form *
+  $details = array(
+    'relationship_table' => 'pub_relationship',  // name of the _relationship table
+    'foreignkey_value' => $pub_id                // value of the pub_id key
+  );
+  chado_node_relationships_form_update_relationships($node, $details);
+
   // add in any database cross-references after first removing
   tripal_core_chado_delete('pub_dbxref', array('pub_id' => $pub_id));
   foreach ($cross_refs as $index => $ref) {
@@ -940,46 +974,46 @@ function chado_pub_delete(&$node) {
  */
 function tripal_pub_node_view($node, $view_mode, $langcode) {
   switch ($node->type) {
-    case 'chado_pub':
-      // Show feature browser and counts
-      if ($view_mode == 'full') {
-        $node->content['tripal_pub_authors'] = array(
-          '#value' => theme('tripal_pub_authors', array('node' => $node)),
-        );
-        $node->content['tripal_pub_base'] = array(
-          '#value' => theme('tripal_pub_base', array('node' => $node)),
-        );
-        $node->content['tripal_pub_featuremaps'] = array(
-          '#value' => theme('tripal_pub_featuremaps', array('node' => $node)),
-        );
-        $node->content['tripal_pub_features'] = array(
-          '#value' => theme('tripal_pub_features', array('node' => $node)),
-        );
-        $node->content['tripal_pub_libraries'] = array(
-          '#value' => theme('tripal_pub_libraries', array('node' => $node)),
-        );
-        $node->content['tripal_pub_projects'] = array(
-          '#value' => theme('tripal_pub_projects', array('node' => $node)),
-        );
-        $node->content['tripal_pub_properties'] = array(
-          '#value' => theme('tripal_pub_properties', array('node' => $node)),
-        );
-        $node->content['tripal_pub_references'] = array(
-          '#value' => theme('tripal_pub_references', array('node' => $node)),
-        );
-        $node->content['tripal_pub_relationships'] = array(
-          '#value' => theme('tripal_pub_relationships', array('node' => $node)),
-        );
-        $node->content['tripal_pub_stocks'] = array(
-          '#value' => theme('tripal_pub_stocks', array('node' => $node)),
-        );
-      }
-      if ($view_mode == 'teaser') {
-        $node->content['tripal_pub_teaser'] = array(
-          '#value' => theme('tripal_pub_teaser', array('node' => $node)),
-        );
-      }
-      break;
+  	case 'chado_pub':
+  	  // Show feature browser and counts
+  	  if ($view_mode == 'full') {
+  	    $node->content['tripal_pub_authors'] = array(
+  	      '#value' => theme('tripal_pub_authors', array('node' => $node)),
+  	    );
+  	    $node->content['tripal_pub_base'] = array(
+  	      '#value' => theme('tripal_pub_base', array('node' => $node)),
+  	    );
+  	    $node->content['tripal_pub_featuremaps'] = array(
+  	      '#value' => theme('tripal_pub_featuremaps', array('node' => $node)),
+  	    );
+  	    $node->content['tripal_pub_features'] = array(
+  	      '#value' => theme('tripal_pub_features', array('node' => $node)),
+  	    );
+  	    $node->content['tripal_pub_libraries'] = array(
+  	      '#value' => theme('tripal_pub_libraries', array('node' => $node)),
+  	    );
+  	    $node->content['tripal_pub_projects'] = array(
+  	      '#value' => theme('tripal_pub_projects', array('node' => $node)),
+  	    );
+  	    $node->content['tripal_pub_properties'] = array(
+  	      '#value' => theme('tripal_pub_properties', array('node' => $node)),
+  	    );
+  	    $node->content['tripal_pub_references'] = array(
+  	      '#value' => theme('tripal_pub_references', array('node' => $node)),
+  	    );
+  	    $node->content['tripal_pub_relationships'] = array(
+  	      '#value' => theme('tripal_pub_relationships', array('node' => $node)),
+  	    );
+  	    $node->content['tripal_pub_stocks'] = array(
+  	      '#value' => theme('tripal_pub_stocks', array('node' => $node)),
+  	    );
+  	  }
+  	  if ($view_mode == 'teaser') {
+  	    $node->content['tripal_pub_teaser'] = array(
+  	      '#value' => theme('tripal_pub_teaser', array('node' => $node)),
+  	    );
+  	  }
+  	  break;
   }
 }
 /**

+ 30 - 0
tripal_pub/tripal_pub.install

@@ -56,6 +56,9 @@ function tripal_pub_install() {
   $obo_id = tripal_cv_add_obo_ref('Tripal Publication', $obo_path);
   tripal_cv_submit_obo_job($obo_id);
 
+  tripal_pub_add_cvs();
+  tripal_pub_add_cvterms();
+
   // add the custom tables
   tripal_pub_add_custom_tables();
 
@@ -204,4 +207,31 @@ function tripal_pub_add_custom_tables() {
     ),
   );
   tripal_core_create_custom_table('pubauthor_contact', $schema, TRUE);
+}
+
+/**
+ *
+ */
+function tripal_project_add_cvs() {
+
+  // Add cv for relationship types
+  tripal_cv_add_cv(
+    'pub_relationship_types',
+    'Contains Types of relationships between publications.'
+  );
+}
+/**
+ *
+ */
+function tripal_project_add_cvterms() {
+
+}
+
+/**
+ * This is the required update for tripal_contact when upgrading from Drupal core API 6.x.
+ */
+function tripal_pub_update_7000() {
+
+  tripal_pub_add_cvs();
+  tripal_pub_add_cvterms();
 }