Browse Source

Fixed bug in library template

Stephen Ficklin 11 years ago
parent
commit
75a9bb37e3

+ 2 - 1
tripal_core/api/tripal_core.chado_nodes.dbxrefs.api.inc

@@ -149,7 +149,8 @@ function chado_node_additional_dbxrefs_form(&$form, &$form_state, $details) {
       as many database references as desired by clicking the add button on the right.  To
       remove a database reference, click the remove button. ' . $details['additional_instructions']),
     '#prefix' => "<div id='addtl-dbxrefs-fieldset'>",
-    '#suffix' => '</div>'
+    '#suffix' => '</div>',
+    '#weight'      => 10
   );
 
   // this form element is a tree, so that we don't puke all of the values into then node variable

+ 2 - 1
tripal_core/api/tripal_core.chado_nodes.properties.api.inc

@@ -510,7 +510,8 @@ function chado_node_properties_form(&$form, &$form_state, $details) {
       clicking the add button on the right. To remove a property, click the remove button.
       To add additional properties to the drop down. ' . $details['additional_instructions']),
     '#prefix' => "<div id='properties-fieldset'>",
-    '#suffix' => '</div>'
+    '#suffix' => '</div>',
+    '#weight'      => 10
   );
 
   // this form element is a tree, so that we don't puke all of the values into then node variable

+ 2 - 1
tripal_core/api/tripal_core.chado_nodes.relationships.api.inc

@@ -190,7 +190,8 @@ function chado_node_relationships_form(&$form, &$form_state, $details) {
       remove a relationship, click the remove button. ' . $details['additional_instructions'],
       array('%nodetype' => $details['nodetype'], '%nodetype_plural' => $details['nodetype_plural'])),
     '#prefix' => "<div id='relationships-fieldset'>",
-    '#suffix' => '</div>'
+    '#suffix' => '</div>',
+    '#weight'      => 10
   );
 
   // this form element is a tree, so that we don't puke all of the values into then node variable

+ 0 - 1
tripal_example/includes/tripal_example.chado_node.inc

@@ -583,7 +583,6 @@ function tripal_example_node_view($node, $view_mode, $langcode) {
         //  '#tripal_toc_id'    => 'base',
         //  '#tripal_toc_title' => 'Details',
         //);
-
         // we can add other templates as well.
         //$node->content['tripal_example_properties'] = array(
         //  '#markup' => theme('tripal_example_properties', array('node' => $node)),

+ 61 - 19
tripal_library/includes/tripal_library.chado_node.inc

@@ -56,20 +56,20 @@ function chado_library_form($node, &$form_state) {
   $library_type = '';
   $organism_id = '';
   $description = '';
-  
+
   // if we are editing an existing node then the library is already part of the node
   if (property_exists($node, 'library')) {
     $library = $node->library;
     $library_id = $library->library_id;
-    
+
     $title        = $library->name;
     $uniquename   = $library->uniquename;
     $library_type = $library->type_id->cvterm_id;
     $organism_id  = $library->organism_id->organism_id;
-    
+
     $libprop = tripal_library_get_property($library->library_id, 'Library Description');
     $description = $libprop->value;
-    
+
     // keep track of the library id if we have.  If we do have one then
     // this is an update as opposed to an insert.
     $form['library_id'] = array(
@@ -169,6 +169,26 @@ function chado_library_form($node, &$form_state) {
     '#weight'        => 5
   );
 
+  // PROPERTIES FORM
+  //---------------------------------------------
+  // Generate our own select list so we can desclude the description since it has it's
+  // own form element above
+  $cv_result = tripal_core_chado_select('cv',array('cv_id'),array('name' => 'library_property'));
+  $cv_id = $cv_result[0]->cv_id;
+  $select_options = tripal_cv_get_cvterm_options($cv_id);
+  $descrip_id = array_search('Library Description', $select_options);
+  unset($select_options[$descrip_id]);
+
+  $details = array(
+    'property_table' => 'libraryprop',      // the name of the prop table
+    'base_foreign_key' => 'library_id',     // the name of the key in your base chado table
+    'base_key_value' => $library_id,        // the value of library_id for this record
+    'cv_name' => 'library_property',        // the cv.name of the cv governing libraryprop.type_id
+    'select_options' => $select_options
+  );
+  // Adds the form elements to your current form
+  chado_node_properties_form($form, $form_state, $details);
+
   return $form;
 }
 /**
@@ -177,11 +197,11 @@ function chado_library_form($node, &$form_state) {
  * @ingroup tripal_library
  */
 function chado_library_validate($node, $form, &$form_state) {
-  
+
   $node->title       = trim($node->title);
   $node->uniquename  = trim($node->uniquename);
   $node->description = trim($node->description);
-  
+
   $lib = 0;
   // check to make sure the unique name on the library is unique
   // before we try to insert into chado.
@@ -209,7 +229,7 @@ function chado_library_validate($node, $form, &$form_state) {
  * @ingroup tripal_library
  */
 function chado_library_insert($node) {
-  
+
   $node->title       = trim($node->title);
   $node->uniquename  = trim($node->uniquename);
   $node->description = trim($node->description);
@@ -232,10 +252,21 @@ function chado_library_insert($node) {
       return;
     }
     $library_id = $library['library_id'];
-    
+
+    // * Properties Form *
     // add the description property
-    tripal_library_insert_property($library_id, 'Library Description', $node->description);
-    
+    $properties = chado_node_properties_form_retreive($node);
+    $descrip_id = tripal_cv_get_cvterm_by_name('Library Description', NULL, 'library_property');
+    $properties[$descrip_id->cvterm_id][0] = $node->description;
+
+    $details = array(
+      'property_table' => 'libraryprop',   // the name of the prop table
+      'base_table' => 'library',           // the name of your chado base table
+      'foreignkey_name' => 'library_id',   // the name of the key in your base table
+      'foreignkey_value' => $library_id    // the value of the library_id key
+    );
+    chado_node_properties_form_update_properties($node, $details, $properties);
+
   }
   else {
     $library_id = $node->library_id;
@@ -258,7 +289,7 @@ function chado_library_insert($node) {
  * @ingroup tripal_library
  */
 function chado_library_update($node) {
-  
+
   $node->title       = trim($node->title);
   $node->uniquename  = trim($node->uniquename);
   $node->description = trim($node->description);
@@ -280,9 +311,20 @@ function chado_library_update($node) {
     watchdog('tripal_library', 'Update library: Unable to update library where values: %values',
     array('%values' => print_r($values, TRUE)), WATCHDOG_ERROR);
   }
-  
-  // add in the library description as a property
-  tripal_library_update_property($library_id, 'Library Description', $node->description, 1);
+
+  // * Properties Form *
+  // add the description property
+  $properties = chado_node_properties_form_retreive($node);
+  $descrip_id = tripal_cv_get_cvterm_by_name('Library Description', NULL, 'library_property');
+  $properties[$descrip_id->cvterm_id][0] = $node->description;
+
+  $details = array(
+    'property_table' => 'libraryprop',   // the name of the prop table
+    'base_table' => 'library',           // the name of your chado base table
+    'foreignkey_name' => 'library_id',   // the name of the key in your base table
+    'foreignkey_value' => $library_id    // the value of the library_id key
+  );
+  chado_node_properties_form_update_properties($node, $details, $properties);
 }
 /**
  *  When a node is requested by the user this function is called to allow us
@@ -291,17 +333,17 @@ function chado_library_update($node) {
  * @ingroup tripal_library
  */
 function chado_library_load($nodes) {
-  
+
   foreach ($nodes as $nid => $node) {
     // get the feature details from chado
     $library_id = chado_get_id_for_node('library', $node->nid);
-  
+
     $values = array('library_id' => $library_id);
     $library = tripal_core_generate_chado_var('library', $values);
-  
+
     // the uniquename field is a text field so we need to expand it
     $library = tripal_core_expand_chado_vars($library, 'field', 'library.uniquename');
-    
+
     $nodes[$nid]->library = $library;
   }
 }
@@ -460,7 +502,7 @@ function tripal_library_node_presave($node) {
       if(property_exists($node, 'library')) {
         // set the title
         $node->title = $node->name;
-      } 
+      }
       else {
         // the title field is already in the form
       }

+ 2 - 4
tripal_library/theme/tripal_library/tripal_library.base.tpl.php

@@ -70,13 +70,11 @@ if (user_access('access administration pages')) {
       'header' => TRUE,
       'class'  => 'tripal-site-admin-only-table-row',
     ),
-    array(
-      'data'  => $library->library_id,
-      'class' => 'tripal-site-admin-only-table-row',
-    ),
+    $library->uniquename,
   );
 }
 
+
 // the $table array contains the headers and rows array as well as other
 // options for controlling the display of the table.  Additional
 // documentation can be found here:

+ 40 - 3
tripal_organism/includes/tripal_organism.chado_node.inc

@@ -179,6 +179,17 @@ function chado_organism_insert($node) {
       return;
     }
     $organism_id = $organism['organism_id'];
+
+    if ($organism_id) {
+      // * Properties Form *
+      $details = array(
+        'property_table' => 'organismprop',   // the name of the prop table
+        'base_table' => 'organism',           // the name of your chado base table
+        'foreignkey_name' => 'organism_id',   // the name of the key in your base table
+        'foreignkey_value' => $organism_id    // the value of the example_id key
+      );
+      chado_node_properties_form_update_properties($node, $details);
+    }
   }
   else {
     $organism_id = $node->organism_id;
@@ -211,12 +222,14 @@ function chado_organism_update($node) {
   $node->common_name  = trim($node->common_name);
   $node->description  = trim($node->description);
 
+  $organism_id = chado_get_id_for_node('organism', $node->nid);
+
   if ($node->revision) {
     // there is no way to handle revisions in Chado but leave
     // this here just to make not we've addressed it.
   }
   $match = array(
-    'organism_id' => chado_get_id_for_node('organism', $node->nid),
+    'organism_id' => $organism_id,
   );
   $values = array(
     'genus' => $node->genus,
@@ -229,6 +242,15 @@ function chado_organism_update($node) {
 
   // add the image
   chado_organism_add_image($node);
+
+  // * Properties Form *
+  $details = array(
+    'property_table' => 'organismprop',   // the name of the prop table
+    'base_table' => 'organism',           // the name of your chado base table
+    'foreignkey_name' => 'organism_id',   // the name of the key in your base table
+    'foreignkey_value' => $organism_id    // the value of the example_id key
+  );
+  chado_node_properties_form_update_properties($node, $details);
 }
 /**
  * Delete organism from both drupal and chado databases. Check dependency before
@@ -262,7 +284,7 @@ function chado_organism_delete($node) {
   $check_lib = chado_query($sql, array(':organism_id' => $organism_id))->fetchObject();
   $sql = "SELECT stock_id FROM {stock} WHERE organism_id = :organism_id";
   $check_stock = chado_query($sql, array(':organism_id' => $organism_id))->fetchObject();
-  
+
   if (!$check_lib && !$check_feature && !$check_stock) {
     tripal_core_chado_delete('organism', array('organism_id' => $organism_id));
   }
@@ -333,6 +355,7 @@ function chado_organism_form($node, $form_state) {
       '#type' => 'value',
       '#value' => $organism->organism_id,
     );
+    $organism_id = $organism->organism_id;
   }
   else {
     // get form defaults
@@ -342,6 +365,8 @@ function chado_organism_form($node, $form_state) {
     $common_name    = property_exists($node, 'common_name')    ? property_exists($node, 'common_name')    : '';
     $description    = property_exists($node, 'description')    ? property_exists($node, 'description')    : '';
     $organism_image = property_exists($node, 'organism_image') ? property_exists($node, 'organism_image') : '';
+
+    $organism_id = NULL;
   }
 
   $form['genus']= array(
@@ -380,6 +405,18 @@ function chado_organism_form($node, $form_state) {
     '#description' => 'Add an image for this organism',
     '#progress_indicator' => 'bar',
   );
+
+  // PROPERTIES FORM
+  //---------------------------------------------
+  $details = array(
+    'property_table' => 'organismprop',      // the name of the prop table
+    'base_foreign_key' => 'organism_id',     // the name of the key in your base chado table
+    'base_key_value' => $organism_id,        // the value of organism_id for this record
+    'cv_name' => 'organism_property'         // the cv.name of the cv governing organismprop.type_id
+  );
+  // Adds the form elements to your current form
+  chado_node_properties_form($form, $form_state, $details);
+
   return $form;
 }
 
@@ -418,7 +455,7 @@ function tripal_organism_node_presave($node) {
       if(property_exists($node, 'organism')) {
         // set the title
         $node->title = $node->organism->genus . " " . $node->organism->species;
-      } 
+      }
       else {
         // set the title
         $node->title = $node->genus  . " " . $node->species;

+ 28 - 0
tripal_organism/tripal_organism.install

@@ -31,6 +31,10 @@ function tripal_organism_install() {
 
   // create the directory where image files will be stored.  We create this
   tripal_create_mod_subdir('tripal_organism', '/images');
+
+  // cvs & cvterms
+  tripal_organism_add_cvs();
+  tripal_organism_add_cvterms();
 }
 
 /**
@@ -97,4 +101,28 @@ function tripal_organism_requirements($phase) {
     }
   }
   return $requirements;
+}
+
+/**
+ *
+ */
+function tripal_organism_add_cvs() {
+
+  tripal_cv_add_cv('organism_property', 'Contains properties for organisms');
+
+}
+/**
+ *
+ */
+function tripal_organism_add_cvterms() {
+
+}
+
+/**
+ * This is the required update for tripal_organism when upgrading from Drupal core API 6.x.
+ */
+function tripal_organism_update_7000() {
+
+  tripal_organism_add_cvs();
+  tripal_organism_add_cvterms();
 }