Browse Source

Set a default URL path for all publications to be the Chado pub ID

spficklin 12 years ago
parent
commit
a7e0a0dc26

+ 1 - 1
tripal_core/api/tripal_core_chado.api.inc

@@ -2072,7 +2072,7 @@ function tripal_core_expand_chado_vars($object, $type, $to_expand, $table_option
 
   // make sure we have a value
   if (!$object) {
-    watchdog('tripal_core', 'Cannot pass non array as $object.', array(),WATCHDOG_ERROR);
+    watchdog('tripal_core', 'Cannot pass non array as arugment, $object, to tripal_core_expand_chado_vars function.', array(), WATCHDOG_ERROR);
     return $object;
   }
 

+ 12 - 0
tripal_feature/theme/tripal_feature_admin.tpl.php

@@ -79,6 +79,18 @@
   <p>Aside from data loading and feature page setup (as described in the Setup section above),
   The Tripal feature module also provides the following functionality
   <ul>
+     <li><p><b>Generic Feature URL</b>:  As described in the setup instructions above, it is often convenient to have a 
+     simple URL for each feature page. For example, http://www.mygenomesite.org/[feature], where [feature] is a 
+     unique identifier for a feature page.  The
+     <?php print l('Feature Configuration page','admin/tripal/tripal_feature/configuration') ?> allows a 
+     site admin to generate unique URLs for all feature.  The unique URL is necessary, however, sometimes
+     it is easier to allow for links to the feature name without knowing the unique URL.  This is possible
+     using the URL: http://[site url]/feature/[feature name], where [site url] is the URL for the site and 
+     [feature name] is the name of the feature.  If the feature name is not unique then a page will be
+     presented listing all of the features with the same name and allow the user to choose which one to 
+     view.  If the feature name is unique then the user will automatically be redirected to the 
+     unique URL for the feature.</p></li>
+     
     <li><p><b>Feature Browser:</b>  The feature browser is a tabular list of features with links to their
      feature pages which appears on the organism
      page.  It was created to provide a mechanism to allow site visitors to quickly

+ 15 - 0
tripal_pub/includes/tripal_pub.admin.inc

@@ -140,3 +140,18 @@ function tripal_pub_cleanup($dummy = NULL, $job_id = NULL) {
   
 }
 
+/**
+ *
+ */
+function tripal_pub_set_pub_url($node, $pub_id) {
+  
+  $node_url = "node/$node->nid";
+  $url_alias = "pub/$pub_id";
+
+  // remove any previous alias
+  db_query("DELETE FROM {url_alias} WHERE src = '%s'", $node_url);
+  // add the new alias
+  path_set_alias($node_url, $url_alias);
+  
+  return $url_alias;
+}

+ 3 - 0
tripal_pub/theme/tripal_pub_admin.tpl.php

@@ -63,6 +63,7 @@ been added to Chado database.
 </ol>
 <h3>Features of this Module:</h3>
 <ul>
+     
   <li><p><b>Add/Edit/Delete Publications</b>: Publications can be maually added <?php  l('here', 'node/add/chado-pub') ?>. 
     Once added, publications can be modified or deleted by clicking the Edit tab at the top of a publication page.</p></li>
   
@@ -77,6 +78,8 @@ been added to Chado database.
     This will allow the site to import publications which have been newly added to remote databases and which 
     are relative to the site.  Site administrators can <?php print l('see the list of importers', 'admin/tripal/tripal_pub/import_list') ?> 
     and edit, disable or delete the importers.</p></li>
+    
+  
 
 </ul>
 

+ 35 - 2
tripal_pub/tripal_pub.module

@@ -300,10 +300,11 @@ function chado_pub_access($op, $node, $account ) {
  *
  *
  */
-function chado_pub_insert($node) {
+function chado_pub_insert($node) { 
  
   // if a pub_id already exists for this node then it already exists in Chado and 
   // we get here because we are syncing the node.  Therefore, we can skip the insert
+  // but we always want to set the URL path alias to be the Chado pub ID
   if ($node->pub_id) {
     $pub['pub_id'] = $node->pub_id;
   }
@@ -471,9 +472,10 @@ function chado_pub_update($node) {
     // there is no way to handle revisions in Chado but leave
     // this here just to make not we've addressed it.
   }
-  
+ 
   // get the publication ID for this publication
   $pub_id = chado_get_id_for_node('pub', $node) ;
+  
   $properties = array(); // stores all of the properties we need to add
   $cross_refs = array(); // stores any cross references for this publication  
    
@@ -643,6 +645,9 @@ function chado_pub_load($node) {
   $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.title');
   $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.volumetitle');  
   $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.uniquename');;
+  
+  // set the URL path
+  $path = "pub/$pub_id";
 
   $additions = new stdClass();
   $additions->pub = $pub;
@@ -823,4 +828,32 @@ function tripal_pub_mail($key, &$message, $params) {
       $message['body'][] = $params['message'];
       break;
   }
+}
+
+/*
+ * 
+ */
+function tripal_pub_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
+  if ($node->type == 'chado_pub') {
+    switch ($op) {
+      case 'presave':                        
+        break;
+      case 'insert':
+        $pub_id = chado_get_id_for_node('pub', $node);
+        tripal_pub_set_pub_url($node, $pub_id);
+        break;
+      case 'load':
+        if (!$node->path) {          
+          $pub_id = chado_get_id_for_node('pub', $node);
+          $path = tripal_pub_set_pub_url($node, $pub_id);
+        }
+        break;
+      case 'update':
+        $pub_id = chado_get_id_for_node('pub', $node);
+        tripal_pub_set_pub_url($node, $pub_id);
+        break;
+      case 'view':
+        break;
+    }
+  }
 }