Browse Source

Merge branch '7.x-2.x' of git.drupal.org:sandbox/spficklin/1337878 into 7.x-2.x

Lacey Sanderson 11 years ago
parent
commit
260671ddc3

+ 4 - 0
tripal_analysis/tripal_analysis.install

@@ -700,6 +700,10 @@ function chado_expand_var($object, $type, $to_expand, $table_options = array())
         return $object;
       }
       $foreign_table_desc = chado_get_schema($foreign_table);
+      
+      // TODO: if we don't get a foreign_table (which could happen of a custom table
+      // is not correctly defined or the table name is mispelled then we should return
+      // gracefully.
 
       // BASE CASE: If it's connected to the base table via a FK constraint
       // then we have all the information needed to expand it now

+ 6 - 1
tripal_core/api/tripal_core.custom_tables.api.inc

@@ -139,7 +139,12 @@ function chado_create_custom_table($table, $schema, $skip_creation = 1) {
     // drop the table we'll recreate it with the new schema
     try {
       chado_query('DROP TABLE {' . $table . '}');
-      db_create_table('chado.' . $table, $schema);
+      // remove any 'referring_tables' from the array as the db_create_table doesn't use that
+      $new_schema = $schema;
+      if (array_key_exists('referring_tables', $new_schema)) {
+        unset($new_schema['referring_tables']);
+      }
+      db_create_table('chado.' . $table, $new_schema);
       $recreated = 1;
     }
     catch (Exception $e) {

+ 4 - 5
tripal_core/includes/custom_tables.inc

@@ -184,12 +184,11 @@ function tripal_custom_tables_form($form, &$form_state = NULL, $table_id = NULL)
     // set the default values.  If there is a value set in the
     // form_state then let's use that, otherwise, we'll pull
     // the values from the database
-    $default_schema = $form_state['values']['schema'];
-    $default_force_drop = $form_state['values']['force_drop'];
-
-    if (!$default_table_name) {
-      $default_table = $custom_table->table_name;
+    if (array_key_exists('values', $form_state)) {
+      $default_schema     = $form_state['values']['schema'];
+      $default_force_drop = $form_state['values']['force_drop'];
     }
+
     if (!$default_schema) {
       $default_schema = var_export(unserialize($custom_table->schema), 1);
       $default_schema = preg_replace('/=>\s+\n\s+array/', '=> array', $default_schema);

+ 2 - 2
tripal_core/tripal_core.module

@@ -356,7 +356,7 @@ function tripal_core_menu() {
   $items['admin/tripal/schema/custom_tables/edit/%'] = array(
     'title' => 'Edit Custom Table',
     'page callback' => 'drupal_get_form',
-    'page arguments' => array('tripal_custom_tables_form', 4),
+    'page arguments' => array('tripal_custom_tables_form', 5),
     'access arguments' => array('administer tripal'),
     'type' => MENU_CALLBACK,
   );
@@ -560,7 +560,7 @@ function tripal_core_node_view_alter(&$build) {
   $node = $build['#node'];
   $toc = array();
   $toc_html = '';
-
+  
   // if we are looking at a Tripal node template then we want to
   // make some changes to each block of content so that we can associate
   // a table of contents and add administrator and curator messages

+ 10 - 17
tripal_cv/api/tripal_cv.api.inc

@@ -142,11 +142,12 @@ function tripal_get_cv_select_options() {
  * Retrieves a chado controlled vocabulary term variable
  *
  * @param $identifier
- *   An array with the key stating what the identifier is. Supported keys (only on of the
- *   following unique keys is required):
+ *   An array with the key stating what the identifier is. Supported keys (only one of the
+ *   following unique keys are required):
  *    - cvterm_id: the chado cv.cvterm_id primary key
- *    - name: the chado cv.name field (assume unique)
+ *    - name: the chado cvterm.name field (assume unique)
  *   There are also some specially handled keys. They are:
+ *    - cv_id:  an integer indicating the cv_id or an array with 'name' => the name of the cv.
  *    - synonym: an array with 'name' => the name of the synonym of the cvterm you want
  *        returned; 'cv_id' => the cv_id of the synonym; 'cv_name' => the name of the cv
  *        of the synonym
@@ -178,26 +179,18 @@ function tripal_get_cvterm($identifiers, $options = array()) {
 
   // Error Checking of parameters
   if (!is_array($identifiers)) {
-    tripal_report_error(
-      'tripal_cv_api',
-      TRIPAL_ERROR,
+    tripal_report_error('tripal_cv_api', TRIPAL_ERROR,
       "tripal_get_cvterm: The identifier passed in is expected to be an array with the key
         matching a column name in the cvterm table (ie: cvterm_id or name). You passed in %identifier.",
-      array(
-        '%identifier'=> print_r($identifiers, TRUE)
-      )
+      array('%identifier'=> print_r($identifiers, TRUE))
     );
   }
   elseif (empty($identifiers)) {
-    tripal_report_error(
-      'tripal_cv_api',
-      TRIPAL_ERROR,
+    tripal_report_error('tripal_cv_api', TRIPAL_ERROR,
       "tripal_get_cvterm: You did not pass in anything to identify the cvterm you want. The identifier
         is expected to be an array with the key matching a column name in the cvterm table
         (ie: cvterm_id or name). You passed in %identifier.",
-      array(
-        '%identifier'=> print_r($identifiers, TRUE)
-      )
+      array('%identifier'=> print_r($identifiers, TRUE))
     );
   }
 
@@ -437,7 +430,7 @@ function tripal_insert_cv($name, $definition) {
  *
  * @ingroup tripal_cv_api
  */
-function tripal_insert_cvterm($term, $options) {
+function tripal_insert_cvterm($term, $options = array()) {
 
   // Set Defaults
   if (isset($term['cv_name'])) {
@@ -852,7 +845,7 @@ function tripal_autocomplete_cvterm($cv_id, $string = '') {
   $sql = "
     SELECT cvterm_id, name
     FROM {cvterm}
-    WHERE cv_id = :cv_id and name like :name
+    WHERE cv_id = :cv_id and lower(name) like lower(:name)
     ORDER by name
     LIMIT 25 OFFSET 0
   ";

+ 6 - 0
tripal_example/includes/tripal_example.admin.inc

@@ -17,6 +17,11 @@ function tripal_example_admin_examples_listing() {
   $breadcrumb[] = l('Examples', 'admin/tripal/chado/tripal_example');
   drupal_set_breadcrumb($breadcrumb);
 
+  
+  // EXPLANATION:  Typically for all Tripal modules the home administrative
+  // page for the module contains a search form to help the adminstrator
+  // locate records.  The following example code adds a default View to
+  // the page
   /*
   // Add the view
   $view = views_embed_view('tripal_example_admin_examples','default');
@@ -33,6 +38,7 @@ function tripal_example_admin_examples_listing() {
     $output .= '</ul>';
   }
   */
+  $output = 'Typically a search view goes here';  
 
   return $output;
 }

+ 86 - 36
tripal_example/includes/tripal_example.chado_node.inc

@@ -139,15 +139,24 @@ function chado_example_form($node, &$form_state) {
 
 
   // SET FORM DEFAULTS
-  //---------------------------------------------
+  //---------------------------------------------  
+  $example      = null;   // holds the example object record
+  $example_id   = null;   // when editing an example record we'll have an example_id
+  
+  // initialize the defaults for the form fields
+  $uniquename   = '';
+  $example_type = '';
+  $organism_id  = '';
+  $description  = '';
   
   // if we are editing an existing node then the 'example' record from Chado
   // is already part of the node, so we set the defaults from that object
   if (property_exists($node, 'example')) {
     $example = $node->example;
-    $example = chado_expand_var($example, 'field', 'example.residues');
     $example_id   = $example->example_id;
     $uniquename   = $example->uniquename;
+    $description  = $example->description;
+    $organism_id  = $example->organism_id;
 
     // keep track of the example id
     $form['example_id'] = array(
@@ -160,19 +169,21 @@ function chado_example_form($node, &$form_state) {
   if (array_key_exists('values', $form_state)) {
      $uniquename   = $form_state['values']['uniquename'];
      $example_type = $form_state['values']['example_type'];
-
+     $description  = $form_state['values']['description'];
+     $organism_id  = $form_state['values']['organism_id'];
   }
   // 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'])) {
      $uniquename   = $form_state['input']['uniquename'];
      $example_type = $form_state['input']['example_type'];
+     $organism_id  = $form_state['input']['organism_id'];
   }
     
   
   // FORM ELEMENTS 
   //---------------------------------------------
-  $form['uniquename']= array(
+  $form['uniquename'] = array(
     '#type' => 'textfield',
     '#title' => t('Unique Name'),
     '#required' => TRUE,
@@ -186,9 +197,9 @@ function chado_example_form($node, &$form_state) {
   $type_cv = tripal_get_default_cv('example', 'type_id');
   $cv_id = $type_cv->cv_id;
   $form['example_type'] = array(
-    '#title'       => t('Feature Type'),
+    '#title'       => t('Example Type'),
     '#type'        => 'textfield',
-    '#description' => t("Choose the example type."),
+    '#description' => t("Choose the example type (e.g. Test Type)."),
     '#required'    => TRUE,
     '#default_value' => $example_type,
     '#autocomplete_path' => "admin/tripal/chado/tripal_cv/cvterm/auto_name/$cv_id",
@@ -204,6 +215,14 @@ function chado_example_form($node, &$form_state) {
     '#default_value' => $organism_id,
     '#options'     => $organisms,
   );
+  
+  $form['description'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Description'),
+    '#required' => TRUE,
+    '#default_value' => $description,
+    '#description' => t('Enter a description for this example.'),
+  );
 
   // PROPERTIES FORM
   //---------------------------------------------
@@ -284,19 +303,38 @@ function chado_example_validate($node, $form, &$form_state) {
 
   // be sure to always trim text fields
   $node->uniquename   = trim($node->uniquename);
+  $node->description  = trim($node->description);
   
   // Validating for an update. If the 'nid' property is present in the node then
   // this is an update and validation can be different for updates
   if (property_exists($node, 'nid')) {
 
-    // if there is a problem with a field then you can set an error on the form
-    form_set_error('uniquename', t("example update cannot proceed. The example name '$node->uniquename' is not unique for this organism. Please provide a unique name for this example."));
+    // make sure the feature type is an allowed term
+    $type_cv = tripal_get_default_cv('example', 'type_id');
+    $type = tripal_get_cvterm(array(
+      'name' => $node->example_type,
+      'cv_id' => $type_cv->cv_id,
+    ));
+    if (!$type) {
+      form_set_error('feature_type', t("The feature type is not a valid name from the Sequence Ontology."));
+    }
+    
+    // TODO: also we should check that the unique constraint is not invalidated by
+    // changing either the type_id, organism_id or uniquename. 
   }
   // Validating for an insert
   else {
-
-    // if there is a problem with a field then you can set an error on the form
-    form_set_error('uniquename', t("example insert cannot proceed. The example name '$node->uniquename' already exists for this organism. Please provide a unique name for this example."));
+    // make sure the feature type is an allowed term
+    $type_cv = tripal_get_default_cv('example', 'type_id');
+    $type = tripal_get_cvterm(array(
+      'name' => $node->example_type,
+      'cv_id' => $type_cv->cv_id,
+    ));
+    if (!$type) {
+      form_set_error('feature_type', t("The feature type is not a valid name from the Sequence Ontology."));
+    }
+    
+    // TODO: also we should check that the unique constraint doesn't already exist
   }
 }
 
@@ -318,6 +356,14 @@ function chado_example_validate($node, $form, &$form_state) {
 function chado_example_insert($node) {
   // be sure to always trim text fields
   $node->uniquename   = trim($node->uniquename);
+  $node->description  = trim($node->description);
+  
+  // get the example type record
+  $type_cv = tripal_get_default_cv('example', 'type_id');
+  $type = tripal_get_cvterm(array(
+    'name' => $node->example_type,
+    'cv_id' => $type_cv->cv_id,
+  ));  
 
   // if there is an example_id in the $node object then this must be a sync so
   // we can skip adding the example as it is already there, although
@@ -327,9 +373,11 @@ function chado_example_insert($node) {
     // perform the insert using the tripal_core_chado_insert function();
     $values = array(
       'uniquename' => $node->uniquename,
-      'residues' => $residues,
+      'description' => $node->description,
+      'type_id' => $type->cvterm_id,
+      'organism_id' => $node->organism_id,
     );
-    $example = chado_select_record('example', array('*'), $values);
+    $example = chado_insert_record('example', $values);
     if (!$example) {
       drupal_set_message(t('Unable to add example.'), 'warning');
       tripal_report_error('tripal_example', TRIPAL_WARNING, 'Insert example: Unable to create example where values: %values',
@@ -338,7 +386,7 @@ function chado_example_insert($node) {
     }
 
     // get the example_id for linking Drupal node with Chado data
-    $example_id = $example->example_id;
+    $example_id = $example['example_id'];
 
     // Only add to other chado tables if the base record was inserted properly
     if ($example_id > 0) {
@@ -346,19 +394,19 @@ function chado_example_insert($node) {
       // If you implemented the properties form in chado_example_form then you need to
       // handle inserting these properties into your chado prop table.
       $details = array(
-        'property_table' => 'exampleprop',   // the name of the prop table
-        'base_table' => 'example',           // the name of your chado base table
-        'foreignkey_name' => 'example_id',   // the name of the key in your base table
-        'foreignkey_value' => $example_id    // the value of the example_id key
+        'property_table'   => 'exampleprop',   // the name of the prop table
+        'base_table'       => 'example',       // the name of your chado base table
+        'foreignkey_name'  => 'example_id',    // the name of the key in your base table
+        'foreignkey_value' => $example_id      // the value of the example_id key
       );
       chado_update_node_form_properties($node, $details);
 
       // If you implemented the dbxrefs form in chado_example_form then you need to
       // handle inserting these database references into your chado _dbxref table.
       $details = array(
-        'linking_table' => 'example_dbxref',   // the name of your _dbxref table
-        'foreignkey_name' => 'example_id',     // the name of the key in your base table
-        'foreignkey_value' => $example_id      // the value of the example_id key
+        'linking_table'    => 'example_dbxref', // the name of your _dbxref table
+        'foreignkey_name'  => 'example_id',     // the name of the key in your base table
+        'foreignkey_value' => $example_id       // the value of the example_id key
       );
       chado_update_node_form_dbxrefs($node, $details);
 
@@ -378,7 +426,7 @@ function chado_example_insert($node) {
 
   // Make sure the entry for this example doesn't already exist in the
   // chado_example table if it doesn't exist then we want to add it.
-  // $check_org_id = chado_get_id_from_nid('example', $node->nid);
+   $check_org_id = chado_get_id_from_nid('example', $node->nid);
   if (!$check_org_id) {
     $record = new stdClass();
     $record->nid = $node->nid;
@@ -401,6 +449,7 @@ function chado_example_insert($node) {
 function chado_example_update($node) {
   // be sure to always trim text fields
   $node->uniquename   = trim($node->uniquename);
+  $node->description  = trim($node->description);
 
   // use the chado_update_record() function to update the record
   $match = array(
@@ -524,7 +573,7 @@ function chado_example_load($nodes) {
     // include it here using the chado_expand_var() function.  In most
     // cases it is probably best to let the end-user decide if text fields should
     // be included by using this function in the templates.
-    $example = chado_expand_var($example, 'field', 'example.residues');
+    $example = chado_expand_var($example, 'field', 'example.description');
 
     // add the new example object to this node.
     $nodes[$nid]->example = $example;
@@ -600,8 +649,8 @@ function tripal_example_node_insert($node) {
     case 'chado_example':
       
       // if we do not have an record ID for this node then get it
-      if (!$node->example_id) {
-        $node->example_id = chado_get_id_for_node('example', $node);
+      if (!property_exists($node, 'example_id')) {
+        $node->example_id = chado_get_id_from_nid('example', $node->nid);
       }
 
       // set the URL for this example page
@@ -655,18 +704,18 @@ function tripal_example_node_update($node) {
  */
 function tripal_example_node_view($node, $view_mode, $langcode) {
   
-  // EXPLANATION: This function defines the content "blocks" that appear 
+  // EXPLANATION: This function defines the content "blocks" that appear
   // when thhe node is displayed. It is node type agnostic so we can add
   // content to any node type.  So, we use this function to add the content
   // from all of our theme templates onto our new node type. We will also
-  // use this function to add content to other node types.
+  // use this function to add content to other node types. 
           
   switch ($node->type) {
     case 'chado_example':
       // there are different ways a node can be viewed. Primarily Tripal
       // supports full page view and teaser view.
       if ($view_mode == 'full') {
-        
+
         // There is always a base template.  This is the template that
         // is first shown when the example node type is first displayed. 
         // if you are using the default Tripal node template, then you should
@@ -692,12 +741,12 @@ function tripal_example_node_view($node, $view_mode, $langcode) {
           '#tripal_toc_title' => 'Properties',
         );
         $node->content['tripal_example_references'] = array(
-          '#markup' => theme('tripal_feature_references', array('node' => $node)),
+          '#markup' => theme('tripal_example_references', array('node' => $node)),
           '#tripal_toc_id'    => 'references',
           '#tripal_toc_title' => 'Cross References',
         );
         $node->content['tripal_example_relationships'] = array(
-          '#markup' => theme('tripal_feature_relationships', array('node' => $node)),
+          '#markup' => theme('tripal_example_relationships', array('node' => $node)),
           '#tripal_toc_id'    => 'relationships',
           '#tripal_toc_title' => 'Relationships',
         );
@@ -713,12 +762,13 @@ function tripal_example_node_view($node, $view_mode, $langcode) {
     // you can add custom content to any node type by adding
     // content to the node in the same way as above.
     case 'chado_organism':
-      break;
-    case 'chado_library':
-      break;
-    case 'chado_stock':
-      break;
-    case 'chado_analysis':
+      if ($view_mode == 'full') {
+        $node->content['tripal_organism_examples'] = array(
+          '#markup' => theme('tripal_organism_examples', array('node' => $node)),
+          '#tripal_toc_id'    => 'examples',
+          '#tripal_toc_title' => 'Examples',
+        );
+      }
       break;
     // ... etc
   }

+ 84 - 0
tripal_example/theme/templates/tripal_example_base.tpl.php

@@ -1 +1,85 @@
 <?php
+$example  = $variables['node']->example;  ?>
+
+<div class="tripal_example-data-block-desc tripal-data-block-desc"></div> <?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();
+
+// Unique Name row
+$rows[] = array(
+  array(
+    'data' => 'Unique Name',
+    'header' => TRUE
+  ),
+  $example->uniquename
+);
+// Type row
+$rows[] = array(
+  array(
+    'data' => 'Type',
+    'header' => TRUE
+  ),
+  $example->type_id->name
+);
+// Organism row
+$organism = $example->organism_id->genus ." " . $example->organism_id->species ." (" . $example->organism_id->common_name .")";
+if (property_exists($example->organism_id, 'nid')) {
+  $organism = l("<i>" . $example->organism_id->genus . " " . $example->organism_id->species . "</i> (" . $example->organism_id->common_name .")", "node/".$example->organism_id->nid, array('html' => TRUE));
+} 
+$rows[] = array(
+  array(
+    'data' => 'Organism',
+    'header' => TRUE,
+  ),
+  $organism
+);
+
+// allow site admins to see the example ID
+if (user_access('administer tripal')) { 
+  // Feature ID
+  $rows[] = array(
+    array(
+      'data' => 'Example ID',
+      'header' => TRUE,
+      'class' => 'tripal-site-admin-only-table-row',
+    ),
+    array(
+      'data' => $example->example_id,
+      'class' => 'tripal-site-admin-only-table-row',
+    ),
+  );
+}
+
+
+// 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_example-table-base',
+    'class' => 'tripal-data-table'
+  ),
+  '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); ?>
+<div style="text-align: justify"><?php print $example->description ?></div>

+ 6 - 22
tripal_example/theme/templates/tripal_example_properties.tpl.php

@@ -1,33 +1,17 @@
 <?php
-$pub = $node->pub;
+$example = $node->example;
 
-// expand the pub to include the properties.
+// expand the example to include the properties.
 $options = array(
   'return_array' => 1,
   'order_by' => array('rank' => 'ASC'),
 );
-$pub = tripal_core_expand_chado_vars($pub,'table', 'pubprop', $options);
-$pubprops = $pub->pubprop;
+$example = tripal_core_expand_chado_vars($example,'table', 'exampleprop', $options);
+$exampleprops = $example->exampleprop;
 $properties = array();
-if (is_array($pubprops)) {
-  foreach ($pubprops as $property) {
-    // skip the following properties as those are already on other templates
-    if ($property->type_id->name == 'Abstract' or
-        $property->type_id->name == 'Citation' or
-        $property->type_id->name == 'Publication Dbxref' or
-        $property->type_id->name == 'Authors' or
-        $property->type_id->name == 'Structured Abstract Part')  {
-      continue;
-    }
-    $property = tripal_core_expand_chado_vars($property,'field','pubprop.value');
-    $properties[] = $property;
-  }
-}
-// we'll keep track of the keywords so we can lump them into a single row
-$keywords = array(); 
 
 if (count($properties)) { ?>
-  <div class="tripal_pub-data-block-desc tripal-data-block-desc">Additional details for this publication include:</div> <?php 
+  <div class="tripal_example-data-block-desc tripal-data-block-desc">Additional details for this example include:</div> <?php 
 
   // the $headers array is an array of fields to use as the colum headers.
   // additional documentation can be found here
@@ -70,7 +54,7 @@ if (count($properties)) { ?>
     'header' => $headers,
     'rows' => $rows,
     'attributes' => array(
-      'id' => 'tripal_pub-table-properties',
+      'id' => 'tripal_example-table-properties',
       'class' => 'tripal-data-table'
     ),
     'sticky' => FALSE,

+ 9 - 10
tripal_example/theme/templates/tripal_example_references.tpl.php

@@ -1,21 +1,20 @@
 <?php
-$pub = $variables['node']->pub;
+$example = $variables['node']->example;
 
-
-// expand the pub object to include the records from the pub_dbxref table
+// expand the example object to include the records from the example_dbxref table
 $options = array('return_array' => 1);
-$pub = tripal_core_expand_chado_vars($pub, 'table', 'pub_dbxref', $options);
-$pub_dbxrefs = $pub->pub_dbxref;
+$example = chado_expand_var($example, 'table', 'example_dbxref', $options);
+$example_dbxrefs = $example->example_dbxref;
 
 $references = array();
-if (count($pub_dbxrefs) > 0 ) {
-  foreach ($pub_dbxrefs as $pub_dbxref) {    
-    $references[] = $pub_dbxref->dbxref_id;
+if (count($example_dbxrefs) > 0 ) {
+  foreach ($example_dbxrefs as $example_dbxref) {    
+    $references[] = $example_dbxref->dbxref_id;
   }
 }
 
 if(count($references) > 0){ ?>
-  <div class="tripal_pub-data-block-desc tripal-data-block-desc">This publication is also available in the following databases:</div><?php 
+  <div class="tripal_example-data-block-desc tripal-data-block-desc">This example is also available in the following databases:</div><?php 
   
   // the $headers array is an array of fields to use as the colum headers.
   // additional documentation can be found here
@@ -54,7 +53,7 @@ if(count($references) > 0){ ?>
     'header' => $headers,
     'rows' => $rows,
     'attributes' => array(
-      'id' => 'tripal_pub-table-references',
+      'id' => 'tripal_example-table-references',
       'class' => 'tripal-data-table'
     ),
     'sticky' => FALSE,

+ 20 - 20
tripal_example/theme/templates/tripal_example_relationships.tpl.php

@@ -1,34 +1,34 @@
 <?php
 /* Typically in a Tripal template, the data needed is retrieved using a call to
  * tripal_core_expand_chado_vars function.  For example, to retrieve all 
- * of the pub relationships for this node, the following function call would be made:
+ * of the example relationships for this node, the following function call would be made:
  * 
- *   $pub = tripal_core_expand_chado_vars($pub,'table','pub_relationship');
+ *   $example = tripal_core_expand_chado_vars($example,'table','example_relationship');
  * 
  * However, this function call can be extremely slow when there are numerous relationships.
  * This is because the tripal_core_expand_chado_vars function is recursive and expands 
  * all data following the foreign key relationships tree.  Therefore, to speed retrieval
  * of data, a special variable is provided to this template:
  * 
- *   $pub->all_relationships;
+ *   $example->all_relationships;
  *   
  * This variable is an array with two sub arrays with the keys 'object' and 'subject'.  The array with
- * key 'object' contains relationships where the pub is the object, and the array with
- * the key 'subject' contains relationships where the pub is the subject
+ * key 'object' contains relationships where the example is the object, and the array with
+ * the key 'subject' contains relationships where the example is the subject
  */
-$pub = $variables['node']->pub;
+$example = $variables['node']->example;
 
-$all_relationships = $pub->all_relationships;
+$all_relationships = $example->all_relationships;
 $object_rels = $all_relationships['object'];
 $subject_rels = $all_relationships['subject'];
 
 if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
-  <div class="tripal_pub-data-block-desc tripal-data-block-desc"></div> <?php
+  <div class="tripal_example-data-block-desc tripal-data-block-desc"></div> <?php
   
   // first add in the subject relationships.  
   foreach ($subject_rels as $rel_type => $rels){
     foreach ($rels as $obj_type => $objects){ ?>
-      <p>This <?php print $pub->type_id->name;?> is <?php print $rel_type ?> the following <b><?php print $obj_type ?></b> pub(s): <?php
+      <p>This <?php print $example->type_id->name;?> is <?php print $rel_type ?> the following <b><?php print $obj_type ?></b> example(s): <?php
        
       // the $headers array is an array of fields to use as the colum headers.
       // additional documentation can be found here
@@ -42,7 +42,7 @@ if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
       $rows = array();
       
       foreach ($objects as $object){
-        // link the pub to it's node
+        // link the example to it's node
         $title = $object->record->object_id->title;
         if (property_exists($object->record, 'nid')) {
           $title = l($title, "node/" . $object->record->nid, array('attributes' => array('target' => "_blank")));
@@ -50,13 +50,13 @@ if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
         
         // get the citation
         $values = array(
-          'pub_id' => $object->record->object_id->pub_id,
+          'example_id' => $object->record->object_id->example_id,
           'type_id' => array(
             'name' => 'Citation',
           ),
         );
-        $citation = tripal_core_generate_chado_var('pubprop', $values);
-        $citation = tripal_core_expand_chado_vars($citation, 'field', 'pubprop.value');
+        $citation = tripal_core_generate_chado_var('exampleprop', $values);
+        $citation = tripal_core_expand_chado_vars($citation, 'field', 'exampleprop.value');
         
         $rows[] = array(
           $title . '<br>' . htmlspecialchars($citation->value),
@@ -70,7 +70,7 @@ if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
          'header' => $headers,
          'rows' => $rows,
          'attributes' => array(
-           'id' => 'tripal_pub-table-relationship-object',
+           'id' => 'tripal_example-table-relationship-object',
            'class' => 'tripal-data-table'
          ),
          'sticky' => FALSE,
@@ -90,7 +90,7 @@ if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
   // second add in the object relationships.  
   foreach ($object_rels as $rel_type => $rels){
     foreach ($rels as $subject_type => $subjects){?>
-      <p>The following <b><?php print $subjects[0]->record->subject_id->type_id->name ?></b> pub(s) are <?php print $rel_type ?> this <?php print $pub->type_id->name;?>: <?php 
+      <p>The following <b><?php print $subjects[0]->record->subject_id->type_id->name ?></b> example(s) are <?php print $rel_type ?> this <?php print $example->type_id->name;?>: <?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
@@ -103,7 +103,7 @@ if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
       $rows = array();
       
       foreach ($subjects as $subject){
-        // link the pub to it's node
+        // link the example to it's node
         $title = $subject->record->subject_id->title;
         if (property_exists($subject->record, 'nid')) {
           $title = l($title, "node/" . $subject->record->nid, array('attributes' => array('target' => "_blank")));
@@ -111,13 +111,13 @@ if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
         
         // get the citation
         $values = array(
-          'pub_id' => $subject->record->subject_id->pub_id,
+          'example_id' => $subject->record->subject_id->example_id,
           'type_id' => array(
             'name' => 'Citation',
           ),
         );
-        $citation = tripal_core_generate_chado_var('pubprop', $values);
-        $citation = tripal_core_expand_chado_vars($citation, 'field', 'pubprop.value');
+        $citation = tripal_core_generate_chado_var('exampleprop', $values);
+        $citation = tripal_core_expand_chado_vars($citation, 'field', 'exampleprop.value');
         
         $rows[] = array(
           $title . '<br>' . htmlspecialchars($citation->value),
@@ -131,7 +131,7 @@ if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
          'header' => $headers,
          'rows' => $rows,
          'attributes' => array(
-           'id' => 'tripal_pub-table-relationship-subject',
+           'id' => 'tripal_example-table-relationship-subject',
            'class' => 'tripal-data-table'
          ),
          'sticky' => FALSE,

+ 370 - 3
tripal_example/tripal_example.install

@@ -98,6 +98,10 @@ function tripal_example_install() {
   // then set it as a default vocabulary (see below).
   tripal_example_add_cvs();
   
+  
+  // add any controlled vocabulary terms
+  tripal_example_add_cvterms();
+  
   // EXPLANATION: Many tables in Chado have a 'type_id' column which allows for
   // association of controlled vocabulries to describe the record.   Chado
   // places no restrictions on which vocabularies can be used, but Tripal can
@@ -105,11 +109,16 @@ function tripal_example_install() {
   // example, the feature.type_id column will typically use the Sequence Ontology
   // In that case, we can use the tripal_set_default_cv() function to specify
   // the Sequence Ontology (sequence) as the default vocabulary.  
-  tripal_set_default_cv('example', 'type_id', 'sequence');
+  tripal_set_default_cv('example', 'type_id', 'example_type');
   tripal_set_default_cv('exampleprop', 'type_id', 'example_property');
   tripal_set_default_cv('example_relationship', 'type_id', 'example_relationship');
+  
+  // add any custom tables. For this case we will add an 'example' table to the
+  // chado schema
+  tripal_example_add_custom_tables();
 }
 
+
 /**
  * Implements hook_uninstall().
  * 
@@ -196,15 +205,373 @@ function tripal_example_add_mviews() {
 /**
  * Add cvs related to publications
  *
- * @ingroup tripal_pub
+ * @ingroup tripal_example
+ */
+function tripal_example_add_dbs() {
+  // EXPLANATION: use the tripal_db_add_db() function to add any
+  // external databases needed by your module.  If the database already
+  // exists then the function will gracefully return.
+  
+  tripal_db_add_db(
+    'example_db',
+    'An example database.'
+  );
+}
+/**
+ * Add cvs related to publications
+ *
+ * @ingroup tripal_example
  */
 function tripal_example_add_cvs() {
 
   // EXPLANATION: use the tripal_cv_add_cv() function to add any 
   // controlled vocabularies needed by your module.  If the vocabulary already
-  // exists then the function will gracefully return.  
+  // exists then the function will gracefully return.  Chado convensions
+  // use a singluar name for CV names (not plural)/
+  
+  tripal_cv_add_cv(
+    'example_property',
+    'Contains property terms for examples.'
+  );
+  
+  tripal_cv_add_cv(
+    'example_type',
+    'Contains terms describing types of examples.'
+  );
+  
+  tripal_cv_add_cv(
+   'example_relationship',
+   'Contains terms for describing relationship types between examples.'
+  );
+  
+}
+
+/**
+ * Adds controlled vocabulary terms needed by this module.
+ *
+ * @ingroup tripal_example
+ */
+function tripal_example_add_cvterms() {
+  
+  // EXPLANATION:  for our test module to work we need to add some terms to our example_type
+  // controlled vocabulary.  Ideally we should have a full OBO file for loading
+  // but sometimes we just have a small list that won't really change so
+  // we can add those terms here.
+  tripal_insert_cvterm(array(
+    'id'         => 'test',         // the term accession
+    'name'       => 'Test type',    // the human readable term name
+    'cv_name'    => 'example_type', // the CV name this term belongs to.
+    'definition' => 'A test type for the example modlue.',
+    'db_name'    => 'example_db',   // the database in which the term is found.
+  ));
 }
 
+/**
+ * Add custom tables to Chado that are required by this module
+ * 
+ * @ingroup tripal_example
+ */
+function tripal_example_add_custom_tables() {
+  
+  // EXPLANATION: for this example module we will create a set of example tables
+  // that mimic Chado tables. These tables are:
+  //
+  //   1) example     (for storing the primary example records)
+  //   2) exampleprop (for sorting properties about the example)
+  //   3) example_relationship (for storing relationships about examples)
+  //   4) example_dbxref (for storing cross-references about an example)
+  //
+  // To make the code easier to read, each table is created by a separte 
+  // function called here:
+  
+  tripal_example_add_example_table();
+  tripal_example_add_exampleprop_table();
+  tripal_example_add_example_relationship_table();
+  tripal_example_add_example_dbxref_table();
+}
+/**
+ * Adds the 'example' custom table to Chado.
+ * 
+ * @ingroup tripal_example
+ */
+function tripal_example_add_example_table() {
+  // EXPLANATION: use the Drupal Schema API to describe the custom table. Then
+  // add the table using the chado_create_custom_table() function.
+  $schema = array(
+    'table' => 'example',
+    'fields' => array(
+      'example_id' => array(
+        'type' => 'serial',
+        'not null' => true,
+      ),
+      'uniquename' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+      ),
+      'type_id' => array(
+        'type' => 'int',
+        'not null' => true,
+      ),
+      'organism_id' => array(
+        'type' => 'int',
+        'not null' => true,
+      ),
+      'description' => array(
+        'type' => 'text',
+      ),
+    ),
+    'primary key' => array(
+      0 => 'example_id',
+    ),
+    'unique keys' => array(
+      'example_uq1' => array(
+        0 => 'uniquename',
+        1 => 'type_id',
+        2 => 'organism_id',
+      ),
+    ),
+    'indexes' => array(
+      'example_idx1' => array(
+        0 => 'example_id',
+      ),
+      'example_idx2' => array(
+        0 => 'uniquename',
+      ),
+    ),
+    'foreign keys' => array(
+      'cvterm' => array(
+        'table' => 'cvterm',
+        'columns' => array(
+          'type_id' => 'cvterm_id',
+        ),
+      ),
+      'organism' => array(
+        'table' => 'organism',
+        'columns' => array(
+          'organism_id' => 'organism_id',
+        ),
+      ),
+    ),
+    // EXPLANATION: the 'referring_tables' array is the list of tables
+    // that have a foreign key relationships with this table. This 
+    // information is required for the Tripal API to be able to expand
+    // tables in templates.
+    'referring_tables' => array(
+      0 => 'example_relationship',
+      1 => 'exampleprop',
+      2 => 'example_dbxref',
+    ),
+  );
+  chado_create_custom_table('example', $schema, TRUE);
+}
+/**
+ * Adds the 'example_relationship' custom table to Chado.
+ * 
+ * @ingroup tripal_example
+ */
+function tripal_example_add_exampleprop_table() {
+  // EXPLANATION: use the Drupal Schema API to describe the custom table. Then
+  // add the table using the chado_create_custom_table() function.
+  
+  // Add the exampleprop table
+  $schema =  array(
+    'table' => 'exampleprop',
+    'fields' => array(
+      'exampleprop_id' => array(
+        'type' => 'serial',
+        'not null' => TRUE,
+      ),
+      'example_id' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'type_id' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'value' => array(
+        'type' => 'text',
+        'not null' => FALSE,
+      ),
+      'rank' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+    ),
+    'primary key' => array(
+      0 => 'exampleprop_id',
+    ),
+    'unique keys' => array(
+      'example_id_type_id_rank' => array(
+        0 => 'example_id',
+        1 => 'type_id',
+        2 => 'rank',
+      ),
+    ),
+    'foreign keys' => array(
+      'cvterm' => array(
+        'table' => 'cvterm',
+        'columns' => array(
+          'type_id' => 'cvterm_id',
+        ),
+      ),
+      'example' => array(
+        'table' => 'example',
+        'columns' => array(
+          'example_id' => 'example_id',
+        ),
+      ),
+    ),
+  );
+  chado_create_custom_table('exampleprop', $schema, TRUE);
+}
+
+/**
+ * Adds the 'example_relationship' custom table to Chado.
+ * 
+ * @ingroup tripal_example
+ */
+function tripal_example_add_example_relationship_table() {
+  // EXPLANATION: use the Drupal Schema API to describe the custom table. Then
+  // add the table using the chado_create_custom_table() function.
+  
+  $schema =  array(
+    'table' => 'example_relationship',
+    'fields' => array(
+      'example_relationship_id' => array(
+        'type' => 'serial',
+        'not null' => TRUE,
+      ),
+      'subject_id' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'object_id' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'type_id' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'value' => array(
+        'type' => 'text',
+        'not null' => FALSE,
+      ),
+      'rank' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+    ),
+    'primary key' => array(
+      0 => 'example_relationship_id',
+    ),
+    'unique keys' => array(
+      'example_relationship_c1' => array(
+        0 => 'subject_id',
+        1 => 'object_id',
+        2 => 'type_id',
+        3 => 'rank',
+      ),
+    ),
+    'indexes' => array(
+      'example_relationship_idx1' => array(
+        0 => 'subject_id',
+      ),
+      'example_relationship_idx2' => array(
+        0 => 'object_id',
+      ),
+      'example_relationship_idx3' => array(
+        0 => 'type_id',
+      ),
+    ),
+    'foreign keys' => array(
+      'cvterm' => array(
+        'table' => 'cvterm',
+        'columns' => array(
+          'type_id' => 'cvterm_id',
+        ),
+      ),
+      'example' => array(
+        'table' => 'example',
+        'columns' => array(
+          'subject_id' => 'example_id',
+          'object_id' => 'example_id',
+        ),
+      ),
+    ),
+  );
+  chado_create_custom_table('example_relationship', $schema, TRUE);
+}
+
+/**
+ * Adds the 'example_dbxref' custom table to Chado.
+ * 
+ * @ingroup tripal_example
+ */
+function tripal_example_add_example_dbxref_table() {
+  
+  // EXPLANATION: use the Drupal Schema API to describe the custom table. Then
+  // add the table using the chado_create_custom_table() function.
+
+  $description =  array(
+    'table' => 'example_dbxref',
+    'fields' => array(
+      'example_dbxref_id' => array(
+        'type' => 'serial',
+        'not null' => TRUE,
+      ),
+      'example_id' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'dbxref_id' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'is_current' => array(
+        'type' => 'int',
+        'size' => 'tiny',
+        'not null' => TRUE,
+        'default' => 1,
+      ),
+    ),
+    'primary key' => array(
+      0 => 'example_dbxref_id',
+    ),
+    'unique keys' => array(
+      'example_dbxref_unq1' => array(
+        0 => 'example_id',
+        1 => 'dbxref_id',
+      ),
+    ),
+    'indexes' => array(
+      'example_dbxref_idx1' => array(
+        0 => 'example_id',
+      ),
+      'example_dbxref_idx2' => array(
+        0 => 'dbxref_id',
+      ),
+    ),
+    'foreign keys' => array(
+      'dbxref' => array(
+        'table' => 'dbxref',
+        'columns' => array(
+          'dbxref_id' => 'dbxref_id',
+        ),
+      ),
+      'example' => array(
+        'table' => 'example',
+        'columns' => array(
+          'example_id' => 'example_id',
+        ),
+      ),
+    ),
+  );
+  chado_create_custom_table('example_dbxref', $schema, TRUE);
+}
 /**
  * This is the required update for tripal_example.
  */

+ 9 - 26
tripal_example/tripal_example.module

@@ -80,14 +80,14 @@ function tripal_example_menu() {
   //    
   
   // EXPLANATION:  all extension modules should have an administrative menu item
-  // with the path set to 'admin/tripal/extesion/[module name]'.  This will
+  // with the path set to 'admin/tripal/extension/[module name]'.  This will
   // place the menu item in the 'Tripal' -> 'Extesion Modules' page.  Because this
   // is an administrative menu item we must be sure to set the 'access arguments'
   // to be 'administer tripal example' which is a permission type we created
   // in the tripal_example_permissions() function above.
   $items['admin/tripal/extension/tripal_example'] = array(
     'title' => 'Examples',
-    'description' => 'Any example.',
+    'description' => 'Example module for help with development of new extension modules.',
     'page callback' => 'tripal_example_admin_examples_listing',
     'access arguments' => array('administer tripal example'),
     'type' => MENU_NORMAL_ITEM,
@@ -101,7 +101,7 @@ function tripal_example_menu() {
   // function and the 'page_arguments' indicate the name of the template file
   // Thus, all help documentation should be provided in the 
   // [module name]/theme/tripal_example_help.tpl.php file. 
-  $items['admin/tripal/chado/tripal_example/help'] = array(
+  $items['admin/tripal/extension/tripal_example/help'] = array(
     'title' => 'Help',
     'description' => 'Basic Description of Tripal Library Module Functionality',
     'page callback' => 'theme',
@@ -120,7 +120,7 @@ function tripal_example_menu() {
   // drupal_get_form() function and the 'page argument' indicates the form
   // to call is named 'tripal_eample_admin'.  The function that describes
   // to form is in the includes/tripal_example.admin.inc file.
-  $items['admin/tripal/chado/tripal_example/configuration'] = array(
+  $items['admin/tripal/extension/tripal_example/configuration'] = array(
     'title' => 'Settings',
     'description' => 'Configure the Tripal Library module',
     'page callback' => 'drupal_get_form',
@@ -135,7 +135,7 @@ function tripal_example_menu() {
   // to quickly provide syncing functionality.  See the API documentation here
   // for more information on how that is setup:
   // http://api.tripal.info/api/tripal/tripal_core%21api%21tripal_core.chado_nodes.api.inc/function/chado_node_sync_form/2.x
-  $items['admin/tripal/chado/tripal_example/sync'] = array(
+  $items['admin/tripal/extension/tripal_example/sync'] = array(
     'title' => ' Sync',
     'description' => 'Create pages on this site for examples stored in Chado',
     'page callback' => 'drupal_get_form',
@@ -222,7 +222,7 @@ function tripal_example_theme($existing, $type, $theme, $path) {
     'tripal_example_help' => array(
       'template' => 'tripal_example_help',
       'variables' =>  array(NULL),
-      'path' => "$path/theme",
+      'path' => "$path/theme/templates",
     ),
     // the teaser template.
     'tripal_example_teaser' => array(
@@ -242,24 +242,14 @@ function tripal_example_theme($existing, $type, $theme, $path) {
       'template' => 'tripal_example_properties',
       'path' => "$path/theme/templates",
     ),
-    'tripal_example_publications' => array(
-      'variables' => array('node' => NULL),
-      'template' => 'tripal_example_publications',
-      'path' => "$path/theme/templates",
-    ),
     'tripal_example_references' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_example_references',
       'path' => "$path/theme/templates",
     ),
-    'tripal_example_synonyms' => array(
-      'variables' => array('node' => NULL),
-      'template' => 'tripal_example_synonyms',
-      'path' => "$path/theme/templates",
-    ),
-    'tripal_example_terms' => array(
+    'tripal_example_relationships' => array(
       'variables' => array('node' => NULL),
-      'template' => 'tripal_example_terms',
+      'template' => 'tripal_example_relationships',
       'path' => "$path/theme/templates",
     ),
 
@@ -277,15 +267,8 @@ function tripal_example_theme($existing, $type, $theme, $path) {
       'template' => 'tripal_organism_examples',
       'path' => "$path/theme/templates",
     ),
-
-    // tripal_feature templates
-    'tripal_feature_examples' => array(
-      'variables' => array('node' => NULL),
-      'template' => 'tripal_feature_examples',
-      'path' => "$path/theme/templates",
-    ),
-
   );
+  
   return $items;
 }
 

+ 8 - 0
tripal_example/tripal_example.views.inc

@@ -1 +1,9 @@
 <?php
+/**
+ *  @file
+ *  This file contains the basic functions for views integration of
+ *  chado/tripal example tables
+ */
+
+// EXPLANATION: see another tripal module (e.g. tripal_feature) for example
+// functions that can be used in this file.

+ 24 - 0
tripal_example/tripal_example.views_default.inc

@@ -1 +1,25 @@
 <?php
+/**
+ * @file
+* Describe default example views
+*/
+
+/**
+ * Implements hook_views_default_views().
+*
+* @ingroup tripal_example
+*/
+function tripal_example_views_default_views() {
+  $views = array();
+  
+  // EXPLANATION:  use this function to programmatically define any default
+  // Drupal views that your module will provide automatically.  Typically
+  // there are two default views: 1) one for the administrator to quickly
+  // find data managed by your module, or 2) one for users to be able to
+  // search for public data.  
+  //
+  // See another Tripal module such as tripal_feature for an example 
+  // of how to setup a default views.
+  
+  return $views;
+}

+ 9 - 4
tripal_featuremap/tripal_featuremap.module

@@ -499,6 +499,11 @@ function tripal_library_node_view($node, $view_mode, $langcode) {
           '#tripal_toc_title' => 'Overview',
           '#weight' => -100,
         );
+        $node->content['tripal_library_features'] = array(
+          '#markup' => theme('tripal_library_features', array('node' => $node)),
+          '#tripal_toc_id'    => 'features',
+          '#tripal_toc_title' => 'Features',
+        );
         $node->content['tripal_library_properties'] = array(
           '#markup' => theme('tripal_library_properties', array('node' => $node)),
           '#tripal_toc_id'    => 'properties',
@@ -533,8 +538,8 @@ function tripal_library_node_view($node, $view_mode, $langcode) {
       break;
     case 'chado_organism':
       if ($view_mode == 'full') {
-        $node->content['tripal_organism.libraries'] = array(
-          '#markup' => theme('tripal_organism.libraries', array('node' => $node)),
+        $node->content['tripal_organism_libraries'] = array(
+          '#markup' => theme('tripal_organism_libraries', array('node' => $node)),
           '#tripal_toc_id'    => 'libraries',
           '#tripal_toc_title' => 'Libraries',
         );
@@ -542,8 +547,8 @@ function tripal_library_node_view($node, $view_mode, $langcode) {
       break;
     case 'chado_feature':
       if ($view_mode == 'full') {
-        $node->content['tripal_feature.libraries'] = array(
-          '#markup' => theme('tripal_feature.libraries', array('node' => $node)),
+        $node->content['tripal_feature_libraries'] = array(
+          '#markup' => theme('tripal_feature_libraries', array('node' => $node)),
           '#tripal_toc_id'    => 'libraries',
           '#tripal_toc_title' => 'Libraries',
         );

+ 1 - 1
tripal_library/theme/templates/tripal_library_base.tpl.php

@@ -71,7 +71,7 @@ if (user_access('administer tripal')) {
       'header' => TRUE,
       'class'  => 'tripal-site-admin-only-table-row',
     ),
-    $library->uniquename,
+    $library->library_id,
   );
 }
 

+ 101 - 0
tripal_library/theme/templates/tripal_library_features.tpl.php

@@ -0,0 +1,101 @@
+<?php
+
+$library = $variables['node']->library;
+
+// get the feature_id's of the features that belong to this library.  But we only
+// want 25 and we want a pager to let the user cycle between pages of features.
+// so we, use the tripal_core_chado_select API function to get the results and
+// generate the pager.  The function is smart enough to know which page the user is
+// on and retrieves the proper set of features
+$element = 0;        // an index to specify the pager if more than one is on the page
+$num_per_page = 25;  // the number of features to show per page
+$values = array(
+  'library_id' => $library->library_id,
+);
+$columns = array('feature_id');
+$options = array(
+  'pager' => array(
+    'limit' => $num_per_page, 
+    'element' => $element
+   ),
+);
+$results = tripal_core_chado_select('library_feature', $columns, $values, $options);
+
+// now that we have all of the feature IDs, we want to expand each one so that we
+// have all of the neccessary values, including the node ID, if one exists, and the
+// cvterm type name.
+$features = array();
+foreach ($results as $library_feature) {
+  $values = array('feature_id' => $library_feature->feature_id);
+  $options = array(
+    'include_fk' => array(
+      'type_id' => 1
+    )
+  );
+  $features[] = tripal_core_generate_chado_var('feature', $values, $options);
+}
+
+if (count($features) > 0) { ?>
+  <div class="tripal_library-data-block-desc tripal-data-block-desc">The following browser provides a quick view for new visitors.  Use the searching mechanism to find specific features.</div> <?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
+  $headers = array('Feature Name' ,'Unique Name', 'Type');
+  
+  // 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();
+
+  foreach ($features as $feature){
+    $fname =  $feature->name;
+    if (property_exists($feature, 'nid')) {
+      $fname =   l($fname, "node/$feature->nid", array('attributes' => array('target' => '_blank')));
+    }
+    $rows[] = array(
+      $fname,
+      $feature->uniquename,
+      $feature->type_id->name
+    );
+  } 
+  // 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_library-table-features',
+      'class' => 'tripal-data-table'
+    ),
+    '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);
+  
+  // the $pager array values that control the behavior of the pager.  For 
+  // documentation on the values allows in this array see:
+  // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
+  // here we add the paramter 'block' => 'feature_browser'. This is because
+  // the pager is not on the default block that appears. When the user clicks a
+  // page number we want the browser to re-appear with the page is loaded.
+  $pager = array(
+    'tags' => array(),
+    'element' => $element,
+    'parameters' => array(
+      'block' => 'features'
+    ),
+    'quantity' => $num_per_page,
+  );
+  print theme_pager($pager); 
+} 
+
+
+

+ 5 - 0
tripal_library/tripal_library.module

@@ -170,6 +170,11 @@ function tripal_library_theme($existing, $type, $theme, $path) {
       'template' => 'tripal_library_base',
       'path' => "$path/theme/templates",
     ),
+    'tripal_library_features' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_library_features',
+      'path' => "$path/theme/templates",
+    ),
     'tripal_library_properties' => array(
       'variables' => array('node' => NULL),
       'template' => 'tripal_library_properties',