Browse Source

Continuing with example module. Also added template for library_features

Stephen Ficklin 11 years ago
parent
commit
a5927accab

+ 1 - 1
tripal_cv/api/tripal_cv.api.inc

@@ -845,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
   ";

+ 22 - 15
tripal_example/includes/tripal_example.chado_node.inc

@@ -357,6 +357,13 @@ 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
@@ -367,10 +374,10 @@ function chado_example_insert($node) {
     $values = array(
       'uniquename' => $node->uniquename,
       'description' => $node->description,
-      'type_id' => $node->example_type,
+      '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',
@@ -379,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) {
@@ -387,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);
 
@@ -419,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;
@@ -566,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;
@@ -642,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
@@ -701,7 +708,7 @@ function tripal_example_node_view($node, $view_mode, $langcode) {
   // 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':

+ 9 - 4
tripal_library/includes/tripal_library.chado_node.inc

@@ -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',