Browse Source

Fixing tripal_library theming

spficklin 14 years ago
parent
commit
86dbc81afa

+ 99 - 40
theme_tripal/node-chado_library.tpl.php

@@ -1,45 +1,104 @@
 <?php
+// Purpose: This template provides the layout of the library node (page)
+//   using the same templates used for the various library content blocks.
+//
+// To Customize the Libray Node Page:
+//   - This Template: customize basic layout and which elements are included
+//   - Using Panels: Override the node page using Panels3 and place the blocks
+//       of content as you please. This method requires no programming. See
+//       the Tripal User Guide for more details
+//   - Block Templates: customize the content/layout of each block of stock 
+//       content. These templates are found in the tripal_stock subdirectory
+//
+// Variables Available:
+//   - $node: a standard object which contains all the fields associated with
+//       nodes including nid, type, title, taxonomy. It also includes stock
+//       specific fields such as stock_name, uniquename, stock_type, synonyms,
+//       properties, db_references, object_relationships, subject_relationships,
+//       organism, etc.
+//   NOTE: For a full listing of fields available in the node object the
+//       print_r $node line below or install the Drupal Devel module which 
+//       provides an extra tab at the top of the node page labelled Devel
+?>
 
+<?php
+ //uncomment this line to see a full listing of the fields avail. to $node
+ //print '<pre>'.print_r($variables,TRUE).'</pre>';
+drupal_add_css('./tripal-node-templates.css');
+$library  = $variables['node']->library;
+//dpm($library);
 ?>
 
-   <?php if ($picture) { print $picture; }?>
-    
-   <div class="node<?php if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
-
-   <?php if ($page == 0) { ?><h2 class="nodeTitle"><a href="<?php print $node_url?>"><?php print $title?></a>
-	<?php global $base_url;
-	if ($sticky) { print '<img src="'.base_path(). drupal_get_path('theme','sanqreal').'/img/sticky.gif" alt="sticky icon" class="sticky" />'; } ?>
-	</h2><?php }; ?>
-    
-	<?php if (!$teaser): ?>
-   	<?php if ($submitted): ?>
-        <div class="metanode"><p><?php print t('') .'<span class="author">'. theme('username', $node).'</span>' . t(' - Posted on ') . '<span class="date">'.format_date($node->created, 'custom', "d F Y").'</span>'; ?></p></div>
-      <?php endif;?>
-      <div>
-      <!-- tripal library theme -->
-         <table>
-            <tr><th>Unique Name</th><td><?php print $node->uniquename;?></td></tr>
-            <tr><th>Organism</th><td><?php print $node->genus.' '.$node->species.' ('.$node->common_name.')';?></td></tr>
-            <tr><th>Libraray Type</th><td><?php print $node->library_type?></td></tr>
-            <!--<tr><th>Number of ESTs</th><td><?php print $node->sequence_num?></td></tr>-->
-            <tr><th>Description</th><td><?php print $node->library_description?></td></tr>
-         </table>
-      <!-- End of tripal library theme-->
-	  </div> 
-    <?php endif; ?>
-    
-    <div class="content"><?php print $content?></div>
-    
-    <?php if (!$teaser): ?>
-    <?php if ($links) { ?><div class="links"><?php print $links?></div><?php }; ?>
-    <?php endif; ?>
-    
-    <?php if ($teaser): ?>
-    <?php if ($links) { ?><div class="linksteaser"><div class="links"><?php print $links?></div></div><?php }; ?>
-    <?php endif; ?>
-    
-    <?php if (!$teaser): ?>
-    <?php if ($terms) { ?><div class="taxonomy"><span><?php print t('tags') ?></span> <?php print $terms?></div><?php } ?>
-    <?php endif; ?>
-  </div>
+<?php if ($teaser) { 
+  include('tripal_library/tripal_library_teaser.tpl.php'); 
+} else { ?>
+
+<script type="text/javascript">
+if (Drupal.jsEnabled) {
+   $(document).ready(function() {
+      // hide all tripal info boxes at the start
+      $(".tripal-info-box").hide();
+ 
+      // iterate through all of the info boxes and add their titles
+      // to the table of contents
+      $(".tripal-info-box-title").each(function(){
+        var parent = $(this).parent();
+        var id = $(parent).attr('id');
+        var title = $(this).text();
+        $('#tripal_library_toc_list').append('<li><a href="#'+id+'" class="tripal_library_toc_item">'+title+'</a></li>');
+      });
+
+      // when a title in the table of contents is clicked, then
+      // show the corresponding item in the details box
+      $(".tripal_library_toc_item").click(function(){
+         $(".tripal-info-box").hide();
+         href = $(this).attr('href');
+         $(href).fadeIn('slow');
+         // we want to make sure our table of contents and the details
+         // box stay the same height
+         $("#tripal_library_toc").height($(href).parent().height());
+         return false;
+      }); 
+
+      // we want the base details to show up when the page is first shown 
+      // unless the user specified a specific block
+      var block = window.location.href.match(/\?block=.*/);
+      if(block != null){
+         block_title = block.toString().replace(/\?block=/g,'');
+         $("#tripal_library-"+block_title+"-box").show();
+      } else {
+         $("#tripal_library-base-box").show();
+      }
+
+      $("#tripal_organism_toc").height($("#tripal_library-base-box").parent().height());
+   });
+}
+</script>
+
+<div id="tripal_library_details" class="tripal_details">
+
+   <!-- Basic Details Theme -->
+   <?php include('tripal_library/tripal_library_base.tpl.php'); ?>
+
+   <!-- External References -->
+   <?php include('tripal_library/tripal_library_references.tpl.php'); ?>
+
+   <!-- Properties -->
+   <?php include('tripal_library/tripal_library_properties.tpl.php'); ?>
+
+   <!-- Synonyms -->
+   <?php include('tripal_library/tripal_library_synonyms.tpl.php'); ?>
+
+
+   <?php print $content ?>
+</div>
+
+<!-- Table of contents -->
+<div id="tripal_library_toc" class="tripal_toc">
+   <div id="tripal_library_toc_title" class="tripal_toc_title">Resources</div>
+   <ul id="tripal_library_toc_list" class="tripal_toc_list">
+
+   </ul>
+</div>
 
+<?php } ?>

+ 3 - 3
theme_tripal/tripal_feature/tripal_feature_base.tpl.php

@@ -11,7 +11,7 @@ $feature  = $variables['node']->feature;
       <div class="tripal_feature-obsolete">This feature is obsolete</div>
    <?php }?>
    <table id="tripal_feature-base-table" class="tripal_feature-table tripal-table tripal-table-vert">
-      <tr class="tripal_feature-table-odd-row tripal-table-even-row">
+      <tr class="tripal_feature-table-even-row tripal-table-even-row">
         <th>Name</th>
         <td><?php print $feature->name; ?></td>
       </tr>
@@ -19,7 +19,7 @@ $feature  = $variables['node']->feature;
         <th nowrap>Unique Name</th>
         <td><?php print $feature->uniquename; ?></td>
       </tr>
-      <tr class="tripal_feature-table-odd-row tripal-table-even-row">
+      <tr class="tripal_feature-table-even-row tripal-table-even-row">
         <th>Internal ID</th>
         <td><?php print $feature->feature_id; ?></td>
       </tr>
@@ -27,7 +27,7 @@ $feature  = $variables['node']->feature;
         <th>Length</th>
         <td><?php print $feature->seqlen ?></td>
       </tr>
-      <tr class="tripal_feature-table-odd-row tripal-table-even-row">
+      <tr class="tripal_feature-table-even-row tripal-table-even-row">
         <th>Type</th>
         <td><?php print $feature->type_id->name; ?></td>
       </tr>

+ 10 - 1
theme_tripal/tripal_feature/tripal_feature_libraries.tpl.php

@@ -41,7 +41,16 @@ if (!$library_features) {
           }
         ?>
         </td>
-        <td><?php print $library_feature->library_id->type_id->name?></td>
+        <td><?php 
+            if ($library_feature->library_id->type_id->name == 'cdna_library') {
+               print 'cDNA';
+            } else if ($library_feature->library_id->type_id->name == 'bac_library') {
+               print 'BAC';
+            } else {
+               print $library_feature->library_id->type_id->name;
+            }
+          ?>
+        </td>
       </tr>
       <?php
       $i++;  

+ 1 - 0
tripal_analysis/tripal_analysis.api.inc

@@ -130,6 +130,7 @@ function tripal_analysis_get_property($analysis_id,$property){
       ),
    );
    $results = tripal_core_generate_chado_var('analysisprop',$values);
+   $results = tripal_core_expand_chado_vars($results,'field','analysisprop.value');
    return $results;
 }
 /**

+ 2 - 1
tripal_feature/tripal_feature.module

@@ -495,7 +495,8 @@ function chado_feature_update($node){
             'type_id' => $type[0]->cvterm_id,
             'md5checksum' => md5($residues)
          );
-         $org_status = tripal_core_chado_update('feature', $match,$values); 
+         $status = tripal_core_chado_update('feature', $match,$values); 
+
          // add the genbank synonyms
          chado_feature_add_synonyms($node->synonyms,$feature_id);
       }    

+ 105 - 0
tripal_library/tripal_library.api.inc

@@ -103,3 +103,108 @@ function tripal_library_chado_libraryprop_schema() {
   
   return $description;
 }
+/**
+* Adds a single property to an existing library record.
+*
+* @ingroup tripal_api
+*/
+function tripal_library_get_property($library_id,$property){
+   // construct the array of values to be inserted  
+   $values = array (
+      'library_id' => $library_id,
+      'type_id' => array ( 
+         'cv_id' => array (
+            'name' => 'tripal',
+         ),
+         'name' => $property,
+         'is_obsolete' => 0
+      ),
+   );
+   $results = tripal_core_generate_chado_var('libraryprop',$values);
+   $results = tripal_core_expand_chado_vars($results,'field','libraryprop.value');
+   return $results;
+}
+/**
+* Adds a single property to an existing library record.
+*
+* @ingroup tripal_api
+*/
+function tripal_library_insert_property($library_id,$property,$value,$update_if_present = 0){
+   // first see if the property already exists, if so we can't insert
+   $prop = tripal_library_get_property($library_id,$property);
+   if(count($prop)>0){
+      if($update_if_present){
+        return tripal_library_update_property($library_id,$property,$value) ;
+      } else {
+        return FALSE;
+      }
+   }
+
+   // construct the array of values to be inserted  
+   $values = array (
+      'library_id' => $library_id,
+      'type_id' => array ( 
+         'cv_id' => array (
+            'name' => 'tripal',
+         ),
+         'name' => $property,
+         'is_obsolete' => 0
+      ),
+      'value' => $value, 
+      'rank' => 0,
+   );
+   return tripal_core_chado_insert('libraryprop',$values);
+}
+/**
+* Adds a single property to an existing library record.
+*
+* @ingroup tripal_api
+*/
+function tripal_library_update_property($library_id,$property,$value,$insert_if_missing = 0){
+
+   // first see if the property is missing (we can't update a missing property
+   $prop = tripal_library_get_property($library_id,$property);
+   if(count($prop)==0){
+      if($insert_if_missing){
+        return tripal_library_insert_property($library_id,$property,$value);
+      } else {
+        return FALSE;
+      }
+   }
+
+   // construct the array that will match the exact record to update
+   $match = array (
+      'library_id' => $library_id,
+      'type_id' => array ( 
+         'cv_id' => array (
+            'name' => 'tripal',
+         ),
+         'name' => $property,
+      ),
+   );
+   // construct the array of values to be updated
+   $values = array (      
+      'value' => $value, 
+   );
+   return tripal_core_chado_update('libraryprop',$match,$values);
+}
+/**
+* Adds a single property to an existing library record.
+*
+* @ingroup tripal_api
+*/
+function tripal_library_delete_property($library_id,$property){
+
+
+   // construct the array that will match the exact record to update
+   $match = array (
+      'library_id' => $library_id,
+      'type_id' => array ( 
+         'cv_id' => array (
+            'name' => 'tripal',
+         ),
+         'name' => $property,
+      ),
+   );
+   return tripal_core_chado_delete('libraryprop',$match);
+}

+ 91 - 143
tripal_library/tripal_library.module

@@ -744,49 +744,44 @@ function chado_library_validate($node){
  *  of type 'chado_library' and inserts the necessary information.
  */
 function chado_library_insert($node){
-   // If this library already exists then don't create it in chado
-   // e.g. when tripal_library_sync_libraries call this function
-   $l_sql= "SELECT library_id ".
-           "FROM {Library} ".
-           "WHERE organism_id = %d ".
-           "AND uniquename = '%s' ".
-           "AND type_id = %d";
-   $previous_db = tripal_db_set_active('chado');
-   $library = db_fetch_object(db_query($l_sql, $node->organism_id,
-   $node->uniquename, $node->type_id));
-   $libid = $node->library_id;
-   
-   // Create the chado library entry only if it doesn't exist
-   if (!$library) {
-      $sql = "INSERT INTO {library} (organism_id, name, uniquename, type_id)".
-             "VALUES(%d,'%s','%s', ".
-             "  (SELECT cvterm_id ".
-             "   FROM {CVTerm} CVT ".
-             "   INNER JOIN CV ON CVT.cv_id = CV.cv_id ".
-             "   WHERE CV.name = 'tripal' and CVT.name = '%s'))";
-      db_query($sql,$node->organism_id,$node->title,$node->uniquename,
-      $node->library_type);
-
-      // get the library id for this library
-      $sql = "SELECT library_id ".
-             "FROM {library} ".
-             "WHERE uniquename = '%s'";
-      $lib = db_fetch_object(db_query($sql, $node->uniquename));
-      $libid = $lib->library_id;
-   }
 
-   // Now use drupal database
-   tripal_db_set_active($previous_db);
-
-   // Next add the node to the drupal table
-   $sql = "INSERT INTO {chado_library} (nid, vid, library_id) ".
-          "VALUES (%d, %d, %d)";
-   db_query($sql, $node->nid, $node->vid, $libid);
+   // get the library type id
+   $values = array(
+      'cv_id' => array(
+         'name' => 'tripal'
+      ),
+      'name' => $node->library_type
+   );
+   $type = tripal_core_chado_select('cvterm',array('cvterm_id'),$values);
 
-   // Finally add the remaining properties if the library doesn't exist in Chado
-   if (!$library) {
-      tripal_library_add_properties($node,$libid);
-   }
+   $values = array(
+      'name' => $node->title,
+      'uniquename' => $node->uniquename,
+      'organism_id' => $node->organism_id,
+      'type_id' => $type[0]->cvterm_id
+   );
+   $library = tripal_core_chado_insert('library', $values);
+   if ($library) {
+       // add the description property
+      tripal_library_insert_property($library['library_id'],'library_description',$node->library_description);
+
+      // make sure the entry for this feature doesn't already exist in the chado_feature table
+      // if it doesn't exist then we want to add it.
+      $library_id = chado_get_id_for_node('library',$node) ;
+      if(!$library_id){
+         // next add the item to the drupal table
+         $sql = "INSERT INTO {chado_library} (nid, vid, library_id) ".
+                "VALUES (%d, %d, %d)";
+         db_query($sql,$node->nid,$node->vid,$library['library_id']);
+      }
+   } else {
+		drupal_set_message('Unable to add library.', 'warning');
+		watchdog('tripal_library', 
+			'Insert feature: Unable to create library where values: %values', 
+			array('%values' => print_r($values, TRUE)),
+			WATCHDOG_WARNING
+		);
+	}
 }
 /*******************************************************************************
  * Update nodes
@@ -795,59 +790,34 @@ function chado_library_update($node){
    if($node->revision){
       // TODO -- decide what to do about revisions
    } else {
-      // Get the library_id for this node:
-      $sql = "SELECT library_id ".
-             "FROM {chado_library} ".
-             "WHERE vid = %d";
-      $lib = db_fetch_object(db_query($sql, $node->vid));
-
-      // Update the chado library table
-      $sql = "UPDATE {library} ".
-             "  SET name = '%s', uniquename = '%s', organism_id = %d, ".
-             "    type_id = (SELECT cvterm_id ".
-             "               FROM {CVTerm} CVT ".
-             "               INNER JOIN CV ON CVT.cv_id = CV.cv_id ".
-             "               WHERE CV.name = 'local' and CVT.name = '%s') ".
-             "WHERE library_id = %d ";
-      $previous_db = tripal_db_set_active('chado');  // use chado database
-      db_query($sql, $node->title, $node->uniquename, $node->organism_id,
-      $node->library_type, $lib->library_id);
-      tripal_db_set_active($previous_db);  // now use drupal database
-      tripal_library_add_properties($node,$lib->library_id);
-      tripal_library_add_taxonomy($node,$lib->library_id);
-   }
-}
+      $library_id = chado_get_id_for_node('library',$node) ;
+
+      // get the library type id
+      $values = array(
+         'cv_id' => array(
+            'name' => 'tripal'
+         ),
+         'name' => $node->library_type
+      );
+      $type = tripal_core_chado_select('cvterm',array('cvterm_id'),$values);
 
-/*******************************************************************************
- * Add properties to the specified library.
- */
-function tripal_library_add_properties ($node,$library_id){
-   // Use chado database
-   $previous_db = tripal_db_set_active('chado');
+      // update the library record
+      $match = array(
+         'library_id' => $library_id,
+      );
+      $values = array(
+         'name' => $node->title,
+         'uniquename' => $node->uniquename,
+         'organism_id' => $node->organism_id,
+         'type_id' => $type[0]->cvterm_id
+      );
+      $status = tripal_core_chado_update('library', $match,$values); 
 
-   // Now remove any properties for this library and add the new properties
-   // provided by the this posting.
-   $sql = "DELETE FROM {libraryprop} ".
-          "WHERE library_id = %d";
-   db_query($sql,$library_id);
-
-   // Now add each property one at a time
-   $sql = "INSERT INTO {libraryprop} (library_id, type_id, value) ".
-          "VALUES (%d,".
-          "        (SELECT cvterm_id ".
-          "         FROM {CVTerm} CVT ".
-          "           INNER JOIN CV ON CVT.cv_id = CV.cv_id ".
-          "         WHERE CV.name = 'tripal' and CVT.name = '%s'), ".
-          "        '%s')";
-
-   if($node->library_description){
-      db_query($sql,$library_id,'library_description',
-      $node->library_description);
+      tripal_library_insert_property($library_id,'library_description',$node->library_description);
    }
-
-   // now use drupal database
-   tripal_db_set_active($previous_db);
 }
+
+
 /*******************************************************************************
  * Add the library as a taxonomy term for associating with library_features
  */
@@ -902,14 +872,34 @@ function tripal_library_add_taxonomy ($node,$library_id){
  *  a form.  This function creates the form that will be used for this.
  */
 function chado_library_form ($node){
-   $type = node_get_types('type',$node);
    $form = array();
 
+   $library = $node->library;
+   
+   // get the default values
+   $uniquename = $node->uniquename;
+   if(!$uniquename){
+     $uniquename = $library->uniquename;
+   }
+   $library_type = $node->library_type;
+   if(!$library_type){
+      $library_type = $library->type_id->name;
+   }
+   $organism_id = $node->organism_id;
+   if(!$organism_id){
+      $organism_id = $library->organism_id->organism_id;
+   }
+   $library_description = $node->library_description;
+   if(!$library_description){
+     $libprop = tripal_library_get_property($library->library_id,'library_description');
+     $library_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(
       '#type' => 'value',
-      '#value' => $node->library_id,
+      '#value' => $library->library_id,
    );
 
    $form['title']= array(
@@ -927,7 +917,7 @@ function chado_library_form ($node){
       '#title'         => t('Unique Library Name'),
       '#description'   => t('Please enter a unique name for this library'),
       '#required'      => TRUE,
-      '#default_value' => $node->uniquename,
+      '#default_value' => $uniquename,
       '#weight'        => 2
    );
 
@@ -946,7 +936,7 @@ function chado_library_form ($node){
       '#type'        => t('select'),
       '#description' => t("Choose the library type."),
       '#required'    => TRUE,
-      '#default_value' => $node->library_type,
+      '#default_value' => $library_type,
       '#options'     => $library_types,
       '#weight'      => 3
    );
@@ -970,7 +960,7 @@ function chado_library_form ($node){
      '#description' => t("Choose the organism with which this library is ".
                          "associated."),
      '#required'    => TRUE,
-     '#default_value' => $node->organism_id,
+     '#default_value' => $organism_id,
      '#options'     => $organisms,
      '#weight'      => 4,
    );
@@ -980,15 +970,10 @@ function chado_library_form ($node){
       '#title'         => t('Library Description'),
       '#description'   => t('A brief description of the library'),
       '#required'      => TRUE,
-      '#default_value' => $node->library_description,
+      '#default_value' => $library_description,
       '#weight'        => 5
    );
 
-   //Save the number of EST so it will show up in preview
-   $form['sequence_num'] = array(
-      '#type' => 'value',
-      '#value' => $node->sequence_num,
-   );
    return $form;
 }
 /************************************************************************
@@ -1051,50 +1036,13 @@ function tripal_library_sync_libraries ($library_id = NULL, $job_id = NULL){
  *  to add auxiliary data to the node object.
  */
 function chado_library_load($node){
-   $sql = 'SELECT library_id FROM {chado_library} WHERE vid = %d';
-   $map = db_fetch_object(db_query($sql, $node->vid));
-   $additions->library_id = $map->library_id;
-   $previous_db = tripal_db_set_active('chado');  // use chado database
-
-   // get information about this library
-   $sql = "SELECT L.organism_id, L.uniquename, CVT.name as type_name ".
-          "FROM {Library} L ".
-          "INNER JOIN CVTerm CVT ON CVT.cvterm_id = L.type_id ".
-          "WHERE library_id = %d";
-   $library = db_fetch_object(db_query($sql, $map->library_id));
-   $additions->uniquename = $library->uniquename;
-   $additions->library_type = $library->type_name;
-   $additions->organism_id = $library->organism_id;
-
-   $sql = "SELECT genus, species, common_name ".
-          "FROM {organism} O ".
-          "INNER JOIN library L ".
-          "ON L.organism_id = O.organism_id ".
-          "WHERE L.library_id = %d";
-   $organism = db_fetch_object(db_query($sql,$map->library_id));
-   $additions->genus = $organism->genus;
-   $additions->species = $organism->species;
-   $additions->common_name = $organism->common_name;
-
-   $sql = "SELECT LP.value ".
-          "FROM {libraryProp} LP ".
-          "WHERE LP.library_id = %d ";
-   $desc = db_fetch_object(db_query($sql, $map->library_id))->value;
-   if ($desc) {
-      $additions->library_description = $desc;
-   } else {
-      $additions->library_description = "NA";
-   }
+   // get the feature details from chado
+   $library_id = chado_get_id_for_node('library',$node);
 
-   // get the feature counts.  This is dependent on a materialized view
-   // installed with the library module
-   if ($map->library_id) {
-      $sql = "SELECT num_features FROM {library_feature_count} ".
-      		 "WHERE Library_id = $map->library_id";
-      $additions->num_features = db_fetch_object(db_query($sql, $map->library_id))->num_features;
-   }
+   $values = array('library_id' => $library_id);
+   $library = tripal_core_generate_chado_var('library',$values);
 
-   tripal_db_set_active($previous_db);  // now use drupal database
+   $additions->library = $library;
    return $additions;
 
 }