Browse Source

Fixed a few bugs in the bulk loader, updated hook_node_insert for features, stocks and example module for setting URLs and added links to terms template to help admin update term links

Stephen Ficklin 11 years ago
parent
commit
5b80accad0

+ 39 - 22
tripal_bulk_loader/includes/tripal_bulk_loader.admin.templates.inc

@@ -496,7 +496,7 @@ function tripal_bulk_loader_modify_template_base_form_submit($form, &$form_state
       $form_state['storage']['template_name'] = $record['name'];
       $form_state['storage']['template'] = array();
       $form_state['rebuild'] = FALSE;
-      $form_state['redirect'] = 'admin/tripal/loaders/bulk/template/'.$record['template_id'].'/edit';
+      $form_state['redirect'] = 'admin/tripal/loaders/bulk/template/' . $record['template_id'] . '/edit';
     break;
 
     // Save Reordered Records -----------------------------------------------------
@@ -520,8 +520,9 @@ function tripal_bulk_loader_modify_template_base_form_submit($form, &$form_state
     break;
 
     case 'New Record/Field':
+      $template_id = $form_state['storage']['template_id'] ? $form_state['storage']['template_id'] : 'O';
       $form_state['rebuild'] = FALSE;
-      $form_state['redirect'] = 'admin/tripal/loaders/bulk/template/'.$form_state['storage']['template_id'].'/add_record';
+      $form_state['redirect'] = "admin/tripal/loaders/bulk/template/$template_id/add_record";
       $save = FALSE;
     break;
 
@@ -1397,10 +1398,15 @@ function tripal_bulk_loader_duplicate_template_record_form_submit($form, &$form_
 function tripal_bulk_loader_template_field_form_default_values($mode, &$form_state) {
   $v = array();
 
+  // mode can be 'create' or 'edit'
   $v['mode'] = $mode;
+  
+  // the template_id is the ID of the template if this is an edit, or FALSE if this is a create
   $v['template_id'] = (isset($form_state['build_info']['args'][1])) ? $form_state['build_info']['args'][1] : FALSE;
   $form_state['storage']['template_id'] = $v['template_id'];
   $template_id = $v['template_id'];
+  
+  
   $v['record_id'] = (isset($form_state['build_info']['args'][2])) ? $form_state['build_info']['args'][2] : FALSE;
   $v['no_record_id'] = ($mode == 'create_record') ? TRUE : FALSE;
   $form_state['storage']['record_id'] = $v['record_id'];
@@ -1411,30 +1417,41 @@ function tripal_bulk_loader_template_field_form_default_values($mode, &$form_sta
   $form_state['storage']['field_index'] = $v['field_index'];
   $field_index = $v['field_index'];
 
-  if (!isset($form_state['values'])) {
+  if (!array_key_exists('values', $form_state)) {
     $form_state['values'] = array();
   }
 
-  // Get the template if not already stored
-  if (!isset($form_state['storage']['template'])) {
-    $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=:template";
-    $template = db_query($sql, array(':template' => $template_id))->fetchObject();
-    $form_state['storage']['template_array'] = unserialize($template->template_array);
-    if (!$form_state['storage']['template_array']) {
-      $form_state['storage']['template_array'] = array();
-    }
-    $form_state['storage']['template'] = $template;
-
-    $form_state['storage']['record2priority'] = array();
-    foreach ($form_state['storage']['template_array'] as $priority => $record_array) {
-      if (!is_array($record_array)) {
-        continue;
+  // if we are editing an existing template then get the template array from the database
+  // and store it in the form_state['storage'] variable for later access
+  if ($mode == 'edit') {
+    if(!array_key_exists('template', $form_state['storage'])) {
+      $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id = :template";
+      $template = db_query($sql, array(':template' => $template_id))->fetchObject();
+      
+      // unserialize the template array. This array contains the PHP serilazed array 
+      // describing the entire loader template
+      $form_state['storage']['template_array'] = unserialize($template->template_array);
+      if (!$form_state['storage']['template_array']) {
+        $form_state['storage']['template_array'] = array();
+      }
+      
+      // save the template record from the database for future use
+      $form_state['storage']['template'] = $template;
+  
+      // initialize the record2priority array which keeps track of the order by
+      // copying the priority information about each record from the template array
+      // into the $form_state['storage']['record2priority'] array
+      $form_state['storage']['record2priority'] = array();
+      foreach ($form_state['storage']['template_array'] as $priority => $record_array) {
+        if (!is_array($record_array)) {
+          continue;
+        }
+        $form_state['storage']['record2priority'][$record_array['record_id']] = $priority;
       }
-      $form_state['storage']['record2priority'][$record_array['record_id']] = $priority;
     }
-  }
-  else {
-    $template = $form_state['storage']['template'];
+    else {
+      $template = $form_state['storage']['template'];
+    }
   }
 
   // If we are editing then get the original values
@@ -1574,7 +1591,7 @@ function tripal_bulk_loader_template_field_form_default_values($mode, &$form_sta
   }
 
   // Field group options
-  if (!$form_state['storage']['record2priority']) {
+  if (!array_key_exists('record2priority', $form_state['storage'])) {
     $groups = array();
   }
   else {

+ 17 - 21
tripal_bulk_loader/theme/tripal_bulk_loader_modify_template_base_form.tpl.php

@@ -18,13 +18,12 @@ td.tbl-action-field-links {
 }
 </style>
 
-<div id="tripal-bulk-loader-fields">
-<?php print drupal_render($form['template_name']); ?>
+<div id="tripal-bulk-loader-fields"><?php 
+print drupal_render($form['template_name']); ?>
 
-<!-- For each table display details in a draggable table -->
-<?php if (!$form['records']['no_records']['#value']) { ?>
-  <fieldset><legend><?php print $form['records']['#title']; ?></legend>
-  <?php
+<!-- For each table display details in a draggable table --><?php 
+if (!$form['records']['no_records']['#value']) { ?>
+  <fieldset><legend><?php print $form['records']['#title']; ?></legend> <?php
     print drupal_render($form['records']['description']);
 
     // generate table
@@ -66,16 +65,14 @@ td.tbl-action-field-links {
     // Render submit
     print drupal_render($form['records']['submit-new_record']);
     print drupal_render($form['records']['submit-reorder']);
-    unset($form['records']);
-  ?>
-  </fieldset>
-<?php } ?>
+    unset($form['records']); ?>
+  </fieldset> <?php 
+} ?>
 
-<!-- For each field display details plus edit/delete buttons-->
-<?php if ($form['fields']['total_fields']['#value'] > 0) { ?>
-  <fieldset><legend><?php print $form['fields']['#title']; ?></legend>
-
-  <?php
+<!-- For each field display details plus edit/delete buttons--> <?php 
+if (array_key_exists('total_fields', $form['fields']) and
+    $form['fields']['total_fields']['#value'] > 0) { ?>
+  <fieldset><legend><?php print $form['fields']['#title']; ?></legend> <?php
     // generate table
     $header = array('','Record Name', 'Field Name', 'Chado Table', 'Chado Field', 'Data File Column', 'Constant Value', 'Foreign Record');
     $rows = array();
@@ -110,11 +107,10 @@ td.tbl-action-field-links {
 
     // Render other elements
     print drupal_render($form['fields']['add_field']);
-    unset($form['fields']);
-  ?>
-  </fieldset>
-<?php } ?>
+    unset($form['fields']); ?>
+  </fieldset> <?php 
+} ?>
 
-<!-- Display Rest of form -->
-<?php print drupal_render_children($form); ?>
+<!-- Display Rest of form --><?php 
+print drupal_render_children($form); ?>
 </div>

+ 9 - 9
tripal_bulk_loader/tripal_bulk_loader.module

@@ -124,7 +124,7 @@ function tripal_bulk_loader_menu() {
     'title' => 'Edit Template',
     'description' => 'Edit loader template for loading tab-delimited data',
     'page callback' => 'drupal_get_form',
-    'page arguments' => array('tripal_bulk_loader_modify_template_base_form', 'edit',5),
+    'page arguments' => array('tripal_bulk_loader_modify_template_base_form', 'edit', 5),
     'access arguments' => array('administer tripal_bulk_loader'),
     'type' => MENU_CALLBACK,
   );
@@ -145,7 +145,7 @@ function tripal_bulk_loader_menu() {
     'title' => 'Add Template Field',
     'description' => 'Add a template field to an existing tripal bulk loader template.',
     'page callback' => 'drupal_get_form',
-    'page arguments' => array('tripal_bulk_loader_template_field_form','create_record',5,FALSE),
+    'page arguments' => array('tripal_bulk_loader_template_field_form', 'create_record', 5, FALSE),
     'access arguments' => array('administer tripal_bulk_loader'),
     'type' => MENU_CALLBACK,
   );
@@ -153,7 +153,7 @@ function tripal_bulk_loader_menu() {
     'title' => 'Edit Template Record',
     'description' => 'Edit a record in an existing tripal bulk loader template.',
     'page callback' => 'drupal_get_form',
-    'page arguments' => array('tripal_bulk_loader_edit_template_record_form',5,7),
+    'page arguments' => array('tripal_bulk_loader_edit_template_record_form', 5, 7),
     'access arguments' => array('administer tripal_bulk_loader'),
     'type' => MENU_CALLBACK,
   );
@@ -161,7 +161,7 @@ function tripal_bulk_loader_menu() {
     'title' => 'Delete Template Record',
     'description' => 'Delete a record in an existing tripal bulk loader template.',
     'page callback' => 'drupal_get_form',
-    'page arguments' => array('tripal_bulk_loader_delete_template_record_form',5,7),
+    'page arguments' => array('tripal_bulk_loader_delete_template_record_form', 5, 7),
     'access arguments' => array('administer tripal_bulk_loader'),
     'type' => MENU_CALLBACK,
   );
@@ -169,7 +169,7 @@ function tripal_bulk_loader_menu() {
     'title' => 'Duplicate Template Record',
     'description' => 'Duplicate a record in an existing tripal bulk loader template.',
     'page callback' => 'drupal_get_form',
-    'page arguments' => array('tripal_bulk_loader_duplicate_template_record_form',5,7),
+    'page arguments' => array('tripal_bulk_loader_duplicate_template_record_form', 5, 7),
     'access arguments' => array('administer tripal_bulk_loader'),
     'type' => MENU_CALLBACK,
   );
@@ -179,7 +179,7 @@ function tripal_bulk_loader_menu() {
     'title' => 'Add Template Field',
     'description' => 'Add a template field to an existing tripal bulk loader template.',
     'page callback' => 'drupal_get_form',
-    'page arguments' => array('tripal_bulk_loader_template_field_form','create',5,7),
+    'page arguments' => array('tripal_bulk_loader_template_field_form','create', 5, 7),
     'access arguments' => array('administer tripal_bulk_loader'),
     'type' => MENU_CALLBACK,
   );
@@ -187,7 +187,7 @@ function tripal_bulk_loader_menu() {
     'title' => 'Edit Template Field',
     'description' => 'Edit an existing field from a tripal bulk loader template.',
     'page callback' => 'drupal_get_form',
-    'page arguments' => array('tripal_bulk_loader_template_field_form','edit',5,7,8),
+    'page arguments' => array('tripal_bulk_loader_template_field_form','edit', 5, 7, 8),
     'access arguments' => array('administer tripal_bulk_loader'),
     'type' => MENU_CALLBACK,
   );
@@ -195,7 +195,7 @@ function tripal_bulk_loader_menu() {
     'title' => 'Delete Template Field',
     'description' => 'Delete an existing field from a tripal bulk loader template.',
     'page callback' => 'drupal_get_form',
-    'page arguments' => array('tripal_bulk_loader_delete_template_field_form',5,7,8),
+    'page arguments' => array('tripal_bulk_loader_delete_template_field_form', 5, 7, 8),
     'access arguments' => array('administer tripal_bulk_loader'),
     'type' => MENU_CALLBACK,
   );
@@ -205,7 +205,7 @@ function tripal_bulk_loader_menu() {
     'title' => 'Delete Template',
     'description' => 'Delete bulk loader template',
     'page callback' => 'drupal_get_form',
-    'page arguments' => array('tripal_bulk_loader_delete_template_base_form',5),
+    'page arguments' => array('tripal_bulk_loader_delete_template_base_form', 5),
     'access arguments' => array('administer tripal_bulk_loader'),
     'weight' => -4,
     'type' => MENU_CALLBACK,

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

@@ -542,6 +542,10 @@ function tripal_example_node_insert($node) {
   //      $chado_example = db_query($sql, array(':nid' => $node->nid))->fetchObject();
   //      $node->example_id = $chado_example->example_id;
   //    }
+  
+  //    // on an insert we need to add the feature_id to the node object
+  //    // so that the tripal_example_get_example_url function can set the URL properly
+  //    $node->example_id = chado_get_id_from_nid('example', $node->nid);
 
   //    // remove any previous alias
   //    db_query("DELETE FROM {url_alias} WHERE source = :source", array(':source' => "node/$node->nid"));

+ 4 - 1
tripal_feature/includes/tripal_feature.chado_node.inc

@@ -472,7 +472,6 @@ function chado_feature_insert($node) {
       'foreignkey_value' => $feature_id      // the value of the feature_id key
     );
     chado_update_node_form_dbxrefs($node, $details);
-
   }
   else {
     $feature_id = $node->feature_id;
@@ -794,6 +793,10 @@ function tripal_feature_node_insert($node) {
   // know the feature_id in the presave
   switch ($node->type) {
     case 'chado_feature':
+      
+      // on an insert we need to add the feature_id to the node object
+      // so that the tripal_feature_get_feature_url function can set the URL properly
+      $node->feature_id = chado_get_id_from_nid('feature', $node->nid);
 
       // remove any previous alias
       db_query("DELETE FROM {url_alias} WHERE source = :source", array(':source' => "node/$node->nid"));

+ 11 - 2
tripal_feature/theme/tripal_feature/tripal_feature_terms.tpl.php

@@ -46,6 +46,15 @@ if (count($s_terms) > 0) { ?>
         $term->cvterm_id->name
       );
     } 
+    
+    // generate the link to configure a database, b ut only if the user is
+    // a tripal administrator
+    $configure_link = '';
+    if (user_access('administer tripal')) {
+      $db_id = $term->cvterm_id->dbxref_id->db_id->db_id;
+      $configure_link = l('[configure term links]', "admin/tripal/chado/tripal_db/edit/$db_id", array('attributes' => array("target" => '_blank')));
+    }
+    
     // 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:
@@ -57,7 +66,7 @@ if (count($s_terms) > 0) { ?>
         'id' => "tripal_feature-table-terms-$i",
       ),
       'sticky' => FALSE,
-      'caption' => '<b>Vocabulary: ' . ucwords(preg_replace('/_/', ' ', $cv)) . '</b>',
+      'caption' => 'Vocabulary:  <b>' . ucwords(preg_replace('/_/', ' ', $cv)) . '</b> ' . $configure_link,
       'colgroups' => array(),
       'empty' => '',
     );
@@ -66,5 +75,5 @@ if (count($s_terms) > 0) { ?>
     // function to generate the table.
     print theme_table($table);
     $i++;
-  } 
+  }
 }

+ 2 - 1
tripal_feature/theme/tripal_organism/tripal_organism_feature_browser.tpl.php

@@ -66,7 +66,8 @@ if (count($features) > 0) { ?>
     "by navigating to the ".
     l("Tripal feature settings page", "admin/tripal/chado/tripal_feature/configuration", array('attributes' => array('target' => '_blank'))),
     TRIPAL_INFO,
-    array('return_html' => 1));
+    array('return_html' => 1)
+  );
   
   foreach ($features as $feature){
     $fname =  $feature->name;

+ 4 - 0
tripal_stock/includes/tripal_stock.chado_node.inc

@@ -895,6 +895,10 @@ function tripal_stock_node_insert($node) {
   switch ($node->type) {
     case 'chado_stock':
 
+      // on an insert we need to add the stock_id to the node object
+      // so that the tripal_stock_get_stock_url function can set the URL properly
+      $node->stock_id = chado_get_id_from_nid('stock', $node->nid);
+      
       // remove any previous alias
       db_query("DELETE FROM {url_alias} WHERE source = :source", array(':source' => "node/$node->nid"));