Browse Source

pub module can now insert/update/delete pubs. Base templates, pub type templates and teaser is working

Stephen Ficklin 11 years ago
parent
commit
97cdd4c4d1

+ 2 - 2
tripal_analysis/theme/tripal_analysis/tripal_analysis_base.tpl.php

@@ -91,7 +91,7 @@ $analysis = tripal_core_expand_chado_vars($analysis,'field','analysis.descriptio
   // once we have our table array structure defined, we call Drupal's theme_table()
   // function to generate the table.
   print theme_table($table); 
-  if (property_exists($analysis, 'description')) {  
-    print $analysis->description; 
+  if (property_exists($analysis, 'description')) { ?>
+    <div style="text-align: justify"><?php print $analysis->description; ?></div> <?php  
   } ?>
 </div>

+ 2 - 2
tripal_contact/theme/tripal_contact/tripal_contact_base.tpl.php

@@ -54,7 +54,7 @@ $contact = $variables['node']->contact; ?>
   // once we have our table array structure defined, we call Drupal's theme_table()
   // function to generate the table.
   print theme_table($table);
-  if (property_exists($contact, 'description')) {
-    print $contact->description;
+  if (property_exists($contact, 'description')) { ?>
+    <div style="text-align: justify"><?php print $contact->description; ?></div> <?php 
   } ?>
 </div>

+ 45 - 18
tripal_core/api/tripal_core_properties.api.inc

@@ -361,13 +361,23 @@ function tripal_core_delete_property_by_id($basetable, $record_id) {
  *   the actual field is only 255 characters. The 'contact_description' therefore should
  *   not be shown in the list of properties, even if present, because it is handled by
  *   a different form element.
+ * @param $include
+ *   An array of terms to pre-populate in the form.  This argument can be used to
+ *   add a default set of pre-populated properties regardless if they exist in the database
+ *   or not.  The array should be of the following form:
+ *     array(
+ *       array('cvterm' => $obj1, 'value' => $val1),
+ *       array('cvterm' => $obj2, 'value' => $val2),
+ *       ... etc
+ *     );
+ *   The 'cvterm' key should have as a value an object with these properties: 'name', 'cvterm_id', 'definition'. 
  * @param $instructions
  *   An additional set of instructions for the form properties.
  *   
  * @ingroup tripal_properties_api
  */
 function tripal_core_properties_form(&$form, &$form_state, $prop_table, $id_field, $cv_name,
-    $available_props, $id = NULL, $exclude = array(), $instructions = '') {
+    $available_props, $id = NULL, $exclude = array(), $include = array(), $instructions = '') {
   
   $d_removed      = array(); // lists removed properties
   $num_new        = 0;  // the number of new rows
@@ -407,7 +417,7 @@ function tripal_core_properties_form(&$form, &$form_state, $prop_table, $id_fiel
   // add in the properties from the Chado prop table (only pertains to existing analyses)
   if ($id) {
     tripal_core_properties_form_add_prop_table_props($prop_table, $id_field, $cv_name,
-      $form, $form_state, $id, $ranks, $d_removed, $exclude);
+      $form, $form_state, $id, $ranks, $d_removed, $exclude, $include);
   }
   
   // add in any new properties that have been added by the user through an AHAH callback
@@ -659,11 +669,14 @@ function tripal_core_properties_form_add_new_props(&$form, &$form_state, &$ranks
 
   return $num_properties;
 }
-/*
+/**
+ * This function queries the proper xxxprop table to look for existing values for the given
+ * $id.  It then adds these properties to the form for editing.  It also will incorporate
+ * extra properties that were specified manually by the caller.
  *
-*/
+ */
 function  tripal_core_properties_form_add_prop_table_props($prop_table, $id_field, $cv_name, 
-    &$form, $form_state, $id, &$ranks, &$d_removed, $exclude = array()) {
+    &$form, $form_state, $id, &$ranks, &$d_removed, $exclude = array(), $include = array()) {
 
   // get the existing properties
   $num_properties = 0;
@@ -672,21 +685,36 @@ function  tripal_core_properties_form_add_prop_table_props($prop_table, $id_fiel
     return;
   }
 
+  // create an array of properties so we can merge those in the database with those provided by the caller
+  $all_props = array();
+  foreach ($include as $prop) {
+    $all_props[] = $prop;
+  }
+  
+  // now merge in properties saved in the database
   $sql = "
     SELECT CVT.cvterm_id, CVT.name, CVT.definition, PP.value, PP.rank
     FROM {" . $prop_table . "} PP
       INNER JOIN {cvterm} CVT ON CVT.cvterm_id = PP.type_id
       INNER JOIN {cv} CV      ON CVT.cv_id     = CV.cv_id
-    WHERE 
-      PP.$id_field = :id AND 
+      WHERE
+      PP.$id_field = :id AND
       CV.name = '$cv_name'
-    ORDER BY CVT.name, PP.rank
-  ";
+      ORDER BY CVT.name, PP.rank
+      ";
   $props = chado_query($sql, array(':id' => $id));
   while ($prop = $props->fetchObject()) {
+    $all_props[] = array('cvterm' => $prop, 'value' => $prop->value);
+  }
+
+  // iterate through the properties
+  foreach ($all_props as $prop) {
 
-    $type_id = $prop->cvterm_id;
-    $rank = 0;
+    $type_id    = $prop['cvterm']->cvterm_id;
+    $value      = $prop['value'];
+    $name       = $prop['cvterm']->name;
+    $definition = $prop['cvterm']->definition;
+    $rank       = 0;
     if(array_key_exists($type_id, $ranks)) {
       $rank = count($ranks[$type_id]);
     }
@@ -697,7 +725,7 @@ function  tripal_core_properties_form_add_prop_table_props($prop_table, $id_fiel
       continue;
     }
     // skip any properties that should be excluded
-    if (count(array_intersect(array($prop->name), $exclude)) == 1) {
+    if (count(array_intersect(array($name), $exclude)) == 1) {
       continue;
     }
     if (array_key_exists('triggering_element', $form_state) and
@@ -706,22 +734,21 @@ function  tripal_core_properties_form_add_prop_table_props($prop_table, $id_fiel
       continue;
     }
 
-    $ranks[$type_id][$rank]['name']  = $prop->name;
+    $ranks[$type_id][$rank]['name']  = $name;
     $ranks[$type_id][$rank]['id']    = $type_id;
-    $ranks[$type_id][$rank]['value'] = $prop->value;
-    $ranks[$type_id][$rank]['definition']  = $prop->definition;
+    $ranks[$type_id][$rank]['value'] = $value;
     $num_properties++;
     $rows = 1;
 
     $form['properties']['table'][$type_id][$rank]["prop_id-$type_id-$rank"] = array(
-      '#markup'        => $prop->name,
+      '#markup'        => $name,
     );
     $form['properties']['table'][$type_id][$rank]["prop_value-$type_id-$rank"] = array(
       '#type'          => 'textarea',
-      '#default_value' => $prop->value,
+      '#default_value' => $value,
       '#cols'          => 50,
       '#rows'          => $rows,
-      '#description'   => $prop->definition,
+      '#description'   => $definition,
     );
 
     $form['properties']['table'][$type_id][$rank]["remove-$type_id-$rank"] = array(

+ 4 - 14
tripal_cv/api/tripal_cv.api.inc

@@ -226,7 +226,6 @@ function tripal_cv_get_cvterm_by_name($name, $cv_id = NULL, $cv_name = 'tripal')
        'cv_id' => $cv_id,
     );
     $options = array(
-      'statement_name' => 'sel_cvterm_nacv',
       'case_insensitive_columns' => array('name')
     );
     $r = tripal_core_chado_select('cvterm', array('*'), $values, $options);
@@ -237,22 +236,13 @@ function tripal_cv_get_cvterm_by_name($name, $cv_id = NULL, $cv_name = 'tripal')
       'cv_id' => array(
         'name' => $cv_name,
       ),
-    );    
-
-    $options = array(
-      'statement_name' => 'sel_cvterm_nacv',
-      'case_insensitive_columns' => array('name')
     );
-    $r = tripal_core_chado_select('cvterm', array('*'), $values, $options);      
+    $options = array('case_insensitive_columns' => array('name'));
+    $r = tripal_core_chado_select('cvterm', array('*'), $values, $options);
   }
   else {
-    $values = array(
-      'name' => $name,
-    );
-    $options = array(
-      'statement_name' => 'sel_cvterm_na',
-      'case_insensitive_columns' => array('name')
-    );
+    $values = array('name' => $name);
+    $options = array('case_insensitive_columns' => array('name'));
     $r = tripal_core_chado_select('cvterm', array('*'), $values, $options);
   }
 

+ 57 - 41
tripal_pub/includes/pub_form.inc

@@ -19,20 +19,16 @@ function chado_pub_form($node, $form_state) {
   // set form field defaults
   $pub_id      = null;
   $title       = '';
-  $volumetitle = '';
-  $volume      = '';
-  $series_name = '';
-  $issue       = '';
   $pyear       = '';
-  $pages       = '';
-  $miniref     = '';
   $uniquename  = '';
   $type_id     = '';
   $is_obsolete = '';
-  $publisher   = '';
-  $pubplace    = '';
-  
   
+  // some of the fields in the pub table should show up in the properties 
+  // form elements to make the form more seemless.  We will add them
+  // to this array.
+  $more_props = array();
+
   // if we are editing an existing node then the pub is already part of the node
   if (property_exists($node, 'pub')) {
     $pub = $node->pub;
@@ -41,19 +37,11 @@ function chado_pub_form($node, $form_state) {
     $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.uniquename');
     $pub_id = $pub->pub_id;
     
-    $title       = $node->title;
-    $volumetitle = $node->volumetitle;
-    $volume      = $node->volume;
-    $series_name = $node->series_name;
-    $issue       = $node->issue;
-    $pyear       = $node->pyear;
-    $pages       = $node->pages;
-    $miniref     = $node->miniref;
-    $uniquename  = $node->uniquename;
-    $type_id     = $node->type_id;
-    $is_obsolete = $node->is_obsolete;
-    $publisher   = $node->publisher;
-    $pubplace    = $node->pubplace;
+    $title       = $pub->title;
+    $pyear       = $pub->pyear;
+    $uniquename  = $pub->uniquename;
+    $type_id     = $pub->type_id->cvterm_id;
+    $is_obsolete = $pub->is_obsolete;
     
     // if the obsolete value is set by the database then it is in the form of
     // 't' or 'f', we need to convert to 1 or 0
@@ -65,40 +53,68 @@ function chado_pub_form($node, $form_state) {
       '#type' => 'value',
       '#value' => $pub->pub_id,
     );
+    
+    // get fields from the pub table and convert them to properties. We will add these to the $more_props
+    // array which gets passed in to the tripal_core_properties_form() API call further down
+    if ($pub->volumetitle) {
+      $cvterm = tripal_cv_get_cvterm_by_name('Volume Title', NULL, 'tripal_pub');
+      $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->volumetitle);
+    }
+    if ($pub->volume) {
+      $cvterm = tripal_cv_get_cvterm_by_name('Volume', NULL, 'tripal_pub');
+      $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->volume);
+    }
+    if ($pub->series_name) {
+      switch ($pub->type_id->name) {
+        case 'Journal Article':
+          $cvterm = tripal_cv_get_cvterm_by_name('Journal Name', NULL, 'tripal_pub');
+          $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->series_name);
+          break;
+        case 'Conference Proceedings':
+          $cvterm = tripal_cv_get_cvterm_by_name('Conference Name', NULL, 'tripal_pub');
+          $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->series_name);
+          break;
+        default:
+          $cvterm = tripal_cv_get_cvterm_by_name('Series Name', NULL, 'tripal_pub');
+          $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->series_name);
+      }
+    }
+    if ($pub->issue) {
+      $cvterm = tripal_cv_get_cvterm_by_name('Issue', NULL, 'tripal_pub');
+      $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->issue);
+    }
+    if ($pub->pages) {
+      $cvterm = tripal_cv_get_cvterm_by_name('Pages', NULL, 'tripal_pub');
+      $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->pages);
+    }
+    if ($pub->miniref) {
+      // not sure what to do with this one
+    }
+    if ($pub->publisher) {
+      $cvterm = tripal_cv_get_cvterm_by_name('Publisher', NULL, 'tripal_pub');
+      $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->publisher);
+    }
+    if ($pub->pubplace) {
+      $cvterm = tripal_cv_get_cvterm_by_name('Published Location', NULL, 'tripal_pub');
+      $more_props[] = array('cvterm' => $cvterm, 'value' => $pub->pages);
+    }
   }
   // if we are re constructing the form from a failed validation or ajax callback
   // then use the $form_state['values'] values
   if (array_key_exists('values', $form_state)) {
     $title        = $form_state['values']['pubtitle'];
-    $volumetitle  = $form_state['values']['volumetitle'];
-    $volume       = $form_state['values']['volume'];
-    $series_name  = $form_state['values']['series_name'];
-    $issue        = $form_state['values']['issue'];
     $pyear        = $form_state['values']['pyear'];
-    $pages        = $form_state['values']['pages'];
-    $miniref      = $form_state['values']['miniref'];
     $uniquename   = $form_state['values']['uniquename'];
     $type_id      = $form_state['values']['type_id'];
     $is_obsolete  = $form_state['values']['is_obsolete'];
-    $publisher    = $form_state['values']['publisher'];
-    $pubplace     = $form_state['values']['pubplace'];
   }
   // if we are re building the form from after submission (from ajax call) then
   // the values are in the $form_state['input'] array
   if (array_key_exists('input', $form_state) and !empty($form_state['input'])) {
     $title        = $form_state['input']['pubtitle'];
-    $volumetitle  = $form_state['input']['volumetitle'];
-    $volume       = $form_state['input']['volume'];
-    $series_name  = $form_state['input']['series_name'];
-    $issue        = $form_state['input']['issue'];
-    $pyear        = $form_state['input']['pyear'];
-    $pages        = $form_state['input']['pages'];
-    $miniref      = $form_state['input']['miniref'];
     $uniquename   = $form_state['input']['uniquename'];
     $type_id      = $form_state['input']['type_id'];
     $is_obsolete  = $form_state['input']['is_obsolete'];
-    $publisher    = $form_state['input']['publisher'];
-    $pubplace     = $form_state['input']['pubplace'];
   }
  
   // a drupal title can only be 255 characters, but the Chado title can be much longer.
@@ -200,7 +216,7 @@ function chado_pub_form($node, $form_state) {
   $exclude = array("Citation");
   $instructions = '';
   tripal_core_properties_form($form, $form_state, 'pubprop', 'pub_id', 'tripal_pub',
-    $properties, $pub_id, $exclude, $instructions);
+    $properties, $pub_id, $exclude, $more_props, $instructions);
 
   return $form;
 
@@ -309,7 +325,7 @@ function chado_pub_validate($node, $form, &$form_state) {
     if((strcmp(strtolower($pub[0]->title), strtolower($title)) == 0) and
        (strcmp(strtolower($pub[0]->series_name), strtolower($series_name)) == 0) and
        ($pub[0]->type_id == $type_id) and
-       ($pub[0]->year == $pyear)) {
+       ($pub[0]->pyear == $pyear)) {
       $skip_duplicate_check = 1;
     }
 

+ 140 - 52
tripal_pub/theme/tripal_pub/pub_types/conference_proceedings.inc

@@ -1,52 +1,140 @@
-<table id="tripal_pub-table-base" class="tripal_pub-table tripal-table tripal-table-vert">
-  <tr class="tripal_pub-table-even-row tripal-table-even-row">
-    <th>Title</th>
-    <td><?php
-      if ($url) {
-        print l(htmlspecialchars($pub->title), $url, array('attributes' => array('target' => '_blank')));          
-      }
-      elseif ($dbxref->db_id->urlprefix) { 
-        print l(htmlspecialchars($pub->title), $dbxref->db_id->urlprefix . $dbxref->accession, array('attributes' => array('target' => '_blank')));             
-      } 
-      else {
-        print htmlspecialchars($pub->title); 
-      }?>
-    </td>
-  </tr>
-  <tr class="tripal_pub-table-odd-row tripal-table-odd-row">
-    <th>Authors</th>
-    <td><?php print $authors->value ? $authors->value : 'N/A'; ?></td>
-  </tr>
-  <tr class="tripal_pub-table-even-row tripal-table-even-row">
-    <th>Type</th>
-    <td><?php print $pub->type_id->name; ?></td>
-  </tr>
-  <tr class="tripal_pub-table-odd-row tripal-table-odd-row">
-    <th nowrap>Conference Name</th>
-    <td><?php print $pub->series_name; ?></td>
-  </tr>
-  <tr class="tripal_pub-table-even-row tripal-table-even-row">
-    <th>Volume</th>
-    <td><?php print $pub->volume ? $pub->volume : 'N/A'; ?></td>
-  </tr>
-  <tr class="tripal_pub-table-odd-row tripal-table-odd-row">
-    <th>Issue</th>
-    <td><?php print $pub->issue ? $pub->issue : 'N/A'; ?></td>
-  </tr>
-  <tr class="tripal_pub-table-even-row tripal-table-even-row">    
-    <th>Year</th>
-    <td><?php print $pub->pyear; ?></td>
-  </tr>
-  <tr class="tripal_pub-table-odd-row tripal-table-odd-row">
-    <th>Page(s)</th>
-    <td><?php print $pub->pages ? $pub->pages : 'N/A'; ?></td>
-  </tr>
-  <tr class="tripal_pub-table-even-row tripal-table-even-row">
-    <th>Citation</th>
-    <td><?php print htmlspecialchars($citation->value); ?></td>
-  </tr>
-  <tr class="tripal_pub-table-odd-row tripal-table-odd-row">
-    <th>Abstract</th>
-    <td style="text-align:justify;"><?php print htmlspecialchars($abstract->value) ? $abstract->value : 'N/A'; ?></td>
-  </tr>
-</table>
+<?php 
+// the $headers array is an array of fields to use as the colum headers. 
+// additional documentation can be found here 
+// https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+// This table for the analysis has a vertical header (down the first column)
+// so we do not provide headers here, but specify them in the $rows array below.
+$headers = array();
+
+// the $rows array contains an array of rows where each row is an array
+// of values for each column of the table in that row.  Additional documentation
+// can be found here:
+// https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7 
+$rows = array();
+
+// Title row
+$title = '';
+if ($url) {
+  $title =  l(htmlspecialchars($pub->title), $url, array('attributes' => array('target' => '_blank')));
+}
+elseif ($dbxref and $dbxref->db_id->urlprefix) {
+  $title =  l(htmlspecialchars($pub->title), $dbxref->db_id->urlprefix . $dbxref->accession, array('attributes' => array('target' => '_blank')));
+}
+else {
+  $title =  htmlspecialchars($pub->title);
+}
+$rows[] = array(
+  array(
+    'data' => 'Title',
+    'header' => TRUE
+  ),
+  $title,
+);
+// Authors row
+$rows[] = array(
+  array(
+    'data' => 'Authors',
+    'header' => TRUE
+  ),
+  $authors_list,
+);
+// Type row
+$rows[] = array(
+  array(
+    'data' => 'Type',
+    'header' => TRUE
+  ),
+  $pub->type_id->name,
+);
+// Media Title
+$rows[] = array(
+  array(
+    'data' => 'Conference Name',
+    'header' => TRUE,
+    'nowrap' => 'nowrap'
+  ),
+  $pub->series_name,
+);
+// Volume
+$rows[] = array(
+  array(
+    'data' => 'Volume',
+    'header' => TRUE
+  ),
+  $pub->volume ? $pub->volume : 'N/A',
+);
+// Issue
+$rows[] = array(
+  array(
+    'data' => 'Issue',
+    'header' => TRUE
+  ),
+  $pub->issue ? $pub->issue : 'N/A'
+);
+// Year
+$rows[] = array(
+  array(
+    'data' => 'Year',
+    'header' => TRUE
+  ),
+  $pub->pyear
+);
+// Pages
+$rows[] = array(
+  array(
+    'data' => 'Page(s)',
+    'header' => TRUE
+  ),
+  $pub->pages ? $pub->pages : 'N/A'
+);
+// Citation row
+$rows[] = array(
+  array(
+    'data' => 'Citation',
+    'header' => TRUE
+  ),
+  htmlspecialchars($citation->value)
+);
+// allow site admins to see the pub ID
+if (user_access('access administration pages')) {
+  // Pub ID
+  $rows[] = array(
+    array(
+      'data' => 'Pub ID',
+      'header' => TRUE
+    ),
+    $pub->pub_id
+  );
+}
+// Is Obsolete Row
+if($pub->is_obsolete == TRUE){
+  $rows[] = array(
+    array(
+      'data' => '<div class="tripal_pub-obsolete">This publication is obsolete</div>',
+      'colspan' => 2
+    ),
+  );
+}
+// 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:
+// https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+$table = array(
+  'header' => $headers,
+  'rows' => $rows,
+  'attributes' => array(
+    'id' => 'tripal_pub-table-base',
+  ),
+  'sticky' => FALSE,
+  'caption' => '',
+  'colgroups' => array(),
+  'empty' => '',
+);
+
+// once we have our table array structure defined, we call Drupal's theme_table()
+// function to generate the table.
+print theme_table($table);
+if ($abstract_text) { ?>
+  <p><b>Abstract</b></p>
+  <div style="text-align: justify"><?php print $abstract_text; ?></div> <?php 
+} 

+ 140 - 52
tripal_pub/theme/tripal_pub/pub_types/journal_article.inc

@@ -1,52 +1,140 @@
-<table id="tripal_pub-table-base" class="tripal_pub-table tripal-table tripal-table-vert">
-  <tr class="tripal_pub-table-even-row tripal-table-even-row">
-    <th>Title</th>
-    <td><?php
-      if ($url) {
-        print l(htmlspecialchars($pub->title), $url, array('attributes' => array('target' => '_blank')));          
-      }
-      elseif ($dbxref->db_id->urlprefix) { 
-        print l(htmlspecialchars($pub->title), $dbxref->db_id->urlprefix . $dbxref->accession, array('attributes' => array('target' => '_blank')));             
-      } 
-      else {
-        print htmlspecialchars($pub->title); 
-      }?>
-    </td>
-  </tr>
-  <tr class="tripal_pub-table-odd-row tripal-table-odd-row">
-    <th>Authors</th>
-    <td><?php print $authors->value ? $authors->value : 'N/A'; ?></td>
-  </tr>
-  <tr class="tripal_pub-table-even-row tripal-table-even-row">
-    <th>Type</th>
-    <td><?php print $pub->type_id->name; ?></td>
-  </tr>
-  <tr class="tripal_pub-table-odd-row tripal-table-odd-row">
-    <th nowrap>Journal Name</th>
-    <td><?php print $pub->series_name; ?></td>
-  </tr>
-  <tr class="tripal_pub-table-even-row tripal-table-even-row">
-    <th>Volume</th>
-    <td><?php print $pub->volume ? $pub->volume : 'N/A'; ?></td>
-  </tr>
-  <tr class="tripal_pub-table-odd-row tripal-table-odd-row">
-    <th>Issue</th>
-    <td><?php print $pub->issue ? $pub->issue : 'N/A'; ?></td>
-  </tr>
-  <tr class="tripal_pub-table-even-row tripal-table-even-row">    
-    <th>Year</th>
-    <td><?php print $pub->pyear; ?></td>
-  </tr>
-  <tr class="tripal_pub-table-odd-row tripal-table-odd-row">
-    <th>Page(s)</th>
-    <td><?php print $pub->pages ? $pub->pages : 'N/A'; ?></td>
-  </tr>
-  <tr class="tripal_pub-table-even-row tripal-table-even-row">
-    <th>Citation</th>
-    <td><?php print htmlspecialchars($citation->value); ?></td>
-  </tr>
-  <tr class="tripal_pub-table-odd-row tripal-table-odd-row">
-    <th>Abstract</th>
-    <td style="text-align:justify;"><?php print htmlspecialchars($abstract->value) ? $abstract->value : 'N/A'; ?></td>
-  </tr>
-</table>
+<?php 
+// the $headers array is an array of fields to use as the colum headers. 
+// additional documentation can be found here 
+// https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+// This table for the analysis has a vertical header (down the first column)
+// so we do not provide headers here, but specify them in the $rows array below.
+$headers = array();
+
+// the $rows array contains an array of rows where each row is an array
+// of values for each column of the table in that row.  Additional documentation
+// can be found here:
+// https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7 
+$rows = array();
+
+// Title row
+$title = '';
+if ($url) {
+  $title =  l(htmlspecialchars($pub->title), $url, array('attributes' => array('target' => '_blank')));
+}
+elseif ($dbxref and $dbxref->db_id->urlprefix) {
+  $title =  l(htmlspecialchars($pub->title), $dbxref->db_id->urlprefix . $dbxref->accession, array('attributes' => array('target' => '_blank')));
+}
+else {
+  $title =  htmlspecialchars($pub->title);
+}
+$rows[] = array(
+  array(
+    'data' => 'Title',
+    'header' => TRUE
+  ),
+  $title,
+);
+// Authors row
+$rows[] = array(
+  array(
+    'data' => 'Authors',
+    'header' => TRUE
+  ),
+  $authors_list,
+);
+// Type row
+$rows[] = array(
+  array(
+    'data' => 'Type',
+    'header' => TRUE
+  ),
+  $pub->type_id->name,
+);
+// Media Title
+$rows[] = array(
+  array(
+    'data' => 'Journal Name',
+    'header' => TRUE,
+    'nowrap' => 'nowrap'
+  ),
+  $pub->series_name,
+);
+// Volume
+$rows[] = array(
+  array(
+    'data' => 'Volume',
+    'header' => TRUE
+  ),
+  $pub->volume ? $pub->volume : 'N/A',
+);
+// Issue
+$rows[] = array(
+  array(
+    'data' => 'Issue',
+    'header' => TRUE
+  ),
+  $pub->issue ? $pub->issue : 'N/A'
+);
+// Year
+$rows[] = array(
+  array(
+    'data' => 'Year',
+    'header' => TRUE
+  ),
+  $pub->pyear
+);
+// Pages
+$rows[] = array(
+  array(
+    'data' => 'Page(s)',
+    'header' => TRUE
+  ),
+  $pub->pages ? $pub->pages : 'N/A'
+);
+// Citation row
+$rows[] = array(
+  array(
+    'data' => 'Citation',
+    'header' => TRUE
+  ),
+  htmlspecialchars($citation->value)
+);
+// allow site admins to see the pub ID
+if (user_access('access administration pages')) {
+  // Pub ID
+  $rows[] = array(
+    array(
+      'data' => 'Pub ID',
+      'header' => TRUE
+    ),
+    $pub->pub_id
+  );
+}
+// Is Obsolete Row
+if($pub->is_obsolete == TRUE){
+  $rows[] = array(
+    array(
+      'data' => '<div class="tripal_pub-obsolete">This publication is obsolete</div>',
+      'colspan' => 2
+    ),
+  );
+}
+// 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:
+// https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+$table = array(
+  'header' => $headers,
+  'rows' => $rows,
+  'attributes' => array(
+    'id' => 'tripal_pub-table-base',
+  ),
+  'sticky' => FALSE,
+  'caption' => '',
+  'colgroups' => array(),
+  'empty' => '',
+);
+
+// once we have our table array structure defined, we call Drupal's theme_table()
+// function to generate the table.
+print theme_table($table);
+if ($abstract_text) { ?>
+  <p><b>Abstract</b></p>
+  <div style="text-align: justify"><?php print $abstract_text; ?></div> <?php 
+} 

+ 116 - 36
tripal_pub/theme/tripal_pub/pub_types/patent.inc

@@ -1,36 +1,116 @@
-<table id="tripal_pub-table-base" class="tripal_pub-table tripal-table tripal-table-vert">
-  <tr class="tripal_pub-table-even-row tripal-table-even-row">
-    <th>Title</th>
-    <td><?php
-      if ($url) {
-        print l(htmlspecialchars($pub->title), $url, array('attributes' => array('target' => '_blank')));          
-      }
-      elseif ($dbxref->db_id->urlprefix) { 
-        print l(htmlspecialchars($pub->title), $dbxref->db_id->urlprefix . $dbxref->accession, array('attributes' => array('target' => '_blank')));             
-      } 
-      else {
-        print htmlspecialchars($pub->title); 
-      }?>
-    </td>
-  </tr>
-  <tr class="tripal_pub-table-odd-row tripal-table-odd-row">
-    <th>Authors</th>
-    <td><?php print $authors->value ? $authors->value : 'N/A'; ?></td>
-  </tr>
-  <tr class="tripal_pub-table-even-row tripal-table-even-row">
-    <th>Type</th>
-    <td><?php print $pub->type_id->name; ?></td>
-  </tr>
-  <tr class="tripal_pub-table-odd-row tripal-table-odd-row">    
-    <th>Year</th>
-    <td><?php print $pub->pyear; ?></td>
-  </tr>
-  <tr class="tripal_pub-table-even-row tripal-table-even-row">
-    <th>Citation</th>
-    <td><?php print htmlspecialchars($citation->value); ?></td>
-  </tr>
-  <tr class="tripal_pub-table-odd-row tripal-table-odd-row">
-    <th>Abstract</th>
-    <td style="text-align:justify;"><?php print htmlspecialchars($abstract->value) ? $abstract->value : 'N/A'; ?></td>
-  </tr>
-</table>
+<?php 
+// the $headers array is an array of fields to use as the colum headers. 
+// additional documentation can be found here 
+// https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+// This table for the analysis has a vertical header (down the first column)
+// so we do not provide headers here, but specify them in the $rows array below.
+$headers = array();
+
+// the $rows array contains an array of rows where each row is an array
+// of values for each column of the table in that row.  Additional documentation
+// can be found here:
+// https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7 
+$rows = array();
+
+// Title row
+$title = '';
+if ($url) {
+  $title =  l(htmlspecialchars($pub->title), $url, array('attributes' => array('target' => '_blank')));
+}
+elseif ($dbxref and $dbxref->db_id->urlprefix) {
+  $title =  l(htmlspecialchars($pub->title), $dbxref->db_id->urlprefix . $dbxref->accession, array('attributes' => array('target' => '_blank')));
+}
+else {
+  $title =  htmlspecialchars($pub->title);
+}
+$rows[] = array(
+  array(
+    'data' => 'Title',
+    'header' => TRUE
+  ),
+  $title,
+);
+// Authors row
+$rows[] = array(
+  array(
+    'data' => 'Authors',
+    'header' => TRUE
+  ),
+  $authors_list,
+);
+// Type row
+$rows[] = array(
+  array(
+    'data' => 'Type',
+    'header' => TRUE
+  ),
+  $pub->type_id->name,
+);
+// Media Title
+$rows[] = array(
+  array(
+    'data' => 'Patent',
+    'header' => TRUE,
+    'nowrap' => 'nowrap'
+  ),
+  $pub->series_name,
+);
+// Year
+$rows[] = array(
+  array(
+    'data' => 'Year',
+    'header' => TRUE
+  ),
+  $pub->pyear
+);
+// Citation row
+$rows[] = array(
+  array(
+    'data' => 'Citation',
+    'header' => TRUE
+  ),
+  htmlspecialchars($citation->value)
+);
+// allow site admins to see the pub ID
+if (user_access('access administration pages')) {
+  // Pub ID
+  $rows[] = array(
+    array(
+      'data' => 'Pub ID',
+      'header' => TRUE
+    ),
+    $pub->pub_id
+  );
+}
+// Is Obsolete Row
+if($pub->is_obsolete == TRUE){
+  $rows[] = array(
+    array(
+      'data' => '<div class="tripal_pub-obsolete">This publication is obsolete</div>',
+      'colspan' => 2
+    ),
+  );
+}
+// 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:
+// https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+$table = array(
+  'header' => $headers,
+  'rows' => $rows,
+  'attributes' => array(
+    'id' => 'tripal_pub-table-base',
+  ),
+  'sticky' => FALSE,
+  'caption' => '',
+  'colgroups' => array(),
+  'empty' => '',
+);
+
+// once we have our table array structure defined, we call Drupal's theme_table()
+// function to generate the table.
+print theme_table($table);
+if ($abstract_text) { ?>
+  <p><b>Abstract</b></p>
+  <div style="text-align: justify"><?php print $abstract_text; ?></div> <?php 
+} 

+ 53 - 18
tripal_pub/theme/tripal_pub/tripal_pub_base.tpl.php

@@ -1,4 +1,17 @@
 <?php
+/*
+ * Note, the table generated by this template that lists the publication
+ * details is generic. It can be customized to look different for different
+ * publication types.  To create a custom template for a given type, create a 
+ * new file in the pub_types directory.  Name the file using the name of the
+ * type. The name must be all lower-case and spaces should be replaced with
+ * and underscore symbol.  For example, to create a custom table for the
+ * "Conference Proceedings", create the file conference_proceedings.inc inside
+ * of the pub_types folder.  Cut and paste the code below that generates the table
+ * structure into the new file.  Then edit to your liking.
+ * 
+ */
+
 $pub = $variables['node']->pub;
 
 // expand the title
@@ -24,7 +37,7 @@ $values = array(
 );
 $abstract = tripal_core_generate_chado_var('pubprop', $values); 
 $abstract = tripal_core_expand_chado_vars($abstract, 'field', 'pubprop.value');
-$abstract_text = 'N/A';
+$abstract_text = '';
 if ($abstract) {
   $abstract_text = htmlspecialchars($abstract->value);
 }
@@ -73,22 +86,24 @@ if (count($urls) > 0) {
 
 <div id="tripal_pub-base-box" class="tripal_pub-info-box tripal-info-box">
   <div class="tripal_pub-info-box-title tripal-info-box-title">Publication Details</div>
-  <!-- <div class="tripal_pub-info-box-desc tripal-info-box-desc"></div> -->
-  <?php 
-  if ($pub->is_obsolete == 't') { ?>
-    <div class="tripal_pub-obsolete">This publication is obsolete</div> <?php 
-  }  
+  <!-- <div class="tripal_pub-info-box-desc tripal-info-box-desc"></div> --> <?php
 
   // to simplify the template, we have a subdirectory named 'pub_types'.  This directory
   // should have include files each specific to a publication type. If the type is 
   // not present then the base template will be used, otherwise the template in the
   // include file is used.
   $inc_name = strtolower(preg_replace('/ /', '_', $pub->type_id->name)) . '.inc';
-  $inc_path = realpath('./') . '/' . drupal_get_path('theme', 'tripal') . "/tripal_pub/pub_types/$inc_name";
+  $inc_path = drupal_realpath(drupal_get_path('module', 'tripal_pub') . "/theme/tripal_pub/pub_types/$inc_name");
   if (file_exists($inc_path)) {
     require_once "pub_types/$inc_name";  
   } 
   else { 
+    // ========================================================================
+    // TO CUSTOMIZE A SPECIFIC PUBLICATION TYPE, CUT-AND-PASTE THE CODE
+    // BELOW INTO A NEW FILE WITH THE SAME NAME AS THE TYPE (SEE INSTRUCTIONS
+    // ABOVE), AND EDIT.
+    // ========================================================================
+    
     // the $headers array is an array of fields to use as the colum headers. 
     // additional documentation can be found here 
     // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
@@ -139,8 +154,9 @@ if (count($urls) > 0) {
     // Media Title
     $rows[] = array(
       array(
-        'data' => 'Type',
-        'header' => TRUE
+        'data' => 'Media Title',
+        'header' => TRUE,
+        'nowrap' => 'nowrap'
       ),
       $pub->series_name,
     );
@@ -184,15 +200,26 @@ if (count($urls) > 0) {
       ),
       htmlspecialchars($citation->value)
     );
-    // Abstract
-    $rows[] = array(
-      array(
-        'data' => 'Abstract',
-        'header' => TRUE
-      ),
-      $abstract_text
-    );
-
+    // allow site admins to see the pub ID
+    if (user_access('access administration pages')) {
+      // Pub ID
+      $rows[] = array(
+        array(
+          'data' => 'Pub ID',
+          'header' => TRUE
+        ),
+        $pub->pub_id
+      );
+    }
+    // Is Obsolete Row
+    if($pub->is_obsolete == TRUE){
+      $rows[] = array(
+        array(
+          'data' => '<div class="tripal_pub-obsolete">This publication is obsolete</div>',
+          'colspan' => 2
+        ),
+      );
+    }
     // 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:
@@ -212,5 +239,13 @@ if (count($urls) > 0) {
     // once we have our table array structure defined, we call Drupal's theme_table()
     // function to generate the table.
     print theme_table($table);
+    if ($abstract_text) { ?>
+      <p><b>Abstract</b></p>
+      <div style="text-align: justify"><?php print $abstract_text; ?></div> <?php 
+    } 
+    
+    // ========================================================================
+    // END OF CUT-AND-PASTE REGION
+    // ========================================================================
   } ?>
 </div>

+ 12 - 3
tripal_pub/tripal_pub.module

@@ -283,6 +283,13 @@ function tripal_pub_theme($existing, $type, $theme, $path) {
     'tripal_pub_search_form' => array(
       'arguments' => array('form'),
     ),
+    
+    // teaser
+    'tripal_pub_teaser' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_pub_teaser',
+      'path' => "$path/theme/tripal_pub",
+    ),
   );
 
   return $items;
@@ -488,13 +495,14 @@ function chado_pub_insert($node) {
         $publisher = $value;
         unset($properties[$name]);
       }
-      elseif ($name == "Journal Name" or $name == "Conference Name") {
+      elseif ($name == "Series Name" or $name == "Journal Name" or $name == "Conference Name") {
         $series_name = $value;
         unset($properties[$name]);
       }
       elseif ($name == "Journal Country" or $name == "Published Location") {
         $pubplace = $value;
-        unset($properties[$name]);
+        // allow this property to go into the pubprop table so we don't loose info
+        // so don't unset it. But it will also go into the pub.pubplace field
       }
       elseif ($name == "Publication Dbxref") {
         // we will add the cross-references to the pub_dbxref table
@@ -676,7 +684,8 @@ function chado_pub_update($node) {
       }
       elseif ($name == "Journal Country" or $name == "Published Location") {
         $pubplace = $value;
-        unset($properties[$name]);
+        // allow this property to go into the pubprop table so we don't loose info
+        // so don't unset it. But it will also go into the pub.pubplace field
       }
       elseif ($name == "Publication Dbxref") {
         // we will add the cross-references to the pub_dbxref table