Browse Source

Featuremap module is now functional

Stephen Ficklin 11 years ago
parent
commit
73035e7b84
28 changed files with 1180 additions and 1939 deletions
  1. 2 2
      tripal_analysis/includes/tripal_analysis.chado_node.inc
  2. 11 0
      tripal_analysis/theme/tripal_analysis/tripal_analysis_base.tpl.php
  3. 3 1
      tripal_core/api/tripal_core_chado.api.inc
  4. 8 2
      tripal_cv/api/tripal_cv.api.inc
  5. 2 2
      tripal_feature/theme/tripal_feature/tripal_feature_base.tpl.php
  6. 3 358
      tripal_featuremap/includes/tripal_featuremap.admin.inc
  7. 397 0
      tripal_featuremap/includes/tripal_featuremap.chado_node.inc
  8. 0 533
      tripal_featuremap/includes/tripal_featuremap.form.inc
  9. 0 142
      tripal_featuremap/theme/node--chado-featuremap.tpl.php
  10. 0 5
      tripal_featuremap/theme/tripal_featuremap.help.tpl.php
  11. 0 0
      tripal_featuremap/theme/tripal_featuremap.theme.inc
  12. 76 0
      tripal_featuremap/theme/tripal_featuremap/tripal_featuremap.base.tpl.php
  13. 158 0
      tripal_featuremap/theme/tripal_featuremap/tripal_featuremap.featurepos.tpl.php
  14. 52 0
      tripal_featuremap/theme/tripal_featuremap/tripal_featuremap.properties.tpl.php
  15. 64 0
      tripal_featuremap/theme/tripal_featuremap/tripal_featuremap.publication.tpl.php
  16. 69 0
      tripal_featuremap/theme/tripal_featuremap/tripal_featuremap.references.tpl.php
  17. 16 0
      tripal_featuremap/theme/tripal_featuremap/tripal_featuremap.teaser.tpl.php
  18. 0 39
      tripal_featuremap/theme/tripal_featuremap/tripal_featuremap_base.tpl.php
  19. 0 126
      tripal_featuremap/theme/tripal_featuremap/tripal_featuremap_featurepos.tpl.php
  20. 0 50
      tripal_featuremap/theme/tripal_featuremap/tripal_featuremap_properties.tpl.php
  21. 0 33
      tripal_featuremap/theme/tripal_featuremap/tripal_featuremap_publication.tpl.php
  22. 0 56
      tripal_featuremap/theme/tripal_featuremap/tripal_featuremap_references.tpl.php
  23. 0 60
      tripal_featuremap/theme/tripal_featuremap/tripal_featuremap_teaser.tpl.php
  24. 129 33
      tripal_featuremap/tripal_featuremap.install
  25. 124 433
      tripal_featuremap/tripal_featuremap.module
  26. 44 8
      tripal_library/includes/tripal_library.chado_node.inc
  27. 20 54
      tripal_library/tripal_library.module
  28. 2 2
      tripal_pub/api/tripal_pub.api.inc

+ 2 - 2
tripal_analysis/includes/tripal_analysis.chado_node.inc

@@ -47,7 +47,7 @@ function chado_analysis_form($node, &$form_state) {
     $timeexecuted   = $analysis->timeexecuted;
     $description    = $analysis->description;
      
-    // set the organism_id in the form
+    // set the analysis_id in the form
     $form['analysis_id'] = array(
       '#type' => 'value',
       '#value' => $analysis->analysis_id,
@@ -250,7 +250,7 @@ function tripal_analysis_validate($node, $form, &$form_state) {
   }
   
   // Validating for an update
-  if (!is_null($node->nid)) {    
+  if (!is_null($node->nid)) {
    
     // get the existing node    
     $values = array('analysis_id' => $node->analysis_id);      

+ 11 - 0
tripal_analysis/theme/tripal_analysis/tripal_analysis_base.tpl.php

@@ -72,6 +72,17 @@ $analysis = tripal_core_expand_chado_vars($analysis,'field','analysis.descriptio
     preg_replace("/^(\d+-\d+-\d+) .*/","$1", $analysis->timeexecuted),
   ); 
   
+  // allow site admins to see the feature ID
+  if (user_access('access administration pages')) {
+    // Analysis ID
+    $rows[] = array(
+      array(
+        'data' => 'Analysis ID',
+        'header' => TRUE
+      ),
+      $analysis->analysis_id
+    );
+  }
   // 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:

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

@@ -1782,7 +1782,9 @@ function tripal_core_expand_chado_vars($object, $type, $to_expand, $table_option
         $table_desc = tripal_core_get_chado_table_schema($tablename);
         $values = array();
         foreach ($table_desc['primary key'] as $key) {
-          $values[$key] = $object->{$key};
+          if(property_exists($object, $key)) {
+            $values[$key] = $object->{$key};
+          }
         }
         if ($base_table == $tablename) {
           //get the field

+ 8 - 2
tripal_cv/api/tripal_cv.api.inc

@@ -539,7 +539,10 @@ function tripal_cv_add_cvterm($term, $defaultcv = '_global', $is_relationship =
   }
   
   // make sure the CV name exists
-  $cv = tripal_cv_add_cv($cvname, '');
+  $cv = tripal_cv_get_cv_by_name($cvname);
+  if (!$cv) {
+    $cv = tripal_cv_add_cv($cvname, '');
+  }
   if (!$cv) {
     watchdog('tripal_cv', "Cannot find namespace '$cvname' when adding/updating $id", NULL, WATCHDOG_WARNING);
     return 0;
@@ -561,7 +564,10 @@ function tripal_cv_add_cvterm($term, $defaultcv = '_global', $is_relationship =
   
   // add the database. The function will just return the DB object if the
   // database already exists.
-  $db = tripal_db_add_db($dbname);
+  $db = tripal_db_get_db_by_name($dbname);
+  if (!$db) {
+    $db = tripal_db_add_db($dbname);
+  }
   if (!$db) {
     watchdog('tripal_cv', "Cannot find database '$dbname' in Chado.", NULL, WATCHDOG_WARNING);
     return 0;

+ 2 - 2
tripal_feature/theme/tripal_feature/tripal_feature_base.tpl.php

@@ -43,9 +43,9 @@ $feature  = $variables['node']->feature;  ?>
     $feature->type_id->name
   );
   // Organism row
-  $organism = $feature->organism_id->genus ." " . $feature->organism_id->species ." (" .$feature->organism_id->common_name .")";
+  $organism = $feature->organism_id->genus ." " . $feature->organism_id->species ." (" . $feature->organism_id->common_name .")";
   if ($feature->organism_id->nid) {
-    $organism = l("<i>" . $feature->organism_id->genus . " " . $feature->organism_id->species . "</i> (" .$feature->organism_id->common_name .")", "node/".$feature->organism_id->nid, array('html' => TRUE));
+    $organism = l("<i>" . $feature->organism_id->genus . " " . $feature->organism_id->species . "</i> (" . $feature->organism_id->common_name .")", "node/".$feature->organism_id->nid, array('html' => TRUE));
   } 
   $rows[] = array(
     array(

+ 3 - 358
tripal_featuremap/includes/tripal_featuremap.admin.inc

@@ -41,374 +41,19 @@ function tripal_featuremap_admin_featuremaps_listing() {
 function tripal_featuremap_admin() {
   $form = array();
 
-  // before proceeding check to see if we have any
-  // currently processing jobs. If so, we don't want
-  // to give the opportunity to sync maps
-  $active_jobs = FALSE;
-  if (tripal_get_module_active_jobs('tripal_featuremap')) {
-    $active_jobs = TRUE;
-  }
-
-  // add the field set for syncing maps
-  if (!$active_jobs) {
-    get_tripal_featuremap_admin_form_sync_set($form);
-    get_tripal_featuremap_admin_form_cleanup_set($form);
-// TODO: complete coding of indexing and taxonomy assignment to features.
-//    get_tripal_featuremap_admin_form_reindex_set($form);
-//    get_tripal_featuremap_admin_form_taxonomy_set($form);
-  }
-  else {
-    $form['notice'] = array(
-     '#type' => 'fieldset',
-     '#title' => t('Feature Map Management Temporarily Unavailable')
-    );
-    $form['notice']['message'] = array(
-        '#value' => t('Currently, feature map management jobs are waiting or are running. Managemment features have been hidden until these jobs complete.  Please check back later once these jobs have finished.  You can view the status of pending jobs in the Tripal jobs page.'),
-    );
-  }
-
-  return system_settings_form($form);
-}
-/**
- *
- *
- * @ingroup tripal_featuremap
- */
-function get_tripal_featuremap_admin_form_cleanup_set(&$form) {
-  $form['cleanup'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Clean Up')
-  );
-  $form['cleanup']['description'] = array(
-     '#type' => 'item',
-     '#value' => t("With Drupal and chado residing in different databases ".
-        "it is possible that nodes in Drupal and maps in Chado become ".
-        "\"orphaned\".  This can occur if an map node in Drupal is ".
-        "deleted but the corresponding chado map is not and/or vice ".
-        "versa. Click the button below to resolve these discrepancies."),
-     '#weight' => 1,
-  );
-  $form['cleanup']['button'] = array(
-    '#type' => 'submit',
-    '#value' => t('Clean up orphaned maps'),
-    '#weight' => 2,
-  );
-}
-
-/**
- *
- *
- * @ingroup tripal_featuremap
- */
-function get_tripal_featuremap_admin_form_taxonomy_set(&$form) {
-  $form['taxonify'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Assign Drupal Taxonomy to Map Features')
-  );
-
-  // get the list of maps
-  $sql = "SELECT * FROM {featuremap} ORDER BY name";
-  $lib_rset = chado_query($sql);
-
-  // iterate through all of the maps
-  $lib_boxes = array();
-  while ($featuremap = $lib_rset->fetchObject()) {
-    $lib_boxes[$featuremap->featuremap_id] = "$featuremap->name";
-  }
-
-  $form['taxonify']['description'] = array(
-     '#type' => 'item',
-     '#value' => t("Drupal allows for assignment of \"taxonomy\" or catagorical terms to " .
-                   "nodes. These terms allow for advanced filtering during searching. This option allows ".
-                   "for setting taxonomy only for features that belong to the selected maps below.  All other features will be unaffected.  To set taxonomy for all features in the site see the Feature Administration page."),
-   '#weight' => 1,
+  $form['nothing'] = array(
+    '#markup' => t('There are currently no settings to configure.')
   );
 
-  $form['taxonify']['tx-maps'] = array(
-   '#title'       => t('Maps'),
-   '#type'        => t('checkboxes'),
-   '#description' => t("Check the maps whose features you want to reset taxonomy.  Note: this list contains all maps, even those that may not be synced."),
-   '#required'    => FALSE,
-   '#prefix'      => '<div id="lib_boxes">',
-   '#suffix'      => '</div>',
-   '#options'     => $lib_boxes,
-   '#weight'      => 2
-  );
-  $form['taxonify']['tx-button'] = array(
-    '#type' => 'submit',
-    '#value' => t('Set Feature Taxonomy'),
-    '#weight'      => 3
-  );
-}
-/**
- *
- * @ingroup tripal_featuremap
- */
-function get_tripal_featuremap_admin_form_reindex_set(&$form) {
-   // define the fieldsets
-  $form['reindex'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Reindex Map Features')
-  );
-
-  // get the list of maps
-  $sql = "SELECT * FROM {featuremap} ORDER BY name";
-  $lib_rset = chado_query($sql);
-
-  // iterate through all of the maps
-  $lib_boxes = array();
-  while ($featuremap = $lib_rset->fetchObject()) {
-    $lib_boxes[$featuremap->featuremap_id] = "$featuremap->name";
-  }
-  $form['reindex']['description'] = array(
-     '#type' => 'item',
-     '#value' => t("This option allows for reindexing of only those features that belong to the selected maps below. All other features will be unaffected.  To reindex all features in the site see the Feature Administration page."),
-   '#weight' => 1,
-  );
-
-  $form['reindex']['re-maps'] = array(
-   '#title'       => t('Maps'),
-   '#type'        => t('checkboxes'),
-   '#description' => t("Check the maps whoee features you want to reindex. Note: this list contains all maps, even those that may not be synced."),
-   '#required'    => FALSE,
-   '#prefix'      => '<div id="lib_boxes">',
-   '#suffix'      => '</div>',
-   '#options'     => $lib_boxes,
-   '#weight' => 2,
-  );
-  $form['reindex']['re-button'] = array(
-    '#type' => 'submit',
-    '#value' => t('Reindex Features'),
-    '#weight' => 3,
-  );
+  return system_settings_form($form);
 }
-/**
- *
- * @ingroup tripal_featuremap
- */
-function get_tripal_featuremap_admin_form_sync_set(&$form) {
-   // define the fieldsets
-  $form['sync'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Sync Maps')
-  );
-
 
-  // get the list of maps
-  $sql = "SELECT * FROM {featuremap} ORDER BY name";
-  $lib_rset = chado_query($sql);
 
-  // if we've added any maps to the list that can be synced
-  // then we want to build the form components to allow the user
-  // to select one or all of them.  Otherwise, just present
-  // a message stating that all maps are currently synced.
-  $lib_boxes = array();
-  $added = 0;
-  while ($featuremap = $lib_rset->fetchObject()) {
-    // check to see if the map is already present as a node in drupal.
-    // if so, then skip it.
-    $sql = "SELECT * FROM {chado_featuremap} WHERE featuremap_id = :featuremap_id";
-    if (!db_query($sql, array(':featuremap_id' => $featuremap->featuremap_id))->fetchObject()) {
-      $lib_boxes[$featuremap->featuremap_id] = "$featuremap->name";
-      $added++;
-    }
-  }
-
-  // if we have maps we need to add to the checkbox then
-  // build that form element
-  if ($added > 0) {
-    $lib_boxes['all'] = "All Maps";
-
-    $form['reindex']['description'] = array(
-     '#type' => 'item',
-     '#value' => t("This option allows for the creation of Drupal content for maps in chado. Only the selected maps will be synced."),
-   '#weight' => 1,
-    );
-
-
-    $form['sync']['featuremaps'] = array(
-      '#title'       => t('Available Maps'),
-      '#type'        => t('checkboxes'),
-      '#description' => t("Check the maps you want to sync.  Drupal content will be created for each of the maps listed above.  Select 'All Maps' to sync all of them."),
-      '#required'    => FALSE,
-      '#prefix'      => '<div id="lib_boxes">',
-      '#suffix'      => '</div>',
-      '#options'     => $lib_boxes,
-    '#weight' => 2,
-    );
-    $form['sync']['button'] = array(
-       '#type' => 'submit',
-       '#value' => t('Sync Maps'),
-     '#weight' => 3,
-    );
-  }
-   // we don't have any maps to select from
-  else {
-    $form['sync']['value'] = array(
-       '#value' => t('All maps in Chado are currently synced with Drupal.')
-    );
-  }
-}
 /**
  *
  * @ingroup tripal_featuremap
  */
 function tripal_featuremap_admin_validate($form, &$form_state) {
-  global $user;  // we need access to the user info
-  $job_args = array();
-
-  // Submit the Sync Job if selected
-  if ($form_state['values']['op'] == t('Sync Maps')) {
-
-    // check to see if the user wants to sync chado and drupal.  If
-    // so then we need to register a job to do so with tripal
-    $featuremaps = $form_state['values']['featuremaps'];
-    $do_all = FALSE;
-    $to_sync = array();
-
-  foreach ($featuremaps as $featuremap_id) {
-    if (preg_match("/^all$/i", $featuremap_id)) {
-      $do_all = TRUE;
-    }
-    if ($featuremap_id and preg_match("/^\d+$/i", $featuremap_id)) {
-      // get the map info
-      $sql = "SELECT * FROM {featuremap} WHERE featuremap_id = :featuremap_id";
-      $featuremap = chado_query($sql, array(':featuremap_id' => $featuremap_id))->fetchObject();
-      $to_sync[$featuremap_id] = $featuremap->name;
-    }
-  }
-
-  // submit the job to the tripal job manager
-  if ($do_all) {
-    tripal_add_job('Sync all maps', 'tripal_featuremap', 'tripal_featuremap_sync_featuremaps', $job_args, $user->uid);
-  }
-  else{
-    foreach ($to_sync as $featuremap_id => $name) {
-      $job_args[0] = $featuremap_id;
-      tripal_add_job("Sync map: $name", 'tripal_featuremap', 'tripal_featuremap_sync_featuremaps', $job_args, $user->uid);
-      }
-    }
-  }
-
-  // -------------------------------------
-  // Submit the Reindex Job if selected
-  if ($form_state['values']['op'] == t('Reindex Features')) {
-    $featuremaps = $form_state['values']['re-maps'];
-    foreach ($featuremaps as $featuremap_id) {
-      if ($featuremap_id and preg_match("/^\d+$/i", $featuremap_id)) {
-        // get the map info
-        $sql = "SELECT * FROM {featuremap} WHERE featuremap_id = :featuremap_id";
-        $featuremap = chado_query($sql, array(':featuremap_id' => $featuremap_id))->fetchObject();
-        $job_args[0] = $featuremap_id;
-        tripal_add_job("Reindex features for map: $featuremap->name", 'tripal_featuremap',
-         'tripal_featuremap_reindex_features', $job_args, $user->uid);
-      }
-    }
-  }
-
-  // -------------------------------------
-  // Submit the Taxonomy Job if selected
-  if ($form_state['values']['op'] == t('Set Feature Taxonomy')) {
-    $featuremaps = $form_state['values']['tx-maps'];
-    foreach ($featuremaps as $featuremap_id) {
-      if ($featuremap_id and preg_match("/^\d+$/i", $featuremap_id)) {
-        // get the map info
-        $sql = "SELECT * FROM {featuremap} WHERE featuremap_id = :featuremap_id";
-        $featuremap = chado_query($sql, array(':featuremap_id' => $featuremap_id))->fetchObject();
-        $job_args[0] = $featuremap_id;
-        tripal_add_job("Set taxonomy for features in map: $featuremap->name", 'tripal_featuremap',
-         'tripal_featuremap_taxonify_features', $job_args, $user->uid);
-      }
-    }
-  }
-    // -------------------------------------
-    // Submit the Cleanup Job if selected
-    if ($form_state['values']['op'] == t('Clean up orphaned maps')) {
-      tripal_add_job('Cleanup orphaned maps', 'tripal_featuremap',
-         'tripal_featuremap_cleanup', $job_args, $user->uid);
-    }
-}
-
-/**
- *
- *
- * @ingroup tripal_featuremap
- */
-function tripal_featuremap_sync_featuremaps($featuremap_id = NULL, $job_id = NULL) {
-
-  global $user;
-  $page_content = '';
-
-  // get the list of featuremaps and create new nodes
-  if (!$featuremap_id) {
-    $sql = "SELECT * FROM {featuremap} F";
-    $results = chado_query($sql);
-  }
-  else {
-    $sql = "SELECT * FROM {featuremap} F WHERE featuremap_id = :featuremap_id";
-    $results = chado_query($sql, array(':featuremap_id' => $featuremap_id));
-  }
 
-  // We'll use the following SQL statement for checking if the map
-  // already exists as a drupal node.
-  $sql = "SELECT * FROM {chado_featuremap} ".
-        "WHERE featuremap_id = :featuremap_id";
-
-  while ($featuremap = $results->fetchObject()) {
-
-    // check if this map already exists in the drupal database. if it
-    // does then skip this map and go to the next one.
-    if (!db_query($sql, array(':featuremap_id' => $featuremap->featuremap_id))->fetchObject()) {
-
-    $new_node = new stdClass();
-    $new_node->type = 'chado_featuremap';
-    $new_node->uid = $user->uid;
-    $new_node->title = "$featuremap->name";
-    $new_node->featuremap_id = $featuremap->featuremap_id;
-
-    node_validate($new_node);
-    $errors = form_get_errors();
-    if (!$errors) {
-      $node = node_submit($new_node);
-      node_save($node);
-      if ($node->nid) {
-        print "Added " . $featuremap->name . "\n";
-      }
-      else {
-        print "ERROR: Unable to create " . $featuremap->name . "\n";
-      }
-    }
-    else {
-      print "ERROR: Unable to create " . $featuremap->name . "\n" . print_r($errors, TRUE) . "\n";
-    }
-    }
-    else {
-      print "Skipped " . $featuremap->name . "\n";
-    }
-  }
-  return $page_content;
 }
 
-/**
- * Remove orphaned drupal nodes
- *
- * @param $dummy
- *   Not Used -kept for backwards compatibility
- * @param $job_id
- *   The id of the tripal job executing this function
- *
- * @ingroup tripal_featuremap
- */
-function tripal_featuremap_cleanup($dummy = NULL, $job_id = NULL) {
-
-  return tripal_core_chado_node_cleanup_orphaned('featuremap', $job_id);
-
-}
-/**
- * Add the map as a taxonomy term for associating with map_features
- *
- * @ingroup tripal_featuremap
- */
-function tripal_featuremap_add_taxonomy($node, $featuremap_id) {
-
-}

+ 397 - 0
tripal_featuremap/includes/tripal_featuremap.chado_node.inc

@@ -0,0 +1,397 @@
+<?php
+/**
+ *  When editing or creating a new node of type 'chado_featuremap' we need
+ *  a form.  This function creates the form that will be used for this.
+ *
+ * @ingroup tripal_featuremap
+ */
+function chado_featuremap_form($node, &$form_state) {
+  $form = array();
+  
+  // Default values can come in the following ways:
+  //
+  // 1) as elements of the $node object.  This occurs when editing an existing library
+  // 2) in the $form_state['values'] array which occurs on a failed validation or
+  //    ajax callbacks from non submit form elements
+  // 3) in the $form_state['input'[ array which occurs on ajax callbacks from submit
+  //    form elements and the form is being rebuilt
+  //
+  // set form field defaults
+  $featuremap_id = NULL;
+  $title = '';
+  $description = '';
+  $unittype_id = '';
+  
+  // if we are editing an existing node then the featuremap is already part of the node
+  if (property_exists($node, 'featuremap')) {
+    $featuremap = $node->featuremap;
+    $featuremap = tripal_core_expand_chado_vars($featuremap, 'field', 'featuremap.description');
+    $featuremap_id = $featuremap->featuremap_id;
+    
+    // get form defaults
+    $title       = $featuremap->name;
+    $description = $featuremap->description;
+    $unittype_id = $featuremap->unittype_id->cvterm_id;
+    
+    // set the featuremap_id in the form
+    $form['featuremap_id'] = array(
+      '#type' => 'hidden',
+      '#value' => $featuremap_id,
+    );
+  }
+  // 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']['title'];
+    $description = $form_state['values']['description'];
+    $unittype_id = $form_state['values']['unittype_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'])) {
+    $title       = $form_state['input']['title'];
+    $description = $form_state['input']['description'];
+    $unittype_id = $form_state['input']['unittype_id'];
+  }
+  
+  $form['title']= array(
+    '#type'          => 'textfield',
+    '#title'         => t('Map Name'),
+    '#description'   => t('Please enter a name for this map'),
+    '#required'      => TRUE,
+    '#default_value' => $title,
+    '#maxlength'     => 255
+  );
+  $form['description']= array(
+    '#type'          => 'textarea',
+    '#title'         => t('Map Description'),
+    '#description'   => t('A description of the map.'),
+    '#required'      => TRUE,
+    '#default_value' => $description,
+  );
+
+  // get the list of unit types
+  $values = array(
+    'cv_id' => array(
+      'name' => 'featuremap_units',
+    )
+  );
+  $columns = array('cvterm_id','name');
+  $options = array('order_by' => array('name' => 'ASC'));
+  $featuremap_units = tripal_core_chado_select('cvterm', $columns, $values, $options);
+  $units = array();
+  $units[''] = '';
+  foreach($featuremap_units as $unit) {
+    $units[$unit->cvterm_id] = $unit->name;
+  }
+  $form['unittype_id'] = array(
+    '#title'       => t('Map Units'),
+    '#type'        => t('select'),
+    '#description' => t("Chose the units for this map"),
+    '#required'    => TRUE,
+    '#default_value' => $unittype_id,
+    '#options'     => $units,
+  );
+
+  // get the featuremap properties
+  $properties = array();
+  $properties[] = 'Select a Property';
+  $sql = "
+    SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
+    FROM  {cvterm} CVT
+      INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
+    WHERE 
+      CV.name = 'featuremap_property' AND 
+      NOT CVT.is_obsolete = 1
+    ORDER BY CVT.name ASC 
+  ";
+  $prop_types = chado_query($sql);
+  while ($prop = $prop_types->fetchObject()) {
+    $properties[$prop->cvterm_id] = $prop->name;
+  }
+
+  $exclude = array();
+  $include = array();
+  $instructions = t('To add additional properties to the drop down. ' . l("Add terms to the featuremap_property vocabulary", "admin/tripal/chado/tripal_cv/cvterm/add") . ".");
+  tripal_core_properties_form($form, $form_state, 'featuremapprop', 'featuremap_id', 'featuremap_property',
+    $properties, $featuremap_id, $exclude, $include, $instructions, 'Properties');
+
+  return $form;
+}
+/**
+ *  validates submission of form when adding or updating a map node
+ *
+ * @ingroup tripal_featuremap
+ */
+function chado_featuremap_validate($node, $form, &$form_state) {
+  $node->title          = trim($node->title);
+  $node->description    = trim($node->description);
+  
+  // if this is a delete then don't validate
+  if($node->op == 'Delete') {
+    return;
+  }
+  
+  // we are syncing if we do not have a node ID but we do have a featuremap_id. We don't
+  // need to validate during syncing so just skip it.
+  if (is_null($node->nid) and property_exists($node, 'featuremap_id') and $node->featuremap_id != 0) {
+    return;
+  }
+
+  $featuremap = 0;
+  // check to make sure the unique name on the map is unique
+  // before we try to insert into chado. If this is an update then we will
+  // have a featuremap_id, therefore we want to look for another map with this
+  // name but with a different featuremap_id. If this is an insert, just look
+  // for a case where the name already exists.
+  if (property_exists($node, 'featuremap_id')) {
+    $sql = "
+      SELECT * FROM {featuremap} 
+      WHERE name = :name AND NOT featuremap_id = :featuremap_id
+    ";
+    $featuremap = chado_query($sql, array(':name' => $node->title, ':featuremap_id' => $node->featuremap_id))->fetchObject();
+  }
+  else {
+    $sql = "SELECT * FROM {featuremap} WHERE name = :name";
+    $featuremap = chado_query($sql, array(':name' => $node->title))->fetchObject();
+  }
+  if ($featuremap) {
+    form_set_error('title', t('The unique map name already exists. Please choose another'));
+  }
+}
+
+
+/**
+ * Implement hook_access().
+ *
+ * This hook allows node modules to limit access to the node types they define.
+ *
+ *  @param $node
+ *  The node on which the operation is to be performed, or, if it does not yet exist, the
+ *  type of node to be created
+ *
+ *  @param $op
+ *  The operation to be performed
+ *
+ *  @param $account
+ *  A user object representing the user for whom the operation is to be performed
+ *
+ *  @return
+ *  If the permission for the specified operation is not set then return FALSE. If the
+ *  permission is set then return NULL as this allows other modules to disable
+ *  access.  The only exception is when the $op == 'create'.  We will always
+ *  return TRUE if the permission is set.
+ *
+ * @ingroup tripal_featuremap
+ */
+function chado_featuremap_node_access($node, $op, $account) {
+  if ($op == 'create') {
+    if (!user_access('create chado_featuremap content', $account)) {
+      return FALSE;
+    }
+    return TRUE;
+  }
+
+  if ($op == 'update') {
+    if (!user_access('edit any chado_featuremap content', $account) &&
+    !user_access('edit own chado_featuremap content', $account)) {
+      return FALSE;
+    }
+    if (user_access('edit own chado_featuremap content', $account) &&
+    $account->uid != $node->uid) {
+      return FALSE;
+    }
+  }
+
+  if ($op == 'delete') {
+    if (!user_access('delete any chado_featuremap content', $account) &&
+    !user_access('delete own chado_featuremap content', $account)) {
+      return FALSE;
+    }
+    if (user_access('delete own chado_featuremap content', $account) &&
+    $account->uid != $node->uid) {
+      return FALSE;
+    }
+  }
+  return NULL;
+}
+
+/**
+ *  When a new chado_featuremap node is created we also need to add information
+ *  to our chado_featuremap table.  This function is called on insert of a new node
+ *  of type 'chado_featuremap' and inserts the necessary information.
+ *
+ * @ingroup tripal_featuremap
+ */
+function chado_featuremap_insert($node) {
+
+  $node->title          = trim($node->title);
+  $node->description    = trim($node->description);
+  
+  // if there is an featuremap_id in the $node object then this must be a sync so
+  // we can skip adding the featuremap as it is already there, although
+  // we do need to proceed with the rest of the insert
+  if (!property_exists($node, 'featuremap_id')) {
+    
+    $values = array(
+      'name'        => $node->title,
+      'description' => $node->description,
+      'unittype_id' => $node->unittype_id
+    );
+    $featuremap = tripal_core_chado_insert('featuremap', $values);
+    if(!$featuremap) {
+      drupal_set_message(t('Unable to add featuremap.', 'warning'));
+      watchdog('tripal_featuremap', 'Unable to create feature map where values: %values',
+      array('%values' => print_r($values, TRUE)), WATCHDOG_WARNING);
+      return;
+    }
+    $featuremap_id = $featuremap['featuremap_id'];
+
+    // get the properties from the form
+    $properties = tripal_core_properties_form_retreive($node, 'featuremap_property');
+    
+    // now add in the properties
+    $properties = tripal_core_properties_form_retreive($node, 'featuremap_property');
+    foreach ($properties as $property => $elements) {
+      foreach ($elements as $rank => $value) {
+        // if the property name is 'Map Dbxref' then save this as a Dbxref record not a property
+        if ($property == 'Map Dbxref') {
+          $featuremap_dbxref = tripal_featuremap_add_featuremap_dbxref($featuremap_id, $value);
+          if (!$featuremap_dbxref) {
+            drupal_set_message("Error cannot add featuremap cross reference: $value", "error");
+            watchdog('t_featuremap', "Error cannot add featuremap cross reference: %ref",
+            array('%ref' => $value), WATCHDOG_ERROR);
+          }
+        }
+        // this is a property so add it 
+        else {
+          $status = tripal_featuremap_insert_property($featuremap_id, $property, $value, FALSE, 'featuremap_property');
+          if (!$status) {
+            drupal_set_message("Error cannot add property: $property", "error");
+            watchdog('t_featuremap', "Error cannot add property: %prop",
+            array('%property' => $property), WATCHDOG_ERROR);
+          }
+        }
+      }
+    }
+  }
+  else {
+    $featuremap_id = $node->featuremap_id;
+  }
+
+  // Make sure the entry for this featuremap doesn't already exist in the
+  // chado_featuremap table if it doesn't exist then we want to add it.
+  $check_org_id = chado_get_id_for_node('featuremap', $node->nid);
+  if (!$check_org_id) {
+    $record = new stdClass();
+    $record->nid = $node->nid;
+    $record->vid = $node->vid;
+    $record->featuremap_id = $featuremap_id;
+    drupal_write_record('chado_featuremap', $record);
+  }
+}
+/**
+ * Update nodes
+ *
+ * @ingroup tripal_featuremap
+ */
+function chado_featuremap_update($node) {
+  
+  $node->title          = trim($node->title);
+  $node->description    = trim($node->description);
+  
+  $featuremap_id = chado_get_id_for_node('featuremap', $node->nid) ;
+
+  // update the map record
+  $match = array(
+    'featuremap_id' => $featuremap_id,
+  );
+  $values = array(
+    'name' => $node->title,
+    'description' => $node->description,
+    'unittype_id' => $node->unittype_id
+  );
+  $status = tripal_core_chado_update('featuremap', $match, $values);
+  if (!$status) {
+    drupal_set_message("Error updating map", "error");
+    watchdog('t_featuremap', "Error updating map", array(), WATCHDOG_ERROR);
+    return;
+  }
+
+  // get the properties from the form
+  $properties = tripal_core_properties_form_retreive($node, 'featuremap_property');
+  
+  tripal_core_chado_delete('featuremapprop', array('featuremap_id' => $featuremap_id));
+  foreach ($properties as $property => $elements) {
+    foreach ($elements as $rank => $value) {
+      // if the property name is 'Map Dbxref' then save this as a Dbxref record not a property
+      if ($property == 'Map Dbxref') {
+        $featuremap_dbxref = tripal_featuremap_add_featuremap_dbxref($featuremap_id, $value);
+        if (!$featuremap_dbxref) {
+          drupal_set_message("Error cannot add featuremap cross reference: $value", "error");
+          watchdog('t_featuremap', "Error cannot add featuremap cross reference: %ref",
+          array('%ref' => $value), WATCHDOG_ERROR);
+        }
+      }
+      // this is a property so add it
+      else {
+        $status = tripal_featuremap_insert_property($featuremap_id, $property, $value, FALSE, 'featuremap_property');
+        if (!$status) {
+          drupal_set_message("Error cannot add property: $property", "error");
+          watchdog('t_featuremap', "Error cannot add property: %prop",
+          array('%property' => $property), WATCHDOG_ERROR);
+        }
+      }
+    }
+  }
+}
+/**
+ *  When a node is requested by the user this function is called to allow us
+ *  to add auxiliary data to the node object.
+ *
+ * @ingroup tripal_featuremap
+ */
+function chado_featuremap_load($nodes) {
+  foreach ($nodes as $nid => $node) {
+    // get the feature details from chado
+    $featuremap_id = chado_get_id_for_node('featuremap', $node->nid);
+  
+    $values = array('featuremap_id' => $featuremap_id);
+    $featuremap = tripal_core_generate_chado_var('featuremap', $values);
+  
+    // expand the description field as it is needed by the form
+    $featuremap = tripal_core_expand_chado_vars($featuremap, 'field', 'featuremap.description');
+  
+    $nodes[$nid]->featuremap = $featuremap;
+  }
+
+}
+/**
+ * Delete data from drupal and chado databases when a node is deleted
+ * @ingroup tripal_featuremap
+ */
+function chado_featuremap_delete(&$node) {
+
+  $featuremap_id = chado_get_id_for_node('featuremap', $node->nid);
+
+  // if we don't have a map id for this node then this isn't a node of
+  // type chado_featuremap or the entry in the chado_featuremap table was lost.
+  if (!$featuremap_id) {
+    return;
+  }
+
+  // Remove data from {chado_featuremap}, {node} and {node_revisions} tables of
+  // drupal database
+  $sql_del = "DELETE FROM {chado_featuremap} WHERE nid = :nid AND vid = :vid";
+  db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
+  $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
+  db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
+  $sql_del = "DELETE FROM {node_revisions} WHERE nid = :nid AND vid = :vid";
+  db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
+
+  // Remove data from map and mapprop tables of chado database as well
+  chado_query("DELETE FROM {featuremapprop}    WHERE featuremap_id = :featuremap_id", array(':featuremap_id' => $featuremap_id));
+  chado_query("DELETE FROM {featuremap_dbxref} WHERE featuremap_id = :featuremap_id", array(':featuremap_id' => $featuremap_id));
+  chado_query("DELETE FROM {featuremap}        WHERE featuremap_id = :featuremap_id", array(':featuremap_id' => $featuremap_id));
+  
+}

+ 0 - 533
tripal_featuremap/includes/tripal_featuremap.form.inc

@@ -1,533 +0,0 @@
-<?php
-/**
- *  When editing or creating a new node of type 'chado_featuremap' we need
- *  a form.  This function creates the form that will be used for this.
- *
- * @ingroup tripal_featuremap
- */
-function chado_featuremap_form($node) {
-  tripal_core_ahah_init_form();
-  $form = array();
-  
-  $featuremap = $node->featuremap;
-  $featuremap_id = $featuremap->featuremap_id;
-  
-  $d_title        = $form_state['values']['title']       ? $form_state['values']['title']       : $featuremap->name;
-  $d_description  = $form_state['values']['description'] ? $form_state['values']['description'] : $featuremap->description;
-  $d_unittype_id  = $form_state['values']['unittype_id'] ? $form_state['values']['unittype_id'] : $featuremap->unittype_id->cvterm_id;
-
-  // on AHAH callbacks we want to keep a list of all the properties that have been removed
-  // we'll store this info in a hidden field and retrieve it here
-  $d_removed = $form_state['values']['removed'];
-
-  // get the number of new fields that have been aded via AHAH callbacks
-  $num_new = $form_state['values']['num_new'] ? $form_state['values']['num_new'] : 0;
-
-  // initialze default properties array. This is where we store the property defaults
-  $d_properties = array();
-  
-  // get the list of unit types
-  $values = array(
-    'cv_id' => array(
-      'name' => 'featuremap_units',
-    )
-  );
-  $columns = array('cvterm_id','name');
-  $options = array('order_by' => array('name' => 'ASC'));
-  $featuremap_units = tripal_core_chado_select('cvterm', $columns, $values, $options);
-  $units = array();
-  $units[''] = '';
-  foreach($featuremap_units as $unit) {
-    $units[$unit->cvterm_id] = $unit->name;
-  }
-  
-  // get the featuremap properties
-  $properties_select = array();
-  $properties_select[] = 'Select a Property';
-  $properties_list = array();
-  $sql = "
-    SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
-    FROM  {cvterm} CVT
-      INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
-    WHERE 
-      CV.name = 'featuremap_property' AND 
-      NOT CVT.is_obsolete = 1
-    ORDER BY CVT.name ASC 
-  ";
-  $prop_types = chado_query($sql);
-  while ($prop = $prop_types->fetchObject()) {
-    $properties_select[$prop->cvterm_id] = $prop->name;
-    $properties_list[$prop->cvterm_id] = $prop;
-  }
-  
-  // keep track of the map id if we have.  If we do have one then
-  // this is an update as opposed to an insert.
-  $form['featuremap_id'] = array(
-    '#type' => 'hidden',
-    '#value' => $featuremap_id,
-  );
-
-  $form['title']= array(
-    '#type'          => 'textfield',
-    '#title'         => t('Map Name'),
-    '#description'   => t('Please enter a name for this map'),
-    '#required'      => TRUE,
-    '#default_value' => $d_title,
-    '#maxlength'     => 255
-  );
-
-  $form['description']= array(
-    '#type'          => 'textarea',
-    '#title'         => t('Map Description'),
-    '#description'   => t('A description of the map.'),
-    '#required'      => TRUE,
-    '#default_value' => $d_description,
-  );
-  
-
-  $form['unittype_id'] = array(
-    '#title'       => t('Map Units'),
-    '#type'        => t('select'),
-    '#description' => t("Chose the units for this map"),
-    '#required'    => TRUE,
-    '#default_value' => $d_unittype_id,
-    '#options'     => $units,
-  );
-
-  
-  // add in the properties from the featuremapprop table
-  $num_properties += chado_featuremap_node_form_add_featuremapprop_table_props($form, $form_state, $featuremap_id, $d_properties, $d_removed);
-
-  // add in any new properties that have been added by the user through an AHAH callback
-  $num_new = chado_featuremap_node_form_add_new_props($form, $form_state, $d_properties, $d_removed);
-
-  // add an empty row of field to allow for addition of a new property
-  chado_featuremap_node_form_add_new_empty_props($form, $properties_select);
-  
-
-  return $form;
-}
-/**
- *  validates submission of form when adding or updating a map node
- *
- * @ingroup tripal_featuremap
- */
-function chado_featuremap_validate($node, $form, &$form_state) {
-  $name          = trim($node->title);
-  $featuremap_id = trim($node->featuremap_id);
-  $unittype_id   = trim($node->unittype_id);
-  $description   = trim($node->description);
-  $num_properties = $node->num_properties;
-  $num_new = $node->num_new;
-  
-  $featuremap = 0;
-  // check to make sure the unique name on the map is unique
-  // before we try to insert into chado. If this is an update then we will
-  // have a featuremap_id, therefore we want to look for another map with this
-  // name but with a different featuremap_id. If this is an insert, just look
-  // for a case where the name already exists.
-  if ($node->featuremap_id) {
-    $sql = "
-      SELECT * FROM {featuremap} 
-      WHERE name = :name AND NOT featuremap_id = :featuremap_id
-    ";
-    $featuremap = chado_query($sql, array(':name' => $node->title, ':featurempa_id' => $node->featuremap_id))->fetchObject();
-  }
-  else {
-    $sql = "SELECT * FROM {featuremap} WHERE name = :name";
-    $featuremap = chado_query($sql, array(':name' => $node->title))->fetchObject();
-  }
-  if ($featuremap) {
-    form_set_error('name', t('The unique map name already exists. Please choose another'));
-  }
-  
-}
-/*
- *
- */
-function chado_featuremap_node_form_add_new_empty_props(&$form, $properties_select) {
-
-  // add one more blank set of property fields
-  $form['properties']['new']["new_id"] = array(
-    '#type'          => 'select',
-    '#options'       => $properties_select,
-    '#ahah' => array(
-      'path'    => "tripal_featuremap/properties/description",
-      'wrapper' => 'tripal-featuremap-new_value-desc',
-      'event'   => 'change',
-      'method'  => 'replace',          
-  ),
-  );
-  $form['properties']['new']["new_value"] = array(
-    '#type'          => 'textarea',
-    '#default_value' => '',
-    '#cols'          => 5,
-    '#rows'          => $rows,
-    '#description'   => '<div id="tripal-featuremap-new_value-desc"></div>'
-    );
-    $form['properties']['new']["add"] = array(
-    '#type'         => 'image_button',      
-    '#value'        => t('Add'),
-    '#src'          => drupal_get_path('theme', 'tripal') . '/images/add.png',
-    '#ahah' => array(
-      'path'    => "tripal_featuremap/properties/add",
-      'wrapper' => 'tripal-featuremap-edit-properties-table',
-      'event'   => 'click',
-      'method'  => 'replace',          
-    ),
-    '#attributes' => array('onClick' => 'return false;'),
-    );
-}
-/*
- *
- */
-function chado_featuremap_node_form_add_new_props(&$form, $form_state, &$d_properties, &$d_removed) {
-   
-  // first, add in all of the new properties that were added through a previous AHAH callback
-  $j = 0;
-  $num_properties++;
-
-  // we need to find the
-  if ($form_state['values']) {
-    foreach ($form_state['values'] as $element_name => $value) {
-      if (preg_match('/new_value-(\d+)-(\d+)/', $element_name, $matches)) {
-        $new_id = $matches[1];
-        $rank = $matches[2];
-
-        // skip any properties that the user requested to delete through a previous
-        // AHAH callback or through the current AHAH callback
-        if($d_removed["$new_id-$rank"]) {
-          continue;
-        }
-        if($form_state['post']['remove-' . $new_id . '-' . $rank]) {
-          $d_removed["$new_id-$rank"] = 1;
-          continue;
-        }
-
-        // get this new_id information
-        $cvterm = tripal_core_chado_select('cvterm', array('name', 'definition'), array('cvterm_id' => $new_id));
-
-        // add it to the $d_properties array
-        $d_properties[$new_id][$rank]['name']  = $cvterm->name;
-        $d_properties[$new_id][$rank]['id']    = $new_id;
-        $d_properties[$new_id][$rank]['value'] = $value;
-        $d_properties[$new_id][$rank]['definition']  = $cvterm->definition;
-        $num_properties++;
-
-        // determine how many rows we need in the textarea
-        $rows = 1;
-        if (preg_match('/Abstract/', $cvterm[0]->name)) {
-          $rows = 10;
-        }
-        if ($cvterm[0]->name == 'Authors') {
-          $rows = 2;
-        }
-
-        // add the new fields
-        $form['properties']['new'][$new_id][$rank]["new_id-$new_id-$rank"] = array(
-          '#type'          => 'item',
-          '#value'         => $cvterm[0]->name
-        );
-        $form['properties']['new'][$new_id][$rank]["new_value-$new_id-$rank"] = array(
-          '#type'          => 'textarea',
-          '#default_value' => $value,
-          '#cols'          => 50,
-          '#rows'          => $rows,
-          '#description'   => $cvterm->definition,
-        );
-
-        $form['properties']['new'][$new_id][$rank]["remove-$new_id-$rank"] = array(
-          '#type'         => 'image_button',
-          '#value'        => t('Remove'),
-          '#src'          => drupal_get_path('theme', 'tripal') . '/images/minus.png',
-          '#ahah' => array(
-            'path'    => "tripal_featuremap/properties/minus/$new_id/$rank",
-            'wrapper' => 'tripal-featuremap-edit-properties-table',
-            'event'   => 'click',
-            'method'  => 'replace',
-        ),
-          '#attributes' => array('onClick' => 'return false;'),
-        );
-      }
-    }
-  }
-
-
-  // second add in any new properties added during this callback
-  if($form_state['post']['add']) {
-    $new_id = $form_state['values']['new_id'];
-    $new_value = $form_state['values']['new_value'];
-
-    // get the rank by counting the number of entries
-    $rank = count($d_properties[$new_id]);
-
-    // get this new_id information
-    $cvterm = tripal_core_chado_select('cvterm', array('name', 'definition'), array('cvterm_id' => $new_id));
-
-    // add it to the $d_properties array
-    $d_properties[$new_id][$rank]['name']  = $cvterm->name;
-    $d_properties[$new_id][$rank]['id']    = $new_id;
-    $d_properties[$new_id][$rank]['value'] = $value;
-    $d_properties[$new_id][$rank]['definition']  = $cvterm->definition;
-    $num_properties++;
-
-    // determine how many rows we need in the textarea
-    $rows = 1;
-    if (preg_match('/Abstract/', $cvterm[0]->name)) {
-      $rows = 10;
-    }
-    if ($cvterm[0]->name == 'Authors') {
-      $rows = 2;
-    }
-
-    // add the new fields
-    $form['properties']['new'][$new_id][$rank]["new_id-$new_id-$rank"] = array(
-      '#type'          => 'item',
-      '#value'         => $cvterm[0]->name
-    );
-    $form['properties']['new'][$new_id][$rank]["new_value-$new_id-$rank"] = array(
-      '#type'          => 'textarea',
-      '#default_value' => $new_value,
-      '#cols'          => 50,
-      '#rows'          => $rows,
-      '#description'   => $cvterm->definition,
-    );
-
-    $form['properties']['new'][$new_id][$rank]["remove-$new_id-$rank"] = array(
-      '#type'         => 'image_button',
-      '#value'        => t('Remove'),
-      '#src'          => drupal_get_path('theme', 'tripal') . '/images/minus.png',
-      '#ahah' => array(
-        'path'    => "tripal_featuremap/properties/minus/$new_id/$rank",
-        'wrapper' => 'tripal-featuremap-edit-properties-table',
-        'event'   => 'click',
-        'method'  => 'replace',
-    ),
-      '#attributes' => array('onClick' => 'return false;'),
-    );
-
-  }
-
-  return $num_properties;
-}
-/*
- *
- */
-function chado_featuremap_node_form_add_featuremapprop_table_props(&$form, $form_state, $featuremap_id, &$d_properties, &$d_removed) {
-
-  // get the properties for this featuremap
-  $num_properties = 0;
-
-  if(!$featuremap_id) {
-    return $num_properties;
-  }
-
-  $sql = "
-    SELECT CVT.cvterm_id, CVT.name, CVT.definition, PP.value, PP.rank
-    FROM {featuremapprop} PP
-      INNER JOIN {cvterm} CVT on CVT.cvterm_id = PP.type_id
-    WHERE PP.featuremap_id = :featuremap_id
-    ORDER BY CVT.name, PP.rank
-  ";
-  $featuremap_props = chado_query($sql, array(':featuremap_id' => $featuremap_id));
-  while ($prop = $featuremap_props->fetchObject()) {
-
-    $type_id = $prop->cvterm_id;
-    $rank = count($d_properties[$type_id]);
-
-    // skip any properties that the user requested to delete through a previous
-    // AHAH callback or through the current AHAH callback
-    if($d_removed["$type_id-$rank"]) {
-      continue;
-    }
-    if($form_state['post']['remove-' . $type_id . '-' . $rank]) {
-      $d_removed["$type_id-$rank"] = 1;
-      continue;
-    }
-
-    $d_properties[$type_id][$rank]['name']  = $prop->name;
-    $d_properties[$type_id][$rank]['id']    = $type_id;
-    $d_properties[$type_id][$rank]['value'] = $prop->value;
-    $d_properties[$type_id][$rank]['definition']  = $prop->definition;
-    $num_properties++;
-
-    $form['properties'][$type_id][$rank]["prop_id-$type_id-$rank"] = array(
-      '#type'          => 'item',
-      '#value'         => $prop->name,
-    );
-    $form['properties'][$type_id][$rank]["prop_value-$type_id-$rank"] = array(
-      '#type'          => 'textarea',
-      '#default_value' => $prop->value,
-      '#cols'          => 50,
-      '#rows'          => $rows,
-      '#description'   => $prop->definition,
-    );
-
-    $form['properties'][$type_id][$rank]["remove-$type_id-$rank"] = array(
-      '#type'         => 'image_button',
-      '#value'        => t('Remove'),
-      '#src'          => drupal_get_path('theme', 'tripal') . '/images/minus.png',
-      '#ahah' => array(
-        'path'    => "tripal_featuremap/properties/minus/$type_id/$rank",
-        'wrapper' => 'tripal-featuremap-edit-properties-table',
-        'event'   => 'click',
-        'method'  => 'replace',
-    ),
-      '#attributes' => array('onClick' => 'return false;'),
-    );
-  }
-  return $num_properties;
-}
-/*
- *
- */
-function tripal_featuremap_theme_node_form_properties($form) {
-  $rows = array();
-
-  if ($form['properties']) {
-
-    // first add in the properties derived from the featuremapprop table
-    // the array tree for these properties looks like this:
-    // $form['properties'][$type_id][$rank]["prop_id-$type_id-$rank"]
-    foreach ($form['properties'] as $type_id => $elements) {
-      // there are other fields in the properties array so we only
-      // want the numeric ones those are our type_id
-      if (is_numeric($type_id)) {
-        foreach ($elements as $rank => $element) {
-          if (is_numeric($rank)) {
-            $rows[] = array(
-            drupal_render($element["prop_id-$type_id-$rank"]),
-            drupal_render($element["prop_value-$type_id-$rank"]),
-            drupal_render($element["remove-$type_id-$rank"]),
-            );
-          }
-        }
-      }
-    }
-
-    // second, add in any new properties added by the user through AHAH callbacks
-    // the array tree for these properties looks like this:
-    // $form['properties']['new'][$type_id][$rank]["new_id-$new_id-$rank"]
-    foreach ($form['properties']['new'] as $type_id => $elements) {
-      if (is_numeric($type_id)) {
-        foreach ($elements as $rank => $element) {
-          if (is_numeric($rank)) {
-            $rows[] = array(
-            drupal_render($element["new_id-$type_id-$rank"]),
-            drupal_render($element["new_value-$type_id-$rank"]),
-            drupal_render($element["remove-$type_id-$rank"]),
-            );
-          }
-        }
-      }
-    }
-
-    // finally add in a set of blank field for adding a new property
-    $rows[] = array(
-    drupal_render($form['properties']['new']['new_id']),
-    drupal_render($form['properties']['new']['new_value']),
-    drupal_render($form['properties']['new']['add']),
-    );
-  }
-
-  $headers = array('Property Type','Value', '');
-  return theme('table', $headers, $rows, array('id'=> "tripal-featuremap-edit-properties-table"));
-}
-
-/*
- *
- */
-function tripal_featuremap_property_add() {
-  $status = TRUE;
-
-  // prepare and render the form
-  $form = tripal_core_ahah_prepare_form();
-
-  // we only want to return the properties as that's all we'll replace with this AHAh callback
-  $data = tripal_featuremap_theme_node_form_properties($form);
-
-  // bind javascript events to the new objects that will be returned
-  // so that AHAH enabled elements will work.
-  $settings = tripal_core_ahah_bind_events();
-
-  // return the updated JSON
-  drupal_json(
-  array(
-      'status'   => $status, 
-      'data'     => $data,
-      'settings' => $settings,
-  )
-  );
-}
-/*
- *
- */
-function tripal_featuremap_property_delete() {
-  $status = TRUE;
-
-  // prepare and render the form
-  $form = tripal_core_ahah_prepare_form();
-
-  // we only want to return the properties as that's all we'll replace with this AHAh callback
-  $data = tripal_featuremap_theme_node_form_properties($form);
-
-  // bind javascript events to the new objects that will be returned
-  // so that AHAH enabled elements will work.
-  $settings = tripal_core_ahah_bind_events();
-
-  // return the updated JSON
-  drupal_json(
-  array(
-      'status'   => $status, 
-      'data'     => $data,
-      'settings' => $settings,
-  )
-  );
-}
-/*
- *
- */
-function tripal_featuremap_property_get_description() {
-  $new_id = $_POST['new_id'];
-
-  $values = array('cvterm_id' => $new_id);
-  $cvterm = tripal_core_chado_select('cvterm', array('definition'), $values);
-
-  $description = '&nbsp;';
-  if ($cvterm[0]->definition) {
-    $description = $cvterm[0]->definition;
-  }
-  drupal_json(
-    array(
-      'status' => TRUE,
-      'data'   => '<div id="tripal-featuremap-new_value-desc">' . $description . '</div>',
-    )
-  );
-}
-/*
- *
- */
-function theme_chado_featuremap_node_form($form) {
-
-  $properties_table = tripal_featuremap_theme_node_form_properties($form);
-
-  $markup  = drupal_render($form['featuremap_id']);
-  $markup .= drupal_render($form['title']);
-  $markup .= drupal_render($form['unittype_id']);
-  $markup .= drupal_render($form['description']);
-  $markup .= "<b>Include Additional Details</b><br>You may add additional 
-    properties to this map by scrolling to the bottom of this table, selecting 
-    a property type from the dropdown and adding text.  You may add as many 
-    properties as desired by clicking the plus button on the right.  To 
-    remove a property, click the minus button. If a property is not available
-    you may add it by " . l('adding the term', 'admin/tripal/tripal_cv/cvterm/add') . "
-    to the <b>featuremap_property</b> vocabulary within the <b>tripal</b> database.";
-  $markup .= $properties_table;
-  $markup .= drupal_render($form['is_obsolete']);
-
-  $form['properties'] = array(
-    '#type' => 'markup',
-    '#value' =>  $markup,
-  );
-  return drupal_render($form);
-}

+ 0 - 142
tripal_featuremap/theme/node--chado-featuremap.tpl.php

@@ -1,142 +0,0 @@
-<?php
-// Purpose: This template provides the layout of the featuremap node (page)
-//   using the same templates used for the various featuremap content blocks.
-//
-// To Customize the Libray Node Page:
-//   - This Template: customize basic layout and which elements are included
-//   - Using Panels: Override the node page using Panels3 and place the blocks
-//       of content as you please. This method requires no programming. See
-//       the Tripal User Guide for more details
-//   - Block Templates: customize the content/layout of each block of stock 
-//       content. These templates are found in the tripal_stock subdirectory
-//
-// Variables Available:
-//   - $node: a standard object which contains all the fields associated with
-//       nodes including nid, type, title, taxonomy. It also includes stock
-//       specific fields such as stock_name, uniquename, stock_type, synonyms,
-//       properties, db_references, object_relationships, subject_relationships,
-//       organism, etc.
-//   NOTE: For a full listing of fields available in the node object the
-//       print_r $node line below or install the Drupal Devel module which 
-//       provides an extra tab at the top of the node page labelled Devel
-
-$featuremap  = $variables['node']->featuremap;
-
-// get the template settings
-$template_settings = theme_get_setting('tripal');
-
-// toggle the sidebar if desired
-$no_sidebar = 0;
-if (is_array($template_settings['tripal_no_sidebar']) and 
-   $template_settings['tripal_no_sidebar']['featuremap']) {
-  $no_sidebar = 1;
-}
-
-if ($teaser) { 
-  print theme('tripal_featuremap_teaser',$variables); 
-} 
-else { ?>
-
-<script type="text/javascript">
-(function ($) {
-  Drupal.behaviors.featuremapBehavior = {
-    attach: function (context, settings){ <?php 
-      if ($no_sidebar) { ?>    
-        // hide the resource side bar and strech the details section    
-        $(".tripal_toc").hide();
-        $(".tripal_details").addClass("tripal_details_full");
-        $(".tripal_details_full").removeClass("tripal_details"); <?php
-      } else { ?>
-        // use default resource sidebar
-        $(".tripal-info-box").hide(); <?php
-      } ?>
- 
-      // iterate through all of the info boxes and add their titles
-      // to the table of contents
-      $(".tripal-info-box-title").each(function(){
-        var parent = $(this).parent();
-        var id = $(parent).attr('id');
-        var title = $(this).text();
-        $('#tripal_featuremap_toc_list').append('<li><a href="#'+id+'" class="tripal_featuremap_toc_item">'+title+'</a></li>');
-      });
-
-      // when a title in the table of contents is clicked, then
-      // show the corresponding item in the details box
-      $(".tripal_featuremap_toc_item").click(function(){
-         $(".tripal-info-box").hide();
-         href = $(this).attr('href');
-         $(href).fadeIn('slow');
-         // we want to make sure our table of contents and the details
-         // box stay the same height
-         $("#tripal_featuremap_toc").height($(href).parent().height());
-         return false;
-      }); 
-
-      // we want the base details to show up when the page is first shown 
-      // unless the user specified a specific block
-      var block = window.location.href.match(/[\?|\&]block=(.+?)\&/)
-      if(block == null){
-         block = window.location.href.match(/[\?|\&]block=(.+)/)
-      }
-      if(block != null){
-         $("#tripal_featuremap-"+block[1]+"-box").show();
-      } else {
-         $("#tripal_featuremap-base-box").show();
-      }
-
-      $("#tripal_featuremap_toc").height($("#tripal_featuremap-base-box").parent().height());
-    }     
-  };
-})(jQuery);
-</script>
-
-<div id="tripal_featuremap_details" class="tripal_details">
-
-   <!-- Basic Details Theme -->
-   <?php print theme('tripal_featuremap_base',$node); ?>
-   
-   <!-- Map Features -->
-   <?php print theme('tripal_featuremap_featurepos',$node); ?>
-
-   <!-- Properties -->
-   <?php print theme('tripal_featuremap_properties',$node); ?>
-   
-   <!-- Publications -->
-   <?php print theme('tripal_featuremap_publications',$node); ?>
-   
-   <!-- Cross References -->
-   <?php print theme('tripal_featuremap_references',$node); ?>
-
-   <!-- Resource Blocks CCK elements --><?php
-   for($i = 0; $i < count($node->field_resource_titles); $i++){
-     if($node->field_resource_titles[$i]['value']){ ?>
-       <div id="tripal_featuremap-resource_<?php print $i?>-box" class="tripal_featuremap-info-box tripal-info-box">
-         <div class="tripal_featuremap-info-box-title tripal-info-box-title"><?php print $node->field_resource_titles[$i]['value'] ?></div>
-         <?php print $node->field_resource_blocks[$i]['value']; ?>
-       </div><?php
-     }
-   }?>
-   
-   <!-- Let modules add more content -->
-
-   <?php print $content ?>
-</div>
-
-<!-- Table of contents -->
-<div id="tripal_featuremap_toc" class="tripal_toc">
-   <div id="tripal_featuremap_toc_title" class="tripal_toc_title">Resources</div>
-   <ul id="tripal_featuremap_toc_list" class="tripal_toc_list">
-   
-     <!-- Resource Links CCK elements --><?php
-     for($i = 0; $i < count($node->field_resource_links); $i++){
-       if($node->field_resource_links[$i]['value']){
-         $matches = preg_split("/\|/",$node->field_resource_links[$i]['value']);?>
-         <li><a href="<?php print $matches[1] ?>" target="_blank"><?php print $matches[0] ?></a></li><?php
-       }
-     }?>
-     
-     <?php // ADD CUSTOMIZED <li> LINKS HERE ?>
-   </ul>
-</div>
-
-<?php } ?>

+ 0 - 5
tripal_featuremap/theme/tripal_featuremap_help.tpl.php → tripal_featuremap/theme/tripal_featuremap.help.tpl.php

@@ -1,8 +1,3 @@
-<h3>Tripal Feature Map Quick Links:</h3>
-<ul>
-  <li><a href="<?php print url('admin/tripal/tripal_featuremap/configuration') ?>">Map Configuration</a></li>
-</ul>
-
 <h3>Module Description:</h3>
 <p>The Tripal Map module is an interface for the Chado Map module which groups features (sequences) into 
    maps (typically genetic maps).

+ 0 - 0
tripal_featuremap/theme/tripal_featuremap.theme.inc


+ 76 - 0
tripal_featuremap/theme/tripal_featuremap/tripal_featuremap.base.tpl.php

@@ -0,0 +1,76 @@
+<?php
+
+$featuremap  = $variables['node']->featuremap;
+
+// expand the description field
+$featuremap = tripal_core_expand_chado_vars($featuremap, 'field', 'featuremap.description');
+
+?>
+<div id="tripal_featuremap-base-box" class="tripal_featuremap-info-box tripal-info-box">
+  <div class="tripal_featuremap-info-box-title tripal-info-box-title">Map Details</div>
+  <div class="tripal_featuremap-info-box-desc tripal-info-box-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();
+  
+  // Map Name row
+  $rows[] = array(
+    array(
+      'data' => 'Map Name',
+      'header' => TRUE
+    ),
+    $featuremap->name
+  );
+  // Map Units
+  $rows[] = array(
+    array(
+      'data' => 'Map Units',
+      'header' => TRUE
+    ),
+    $featuremap->unittype_id->name
+  );
+  // allow site admins to see the feature ID
+  if (user_access('access administration pages')) {
+    // Feature Map ID
+    $rows[] = array(
+      array(
+        'data' => 'Feature Map ID',
+        'header' => TRUE
+      ),
+      $featuremap->featuremap_id
+    );
+  }
+
+  // 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_featuremap-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 (property_exists($featuremap, 'description')) { ?>
+    <div style="text-align: justify"><?php print $featuremap->description; ?></div> <?php  
+  } ?>
+</div>

+ 158 - 0
tripal_featuremap/theme/tripal_featuremap/tripal_featuremap.featurepos.tpl.php

@@ -0,0 +1,158 @@
+<?php
+$featuremap = $variables['node']->featuremap;
+$feature_positions = array();
+
+// expand the featuremap object to include the records from the featurepos table
+// specify the number of features to show by default and the unique pager ID
+$num_results_per_page = 25; 
+$featurepos_pager_id = 0;
+
+// get the features aligned on this map
+$options = array(  
+  'return_array' => 1,
+  'order_by' => array('map_feature_id' => 'ASC'),
+  'pager' => array(
+    'limit' => $num_results_per_page, 
+    'element' => $featurepos_pager_id
+  ),
+  'include_fk' => array(
+    'map_feature_id' => array(
+      'type_id' => 1,
+      'organism_id' => 1,
+    ),
+    'feature_id' => array(
+      'type_id' => 1,
+    ),
+    'featuremap_id' => array(
+       'unittype_id' => 1,
+    ),
+  ),
+);
+
+$featuremap = tripal_core_expand_chado_vars($featuremap, 'table', 'featurepos', $options);
+$feature_positions = $featuremap->featurepos;
+
+
+// the total number of records for the paged query is stored in a session variable
+$total_features = $_SESSION['chado_pager'][$featurepos_pager_id]['total_records'];
+
+
+if(count($feature_positions) > 0){ ?>
+  <div id="tripal_featuremap-featurepos-box" class="tripal_featuremap-info-box tripal-info-box">
+    <div class="tripal_featuremap-info-box-title tripal-info-box-title">Map Features</div>
+    <div class="tripal_featuremap-info-box-desc tripal-info-box-desc">This map contains <?php print number_format($total_features) ?> 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('Landmark', 'Type', 'Organism', 'Feature Name', 'Type', 'Position');
+    
+    // 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 ($feature_positions as $position){
+      $map_feature = $position->map_feature_id;
+      $feature     = $position->feature_id;  
+      $organism    = $map_feature->organism_id; 
+
+      // check if there are any values in the featureposprop table for the start and stop
+      $mappos = $position->mappos;
+      $options = array(
+        'return_array' => 1,
+        'include_fk' => array(
+          'type_id' => 1,            
+        ),
+      );
+      $position = tripal_core_expand_chado_vars($position, 'table', 'featureposprop', $options);
+      $featureposprop = $position->featureposprop;
+      $start = 0;
+      $stop = 0;
+      if (is_array($featureposprop)) {
+        foreach ($featureposprop as $index => $property) {
+           if ($property->type_id->name == 'start') {
+             $start = $property->value;
+           }
+           if ($property->type_id->name == 'stop') {
+             $stop = $property->value;
+           }
+        }      
+      }  
+      if ($start and $stop and $start != $stop) {
+        $mappos = "$start-$stop";
+      }
+      if ($start and !$stop) {
+        $mappos = $start;
+      } 
+      if ($start and $stop and $start == $stop) {
+        $mappos = $start;
+      }
+      
+      $mfname = $map_feature->name;
+      if (property_exists($map_feature, 'nid')) {
+        $mfname =  l($mfname, 'node/' . $map_feature->nid, array('attributes' => array('target' => '_blank')));
+      }
+      $orgname = $organism->genus ." " . $organism->species ." (" . $organism->common_name .")";
+      if (property_exists($organism, 'nid')) {
+        $orgname = l(
+          "<i>" . $organism->genus . " " . $organism->species . "</i> (" . $organism->common_name .")", 
+          "node/". $organism->nid, 
+          array('html' => TRUE, 'attributes' => array('target' => '_blank'))
+        );
+      }
+      $organism =  $organism->genus . ' ' . $organism->species;
+      
+      $fname = $feature->name;
+      if (property_exists($feature, 'nid')) {
+        $fname = l($fname, 'node/' . $feature->nid, array('attributes' => array('target' => '_blank')));
+      }
+        
+      $rows[] = array(
+        $mfname,
+        $map_feature->type_id->name,
+        $orgname,
+        $fname,
+        $feature->type_id->name,
+        $mappos . ' ' . $position->featuremap_id->unittype_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_featuremap-table-featurepos',
+      ),
+      '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' => 'features'. 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' => $featurepos_pager_id,
+      'parameters' => array(
+        'block' => 'featurepos'
+      ),
+      'quantity' => $num_results_per_page,
+    );
+    print theme_pager($pager); ?>
+  </div><?php 
+}?>
+

+ 52 - 0
tripal_featuremap/theme/tripal_featuremap/tripal_featuremap.properties.tpl.php

@@ -0,0 +1,52 @@
+<?php
+
+$featuremap = $variables['node']->featuremap;
+$options = array('return_array' => 1);
+$featuremap = tripal_core_expand_chado_vars($featuremap, 'table', 'featuremapprop', $options);
+$properties = $featuremap->featuremapprop;
+
+if(count($properties) > 0){ ?>
+
+  <div id="tripal_featuremap-properties-box" class="tripal_featuremap-info-box tripal-info-box">
+    <div class="tripal_featuremap-info-box-title tripal-info-box-title">Properties</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('Property Name', 'Value');
+    
+    // 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 ($properties as $property){
+      $property = tripal_core_expand_chado_vars($property,'field','featuremapprop.value');
+      $rows[] = array(
+        ucfirst(preg_replace('/_/', ' ', $property->type_id->name)),
+        urldecode($property->value)
+      );
+    }
+     
+    // 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_featuremap-table-properties',
+      ),
+      '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> <?php
+}

+ 64 - 0
tripal_featuremap/theme/tripal_featuremap/tripal_featuremap.publication.tpl.php

@@ -0,0 +1,64 @@
+<?php
+$featuremap  = $variables['node']->featuremap;
+
+// expand featuremap to include pubs 
+$featuremap = tripal_core_expand_chado_vars($featuremap, 'table', 'featuremap_pub');
+$pubs = $featuremap->featuremap_pub;
+$pubs = tripal_core_expand_chado_vars($pubs, 'field', 'pub.title');
+
+if (count($pubs) > 0) { ?>
+
+  <div id="tripal_featuremap-pub-box" class="tripal_featuremap-info-box tripal-info-box">
+    <div class="tripal_featuremap-info-box-title tripal-info-box-title">Publications</div>
+    <div class="tripal_featuremap-info-box-desc tripal-info-box-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
+    $headers = array('Year', 'Publication');
+    
+    // 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.dr
+    $rows = array();
+    
+    foreach ($pubs AS $pub) {
+      // get the citation
+      $values = array(
+        'pub_id' => $pub->pub_id->pub_id,
+        'type_id' => array(
+          'name' => 'Citation',
+        ),
+      );
+      $citation = tripal_core_generate_chado_var('pubprop', $values);
+      $citation = tripal_core_expand_chado_vars($citation, 'field', 'pubprop.value');
+      if(property_exists($pub->pub_id, 'nid')) {
+        $citation->value = l($citation->value, 'node/' . $pub->pub_id->nid, array('attributes' => array('target' => '_blank')));
+      }
+      $rows[] = array(
+        $pub->pub_id->pyear,
+        $citation->value,
+      );
+    }
+      
+    // 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-publications',
+      ),
+      '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> <?php 
+}?>

+ 69 - 0
tripal_featuremap/theme/tripal_featuremap/tripal_featuremap.references.tpl.php

@@ -0,0 +1,69 @@
+<?php
+$featuremap = $variables['node']->featuremap;
+$references = array();
+
+// expand the featuremap object to include the records from the featuremap_dbxref table
+$options = array('return_array' => 1);
+$featuremap = tripal_core_expand_chado_vars($featuremap, 'table', 'featuremap_dbxref', $options);
+$featuremap_dbxrefs = $featuremap->featuremap_dbxref;
+if (count($featuremap_dbxrefs) > 0 ) {
+  foreach ($featuremap_dbxrefs as $featuremap_dbxref) {    
+    $references[] = $featuremap_dbxref->dbxref_id;
+  }
+}
+
+
+if(count($references) > 0){ ?>
+  <div id="tripal_featuremap-references-box" class="tripal_featuremap-info-box tripal-info-box">
+    <div class="tripal_featuremap-info-box-title tripal-info-box-title">Cross References</div>
+    <div class="tripal_featuremap-info-box-desc tripal-info-box-desc">External references for this map</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('Dababase', 'Accession');
+    
+    // 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 ($references as $dbxref){
+      $dbname = $dbxref->db_id->name; 
+      if ($dbxref->db_id->url) { 
+        $dbname = l($dbname, $dbxref->db_id->url, array('attributes' => array('target' => '_blank')));
+      } 
+      
+      $accession = $dbxref->accession; 
+      if ($dbxref->db_id->urlprefix) { 
+        $accession = l($accession, $dbxref->db_id->urlprefix . $dbxref->accession, array('attributes' => array('target' => '_blank')));
+      } 
+      $rows[] = array(
+        $dbname,
+        $accession
+      );
+    } 
+    
+    // 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_featuremap-table-references',
+      ),
+      '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><?php 
+}?>
+

+ 16 - 0
tripal_featuremap/theme/tripal_featuremap/tripal_featuremap.teaser.tpl.php

@@ -0,0 +1,16 @@
+<?php
+$node = $variables['node'];
+$featuremap = $variables['node']->featuremap;
+$featuremap = tripal_core_expand_chado_vars($featuremap,'field','featuremap.description'); ?>
+
+<div class="tripal_featuremap-teaser tripal-teaser"> 
+  <div class="tripal-featuremap-teaser-title tripal-teaser-title"><?php 
+    print l($node->title, "node/$node->nid", array('html' => TRUE));?>
+  </div>
+  <div class="tripal-featuremap-teaser-text tripal-teaser-text"><?php 
+    print substr($featuremap->description, 0, 650);
+    if (strlen($featuremap->description) > 650) {
+      print "... " . l("[more]", "node/$node->nid");
+    } ?>
+  </div>
+</div>

+ 0 - 39
tripal_featuremap/theme/tripal_featuremap/tripal_featuremap_base.tpl.php

@@ -1,39 +0,0 @@
-<?php
-
-$featuremap  = $variables['node']->featuremap;
-
-// expand the description field
-$featuremap = tripal_core_expand_chado_vars($featuremap, 'field', 'featuremap.description');
-
-?>
-<div id="tripal_featuremap-base-box" class="tripal_featuremap-info-box tripal-info-box">
-  <div class="tripal_featuremap-info-box-title tripal-info-box-title">Map Details</div>
-  <div class="tripal_featuremap-info-box-desc tripal-info-box-desc"></div>
-
-   <table id="tripal_featuremap-base-table" class="tripal_featuremap-table tripal-table tripal-table-vert">
-      <tr class="tripal_featuremap-table-even-row tripal-table-even-row">
-        <th nowrap>Name</th>
-        <td><?php print $featuremap->name; ?></td>
-      </tr>
-      <tr class="tripal_featuremap-table-odd-row tripal-table-odd-row">
-        <th>Map Units</th>
-        <td><?php print $featuremap->unittype_id->name; ?></td>
-      </tr>
-      <tr class="tripal_featuremap-table-even-row tripal-table-even-row">
-        <th>Description</th>
-        <td><?php
-           // right now we only have one property for featuremaps. So we can just
-           // refernece it directly.  If we had more than one property
-           // we would need to convert this to an if statment and loop
-           // until we found the right one.
-           print $featuremap->description?>
-        </td>
-     	</tr>
-     	<!--     
-     	<tr class="tripal_featuremap-table-odd-row tripal-table-odd-row">
-        <th>Internal ID</th>
-        <td><?php print $featuremap->featuremap_id; ?></td>
-      </tr>  
-       -->     	                                
-   </table>
-</div>

+ 0 - 126
tripal_featuremap/theme/tripal_featuremap/tripal_featuremap_featurepos.tpl.php

@@ -1,126 +0,0 @@
-<?php
-$featuremap = $variables['node']->featuremap;
-$feature_positions = array();
-
-// expand the featuremap object to include the records from the featurepos table
-// specify the number of features to show by default and the unique pager ID
-$num_results_per_page = 25; 
-$featurepos_pager_id = 0;
-
-// get the features aligned on this map
-$options = array(  
-  'return_array' => 1,
-  'order_by' => array('map_feature_id' => 'ASC'),
-  'pager' => array('limit' => $num_results_per_page, 'element' => $featurepos_pager_id),
-  'include_fk' => array(
-    'map_feature_id' => array(
-      'type_id' => 1,
-      'organism_id' => 1,
-    ),
-    'feature_id' => array(
-      'type_id' => 1,
-    ),
-    'featuremap_id' => array(
-       'unittype_id' => 1,
-    ),
-  ),
-);
-
-$featuremap = tripal_core_expand_chado_vars($featuremap, 'table', 'featurepos', $options);
-$feature_positions = $featuremap->featurepos;
-
-// create the pager.  
-global $pager_total_items;
-$featurepos_pager = theme('pager', array(), $num_results_per_page, $featurepos_pager_id, array('block' => 'featurepos'));
-$total_features = $pager_total_items[$featurepos_pager_id];
-
-
-if(count($feature_positions) > 0){ ?>
-  <div id="tripal_featuremap-featurepos-box" class="tripal_featuremap-info-box tripal-info-box">
-    <div class="tripal_featuremap-info-box-title tripal-info-box-title">Map Features</div>
-    <div class="tripal_featuremap-info-box-desc tripal-info-box-desc">This Map contains <?php print number_format($total_features) ?> features:</div>
-    <table id="tripal_featuremap-featurepos-table" class="tripal_featuremap-table tripal-table tripal-table-horz">
-      <tr>
-        <th>Landmark</th>
-        <th>Type</th>
-        <th>Organism</th>
-        <th>Feature Name</th>
-        <th>Type</th>
-        <th>Position</th>
-      </tr> <?php
-      $i = 0; 
-      foreach ($feature_positions as $position){
-        $map_feature = $position->map_feature_id;
-        $feature = $position->feature_id;  
-        $organism = $map_feature->organism_id; 
-
-        // check if there are any values in the featureposprop table for the start and stop
-        $mappos = $position->mappos;
-        $options = array(
-          'return_array' => 1,
-          'include_fk' => array(
-            'type_id' => 1,            
-          ),
-        );
-        $position = tripal_core_expand_chado_vars($position, 'table', 'featureposprop', $options);
-        $featureposprop = $position->featureposprop;
-        if (is_array($featureposprop)) {
-          foreach ($featureposprop as $index => $property) {
-             if ($property->type_id->name == 'start') {
-               $start = $property->value;
-             }
-             if ($property->type_id->name == 'stop') {
-               $stop = $property->value;
-             }
-          }      
-        }  
-        if ($start and $stop and $start != $stop) {
-          $mappos = "$start-$stop";
-        }
-        if ($start and !$stop) {
-          $mappos = $start;
-        } 
-        if ($start and $stop and $start == $stop) {
-          $mappos = $start;
-        }
-        
-        $class = 'tripal_featuremap-table-odd-row tripal-table-odd-row';
-        if($i % 2 == 0 ){
-           $class = 'tripal_featuremap-table-even-row tripal-table-even-row';
-        } ?>
-        <tr class="<?php print $class ?>">
-          <td> <?php 
-            if ($map_feature->nid) { 
-              print l($map_feature->name, 'node/' . $map_feature->nid, array('attributes' => array('target' => '_blank')));
-            } 
-            else { 
-              print $map_feature->name;
-            } ?>
-          </td>          
-          <td><?php print $map_feature->type_id->name ?></td>
-          <td><?php 
-            if ($organism->nid) { 
-              print l($organism->genus . ' ' . $organism->species, 'node/' . $organism->nid, array('attributes' => array('target' => '_blank')));
-            } 
-            else { 
-              print $organism->genus . ' ' . $organism->species;
-            } ?>
-          </td>
-          <td> <?php 
-            if ($feature->nid) { 
-              print l($feature->name, 'node/' . $feature->nid, array('attributes' => array('target' => '_blank')));
-            } 
-            else { 
-              print $feature->name;
-            } ?>
-          </td>
-          <td><?php print $feature->type_id->name ?></td>
-          <td><?php print $mappos ?>&nbsp;<?php print $position->featuremap_id->unittype_id->name ?> </td>
-        </tr> <?php
-        $i++;  
-      } ?>
-    </table> <?php 
-    print $featurepos_pager ?>
-  </div><?php 
-}?>
-

+ 0 - 50
tripal_featuremap/theme/tripal_featuremap/tripal_featuremap_properties.tpl.php

@@ -1,50 +0,0 @@
-<?php
-
-$featuremap = $node->featuremap;
-
-// expand the featuremap to include the properties.
-$options = array(
-  'return_array' => 1,
-  'order_by' => array('rank' => 'ASC'),
-);
-$featuremap = tripal_core_expand_chado_vars($featuremap, 'table', 'featuremapprop', $options);
-$featuremapprops = $featuremap->featuremapprop;
-$properties = array();
-if (is_array($featuremapprops)) {
-  foreach ($featuremapprops as $property) {
-    // skip the following properties as those are already on other templates
-    if ($property->type_id->name == 'Map Dbxref')  {
-      continue;
-    }
-    $property = tripal_core_expand_chado_vars($property,'field','featuremapprop.value');
-    $properties[] = $property;
-  }
-}
-if(count($properties) > 0){ ?>
-
-  <div id="tripal_featuremap-properties-box" class="tripal_featuremap-info-box tripal-info-box">
-    <div class="tripal_featuremap-info-box-title tripal-info-box-title">Properties</div>
-    <div class="tripal_featuremap-info-box-desc tripal-info-box-desc">Properties for the featuremap '<?php print $node->featuremap->name ?>' include:</div>
-
-    <table class="tripal_featuremap-table tripal-table tripal-table-horz">
-    <tr>
-      <th>Property Name</th>
-      <th>Value</th>
-    </tr>
-	  <?php	// iterate through each property
-		  $i = 0;
-		  foreach ($properties as $result){
-		    $result = tripal_core_expand_chado_vars($result,'field','featuremapprop.value');
-		    $class = 'tripal_featuremap-table-odd-row tripal-table-odd-row';
-        if($i % 2 == 0 ){
-           $class = 'tripal_featuremap-table-odd-row tripal-table-even-row';
-        } ?>
-			  <tr class="<?php print $class ?>">
-  			  <td><?php print $result->type_id->name ?></td>
-  			  <td><?php print urldecode($result->value) ?></td>
-  			</tr> <?php
-			  $i++;
-		  } ?>
-		</table>
-  </div> <?php
-}

+ 0 - 33
tripal_featuremap/theme/tripal_featuremap/tripal_featuremap_publication.tpl.php

@@ -1,33 +0,0 @@
-<?php
-$featuremap  = $variables['node']->featuremap;
-
-// expand featuremap to include pubs 
-$featuremap = tripal_core_expand_chado_vars($featuremap, 'table', 'featuremap_pub');
-$pubs = $featuremap->featuremap_pub;
-$pubs = tripal_core_expand_chado_vars($pubs, 'field', 'pub.title', array('return_array' => 1));
-?>
-
-<div id="tripal_featuremap-pub-box" class="tripal_featuremap-info-box tripal-info-box">
-  <div class="tripal_featuremap-info-box-title tripal-info-box-title">Publications</div>
-  <div class="tripal_featuremap-info-box-desc tripal-info-box-desc"></div>
-
-  <table id="tripal_featuremap-pub-table" class="tripal_featuremap-table tripal-table tripal-table-vert" style="border-bottom:solid 2px #999999">
-    <tr>
-      <th>Year</th>
-      <th>Reference</th>
-      <th>Title</th></tr> <?php
-      $i = 0;
-      foreach ($pubs AS $pub) {
-        $class = 'tripal_featuremap-table-odd-row tripal-table-odd-row';
-        if($i % 2 == 0 ){
-           $class = 'tripal_featuremap-table-odd-row tripal-table-even-row';
-        } ?>
-    	  <tr class="<?php print $class ?>">
-    	    <td><?php print $pub->pub_id->pyear ?></td>
-    	    <td><?php print $pub->pub_id->uniquename ?></td>
-    	    <td><?php print $pub->pub_id->title ?></td>
-    	  </tr><?php 
-    	  $i++;
-      }  ?>
-  </table>
-</div>

+ 0 - 56
tripal_featuremap/theme/tripal_featuremap/tripal_featuremap_references.tpl.php

@@ -1,56 +0,0 @@
-<?php
-$featuremap = $variables['node']->featuremap;
-$references = array();
-
-// expand the featuremap object to include the records from the featuremap_dbxref table
-$options = array('return_array' => 1);
-$featuremap = tripal_core_expand_chado_vars($featuremap, 'table', 'featuremap_dbxref', $options);
-$featuremap_dbxrefs = $featuremap->featuremap_dbxref;
-if (count($featuremap_dbxrefs) > 0 ) {
-  foreach ($featuremap_dbxrefs as $featuremap_dbxref) {    
-    $references[] = $featuremap_dbxref->dbxref_id;
-  }
-}
-
-if(count($references) > 0){ ?>
-  <div id="tripal_featuremap-references-box" class="tripal_featuremap-info-box tripal-info-box">
-    <div class="tripal_featuremap-info-box-title tripal-info-box-title">Cross References</div>
-    <div class="tripal_featuremap-info-box-desc tripal-info-box-desc">This Map is also available in the following databases:</div>
-    <table id="tripal_featuremap-references-table" class="tripal_featuremap-table tripal-table tripal-table-horz">
-      <tr>
-        <th>Dababase</th>
-        <th>Accession</th>
-      </tr> <?php
-      $i = 0; 
-      foreach ($references as $dbxref){         
-        $class = 'tripal_featuremap-table-odd-row tripal-table-odd-row';
-        if($i % 2 == 0 ){
-           $class = 'tripal_featuremap-table-even-row tripal-table-even-row';
-        } ?>
-        <tr class="<?php print $class ?>">
-          <td> <?php 
-            if ($dbxref->db_id->url) { 
-              print l($dbxref->db_id->name, $dbxref->db_id->url, array('attributes' => array('target' => '_blank'))) . '<br> ' . $dbxref->db_id->description;             
-            } 
-            else { 
-              print $dbxref->db_id->name . '<br>' . $dbxref->db_id->description;
-            } ?>
-          </td>
-          <td> <?php 
-            if ($dbxref->db_id->urlprefix) { 
-              print l($dbxref->db_id->name . ':' . $dbxref->accession, $dbxref->db_id->urlprefix . $dbxref->accession, array('attributes' => array('target' => '_blank')));
-            } 
-            else { 
-              print $dbxref->db_id->name . ':' . $dbxref->accession; 
-            }
-            if ($dbxref->is_primary) {
-              print " <i>(primary cross-reference)</i>";
-            } ?>
-          </td>
-        </tr> <?php
-        $i++;  
-      } ?>
-    </table>
-  </div><?php 
-}?>
-

+ 0 - 60
tripal_featuremap/theme/tripal_featuremap/tripal_featuremap_teaser.tpl.php

@@ -1,60 +0,0 @@
-<?php
-
-$featuremap  = $variables['node']->featuremap;
-
-// expand the featuremap to include the properties.
-$featuremap = tripal_core_expand_chado_vars($featuremap,'table','featuremapprop');
-$featuremap = tripal_core_expand_chado_vars($featuremap,'field','featuremapprop.value');
-
-?>
-<div id="tripal_featuremap-base-box" class="tripal_featuremap-info-box tripal-info-box">
-  <div class="tripal_featuremap-info-box-title tripal-info-box-title">featuremap Details</div>
-  <div class="tripal_featuremap-info-box-desc tripal-info-box-desc"></div>
-
-   <?php if(strcmp($featuremap->is_obsolete,'t')==0){ ?>
-      <div class="tripal_featuremap-obsolete">This featuremap is obsolete</div>
-   <?php }?>
-   <table id="tripal_featuremap-base-table" class="tripal_featuremap-table tripal-table tripal-table-vert">
-      <tr class="tripal_featuremap-table-even-row tripal-table-even-row">
-        <th nowrap>Unique Name</th>
-        <td><?php print $featuremap->uniquename; ?></td>
-      </tr>
-      <tr class="tripal_featuremap-table-odd-row tripal-table-odd-row">
-        <th>Internal ID</th>
-        <td><?php print $featuremap->featuremap_id; ?></td>
-      </tr>
-      <tr class="tripal_featuremap-table-even-row tripal-table-even-row">
-        <th>Organism</th>
-        <td>
-          <?php if ($featuremap->organism_id->nid) { 
-      	   print "<a href=\"".url("node/".$featuremap->organism_id->nid)."\">".$featuremap->organism_id->genus ." " . $featuremap->organism_id->species ." (" .$featuremap->organism_id->common_name .")</a>";      	 
-          } else { 
-            print $featuremap->organism_id->genus ." " . $featuremap->organism_id->species ." (" .$featuremap->organism_id->common_name .")";
-          } ?>
-        </td>
-      </tr>      
-      <tr class="tripal_featuremap-table-odd-row tripal-table-odd-row">
-        <th>Type</th>
-        <td><?php 
-            if ($featuremap->type_id->name == 'cdna_featuremap') {
-               print 'cDNA';
-            } else if ($featuremap->type_id->name == 'bac_featuremap') {
-               print 'BAC';
-            } else {
-               print $featuremap->type_id->name;
-            }
-          ?>
-        </td>
-      </tr>
-      <tr class="tripal_featuremap-table-even-row tripal-table-even-row">
-        <th>Description</th>
-        <td><?php
-           // right now we only have one property for libraries. So we can just
-           // refernece it directly.  If we had more than one property
-           // we would need to convert this to an if statment and loop
-           // until we found the right one.
-           print $featuremap->featuremapprop->value?>
-        </td>
-     	</tr>           	                                
-   </table>
-</div>

+ 129 - 33
tripal_featuremap/tripal_featuremap.install

@@ -49,6 +49,7 @@ function tripal_featuremap_install() {
   tripal_featuremap_add_custom_tables();
 
   // Add cvterms
+  tripal_featuremap_add_cvs();
   tripal_featuremap_add_cvterms();
 
 }
@@ -100,47 +101,142 @@ function tripal_featuremap_schema() {
   return $schema;
 }
 
+/**
+ *
+ */
+function tripal_featuremap_add_cvs() {
+  
+  tripal_cv_add_cv(
+    'featuremap_units', 
+    'Contains map unit types for the unittype_id column of the featuremap table.'
+  );
+  
+  tripal_cv_add_cv(
+    'featurepos_property', 
+    'Contains terms map properties.'
+  );
+  
+  tripal_cv_add_cv(
+    'featuremap_property',
+    'Contains positional types for the feature positions'
+  );
+}
 
-
-/*
+/**
  *
  */
 function tripal_featuremap_add_cvterms() {
 
    // add cvterms for the map unit types
-   tripal_cv_add_cvterm(array('name' => 'cM','def' => 'Centimorgan units'),
-     'featuremap_units', 0, 1, 'tripal');
-   tripal_cv_add_cvterm(array('name' => 'bp','def' => 'Base pairs units'),
-     'featuremap_units', 0, 1, 'tripal');
-   tripal_cv_add_cvterm(array('name' => 'bin_unit','def' => 'The bin unit'),
-     'featuremap_units', 0, 1, 'tripal');
-   tripal_cv_add_cvterm(array('name' => 'marker_order','def' => 'Units simply to define marker order.'),
-     'featuremap_units', 0, 1, 'tripal');
-   tripal_cv_add_cvterm(array('name' => 'undefined','def' => 'A catch-all for an undefined unit type'),
-     'featuremap_units', 0, 1, 'tripal');
-
-   tripal_cv_add_cvterm(array('name' => 'start','def' => 'The start coordinate for a map feature.'),
-     'featurepos_property', 0, 1, 'tripal');
-   tripal_cv_add_cvterm(array('name' => 'stop','def' => 'The end coordinate for a map feature'),
-     'featurepos_property', 0, 1, 'tripal');
+   tripal_cv_add_cvterm(
+     array(
+       'name' => 'cM',
+       'def' => 'Centimorgan units'
+     ),
+     'featuremap_units', 0, 1, 'tripal'
+   );
+   tripal_cv_add_cvterm(
+     array(
+       'name' => 'bp',
+       'def' => 'Base pairs units'
+     ),
+     'featuremap_units', 0, 1, 'tripal'
+   );
+   tripal_cv_add_cvterm(
+     array(
+       'name' => 'bin_unit',
+       'def' => 'The bin unit'
+     ),
+     'featuremap_units', 0, 1, 'tripal'
+   );
+   tripal_cv_add_cvterm(
+     array(
+       'name' => 'marker_order',
+       'def' => 'Units simply to define marker order.'
+     ),
+     'featuremap_units', 0, 1, 'tripal'
+   );
+   tripal_cv_add_cvterm(
+     array(
+       'name' => 'undefined',
+       'def' => 'A catch-all for an undefined unit type'
+     ),
+     'featuremap_units', 0, 1, 'tripal'
+   );
+   
+   // featurepos properties
+   tripal_cv_add_cvterm(
+     array(
+       'name' => 'start',
+       'def' => 'The start coordinate for a map feature.'
+     ),
+     'featurepos_property', 0, 1, 'tripal'
+   );
+   tripal_cv_add_cvterm(
+     array(
+       'name' => 'stop',
+       'def' => 'The end coordinate for a map feature'
+     ),
+     'featurepos_property', 0, 1, 'tripal'
+   );
 
    // add cvterms for map properties
-   tripal_cv_add_cvterm(array('name' => 'Map Dbxref','def' => 'A unique identifer for the map in a remote database.  The format is a database abbreviation and a unique accession separated by a colon.  (e.g. Gramene:tsh1996a)'),
-     'featuremap_property', 0, 1, 'tripal');
-   tripal_cv_add_cvterm(array('name' => 'Map Type','def' => 'The type of Map (e.g. QTL, Physical, etc.)'),
-     'featuremap_property', 0, 1, 'tripal');
-   tripal_cv_add_cvterm(array('name' => 'Genome Group','def' => ''),
-     'featuremap_property', 0, 1, 'tripal');
-   tripal_cv_add_cvterm(array('name' => 'URL','def' => 'A univeral resource locator (URL) reference where the publication can be found.  For maps found online, this would be the web address for the map.'),
-     'featuremap_property', 0, 1, 'tripal');
-   tripal_cv_add_cvterm(array('name' => 'Population Type','def' => 'A brief descriptoin of the population type used to generate the map (e.g. RIL, F2, BC1, etc).'),
-     'featuremap_property', 0, 1, 'tripal');
-   tripal_cv_add_cvterm(array('name' => 'Population Size','def' => 'The size of the population used to construct the map.'),
-     'featuremap_property', 0, 1, 'tripal');
-   tripal_cv_add_cvterm(array('name' => 'Methods','def' => 'A brief description of the methods used to construct the map.'),
-     'featuremap_property', 0, 1, 'tripal');
-   tripal_cv_add_cvterm(array('name' => 'Software','def' => 'The software used to construct the map.'),
-     'featuremap_property', 0, 1, 'tripal');
+   tripal_cv_add_cvterm(
+     array(
+       'name' => 'Map Dbxref',
+       'def' => 'A unique identifer for the map in a remote database.  The format is a database abbreviation and a unique accession separated by a colon.  (e.g. Gramene:tsh1996a)'
+     ),
+     'featuremap_property', 0, 1, 'tripal'
+   );
+   tripal_cv_add_cvterm(
+     array(
+       'name' => 'Map Type',
+       'def' => 'The type of Map (e.g. QTL, Physical, etc.)'
+     ),
+     'featuremap_property', 0, 1, 'tripal'
+   );
+   tripal_cv_add_cvterm(
+     array(
+       'name' => 'Genome Group',
+       'def' => ''
+     ),
+     'featuremap_property', 0, 1, 'tripal'
+   );
+   tripal_cv_add_cvterm(
+     array(
+       'name' => 'URL',
+       'def' => 'A univeral resource locator (URL) reference where the publication can be found.  For maps found online, this would be the web address for the map.'
+     ),
+     'featuremap_property', 0, 1, 'tripal'
+   );
+   tripal_cv_add_cvterm(
+     array(
+       'name' => 'Population Type',
+       'def' => 'A brief description of the population type used to generate the map (e.g. RIL, F2, BC1, etc).'
+     ),
+     'featuremap_property', 0, 1, 'tripal'
+   );
+   tripal_cv_add_cvterm(
+     array(
+       'name' => 'Population Size',
+       'def' => 'The size of the population used to construct the map.'
+     ),
+     'featuremap_property', 0, 1, 'tripal'
+   );
+   tripal_cv_add_cvterm(
+     array(
+       'name' => 'Methods',
+       'def' => 'A brief description of the methods used to construct the map.'
+     ),
+     'featuremap_property', 0, 1, 'tripal'
+   );
+   tripal_cv_add_cvterm(
+     array(
+       'name' => 'Software',
+       'def' => 'The software used to construct the map.'
+     ),
+     'featuremap_property', 0, 1, 'tripal'
+   );
 
 }
 

+ 124 - 433
tripal_featuremap/tripal_featuremap.module

@@ -9,8 +9,9 @@
  */
 
 require('api/tripal_featuremap.api.inc');
+require('theme/tripal_featuremap.theme.inc');
 require('includes/tripal_featuremap.admin.inc');
-require('includes/tripal_featuremap.form.inc');
+require('includes/tripal_featuremap.chado_node.inc');
 
 /**
  *
@@ -52,14 +53,26 @@ function tripal_featuremap_help($path, $arg) {
 function tripal_featuremap_node_info() {
   $nodes = array();
   $nodes['chado_featuremap'] = array(
-      'name' => t('Map'),
-      'base' => 'chado_featuremap',
-      'description' => t('A feature map from the chado database (e.g. genetic map)'),
-      'has_title' => FALSE,
-      'title_label' => t('Feature Map'),
-      'has_body' => FALSE,
-      'body_label' => t('Feature Map Description'),
-      'locked' => TRUE
+    'name' => t('Feature Map'),
+    'base' => 'chado_featuremap',
+    'description' => t('A map of features from the chado database (e.g. genetic map)'),
+    'has_title' => FALSE,
+    'title_label' => t('Feature Map'),
+    'has_body' => FALSE,
+    'body_label' => t('Feature Map Description'),
+    'locked' => TRUE,
+    'chado_node_api' => array(
+      'base_table' => 'featuremap',
+      'hook_prefix' => 'chado_featuremap',
+      'record_type_title' => array(
+        'singular' => t('Feature Map'),
+        'plural' => t('Feature Maps')
+      ),
+      'sync_filters' => array(
+        'type_id' => FALSE,
+        'organism_id' => FALSE
+      ),
+    )
   );
   return $nodes;
 }
@@ -95,34 +108,7 @@ function tripal_featuremap_permissions() {
     ),
   );
 }
-/**
- *  Set the permission types that the module uses.
- *
- * @ingroup tripal_featuremap
- */
-function chado_featuremap_access($op, $node, $account) {
-  if ($op == 'create') {
-    if (!user_access('create chado_featuremap content', $account)) {
-      return FALSE;
-    }
-  }
-  if ($op == 'update') {
-    if (!user_access('edit chado_featuremap content', $account)) {
-      return FALSE;
-    }
-  }
-  if ($op == 'delete') {
-    if (!user_access('delete chado_featuremap content', $account)) {
-      return FALSE;
-    }
-  }
-  if ($op == 'view') {
-    if (!user_access('access chado_featuremap content', $account)) {
-      return FALSE;
-    }
-  }
-  return NULL;
-}
+
 /**
  * Menu items are automatically added for the new node types created
  * by this module to the 'Create Content' Navigation menu item.  This function
@@ -135,8 +121,8 @@ function tripal_featuremap_menu() {
 
   // The administative settings menu
   $items['admin/tripal/chado/tripal_featuremap'] = array(
-    'title' => 'Maps',
-    'description' => 'Genetic Maps of Features',
+    'title' => 'Feature Maps',
+    'description' => 'A map of features from the chado database (e.g. genetic map)',
     'page callback' => 'tripal_featuremap_admin_featuremaps_listing',
     'access arguments' => array('administer tripal featuremap'),
     'type' => MENU_NORMAL_ITEM,
@@ -146,7 +132,7 @@ function tripal_featuremap_menu() {
     'title' => 'Help',
     'description' => 'Basic Description of Tripal Map Module Functionality',
     'page callback' => 'theme',
-    'page arguments' => array('tripal_featuremap_help'),
+    'page arguments' => array('tripal_featuremap.help'),
     'access arguments' => array('administer tripal featuremap'),
     'type' => MENU_LOCAL_TASK,
     'weight' => 10
@@ -161,6 +147,16 @@ function tripal_featuremap_menu() {
     'type' => MENU_LOCAL_TASK,
     'weight' => 2
   );
+  
+  $items['admin/tripal/chado/tripal_featuremap/sync'] = array(
+    'title' => ' Sync',
+    'description' => 'Sync featuremaps from Chado with Drupal',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_core_chado_node_sync_form', 'tripal_featuremap', 'chado_featuremap'),
+    'access arguments' => array('administer tripal featuremaps'),
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 0
+  );
 
   // Synchronizing maps from Chado to Drupal
   $items['chado_sync_featuremaps'] = array(
@@ -220,47 +216,87 @@ function tripal_featuremap_views_api() {
  *
  * @ingroup tripal_featuremap
  */
-function tripal_featuremap_theme() {
-  return array(
-    'tripal_featuremap_search_index' => array(
-       'arguments' => array('node'),
+function tripal_featuremap_theme($existing, $type, $theme, $path) {
+  $core_path = drupal_get_path('module', 'tripal_core');
+
+  $items = array(
+    'node__chado_featuremap' => array(
+      'template' => 'node--chado-generic',
+      'render element' => 'node',
+      'base hook' => 'node',
+      'path' => "$core_path/theme",
     ),
-    'tripal_featuremap_search_result' => array(
-       'arguments' => array('node'),
+    'tripal_featuremap.base' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_featuremap.base',
+      'path' => "$path/theme/tripal_featuremap",
     ),
-    'tripal_featuremap_base' => array(
-       'arguments' => array('node' => NULL),
-       'template' => 'tripal_featuremap_base',
+    'tripal_featuremap.properties' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_featuremap.properties',
+      'path' => "$path/theme/tripal_featuremap",
     ),
-    'tripal_featuremap_properties' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_featuremap_properties',
+    'tripal_featuremap.featurepos' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_featuremap.featurepos',
+      'path' => "$path/theme/tripal_featuremap",
     ),
-    'tripal_featuremap_featurepos' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_featuremap_featurepos',
+    'tripal_featuremap.publication' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_featuremap.publication',
+      'path' => "$path/theme/tripal_featuremap",
     ),
-    'tripal_featuremap_publication' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_featuremap_publication',
+    'tripal_featuremap.references' => array(
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_featuremap.references',
+      'path' => "$path/theme/tripal_featuremap",
     ),
-    'tripal_featuremap_references' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_featuremap_references',
+    'tripal_featuremap.help' => array(
+      'template' => 'tripal_featuremap.help',
+      'variables' =>  array(NULL),
+      'path' => "$path/theme",
     ),
-    'tripal_featuremap_help' => array(
-      'template' => 'tripal_featuremap_help',
-      'arguments' =>  array(NULL),
-      'path' => drupal_get_path('module', 'tripal_featuremap') . '/theme'
-    ),
-
-    // Themed Forms
-    'chado_featuremap_node_form' => array(
-     'arguments' => array('form'),
+    'tripal_featuremap.teaser' => array(
+      'template' => 'tripal_featuremap.teaser',
+      'variables' =>  array(NULL),
+      'path' => "$path/theme/tripal_featuremap",
     ),
   );
+  return $items;
+}
+/**
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_featuremap_node_view($node, $view_mode, $langcode) {
+  switch ($node->type) {
+    case 'chado_featuremap':
+      // Show feature browser and counts
+      if ($view_mode == 'full') {
+        $node->content['tripal_featuremap.base'] = array(
+          '#value' => theme('tripal_featuremap.base', array('node' => $node)),
+        );
+        $node->content['tripal_featuremap.featurepos'] = array(
+          '#value' => theme('tripal_featuremap.featurepos', array('node' => $node)),
+        );
+        $node->content['tripal_featuremap.properties'] = array(
+          '#value' => theme('tripal_featuremap.properties', array('node' => $node)),
+        );
+        $node->content['tripal_featuremap.publication'] = array(
+          '#value' => theme('tripal_featuremap.publication', array('node' => $node)),
+        );
+        $node->content['tripal_featuremap.references'] = array(
+          '#value' => theme('tripal_featuremap.references', array('node' => $node)),
+        );
+      }
+      if ($view_mode == 'teaser') {
+        $node->content['tripal_featuremap.teaser'] = array(
+          '#value' => theme('tripal_featuremap.teaser', array('node' => $node)),
+        );
+      }
+      break;
+  }
 }
-
 /**
  * @ingroup tripal_library
  */
@@ -296,38 +332,29 @@ function tripal_featuremap_block_view($delta = '') {
     switch ($delta) {
       case 'mapbase':
         $block['subject'] = t('Library Details');
-        $block['content'] = theme('tripal_featuremap_base', $node);
+        $block['content'] = theme('tripal_featuremap.base', $node);
         break;
       case 'mapprops':
         $block['subject'] = t('Properties');
-        $block['content'] = theme('tripal_featuremap_properties', $node);
+        $block['content'] = theme('tripal_featuremap.properties', $node);
         break;
       case 'mappos':
         $block['subject'] = t('Features');
-        $block['content'] = theme('tripal_featuremap_featurepos', $node);
+        $block['content'] = theme('tripal_featuremap.featurepos', $node);
         break;
       case 'mappubs':
         $block['subject'] = t('Publications');
-        $block['content'] = theme('tripal_featuremap_publication', $node);
+        $block['content'] = theme('tripal_featuremap.publication', $node);
         break;
       case 'maprefs':
         $block['subject'] = t('References');
-        $block['content'] = theme('tripal_featuremap_references', $node);
+        $block['content'] = theme('tripal_featuremap.references', $node);
         break;
       default :
     }
     return $block;
   }
 }
-/**
- * This function is an extension of the chado_feature_view and
- * chado_organism_view by providing the markup for the map object
- * THAT WILL BE INDEXED.
- *
- * @ingroup tripal_featuremap
- */
-function theme_tripal_featuremap_search_index($node) {
-}
 
 /**
  *
@@ -336,356 +363,8 @@ function theme_tripal_featuremap_search_index($node) {
 function tripal_featuremap_cron() {
 
 }
-/**
- * Implement hook_access().
- *
- * This hook allows node modules to limit access to the node types they define.
- *
- *  @param $node
- *  The node on which the operation is to be performed, or, if it does not yet exist, the
- *  type of node to be created
- *
- *  @param $op
- *  The operation to be performed
- *
- *  @param $account
- *  A user object representing the user for whom the operation is to be performed
- *
- *  @return
- *  If the permission for the specified operation is not set then return FALSE. If the
- *  permission is set then return NULL as this allows other modules to disable
- *  access.  The only exception is when the $op == 'create'.  We will always
- *  return TRUE if the permission is set.
- *
- * @ingroup tripal_featuremap
- */
-function chado_featuremap_node_access($node, $op, $account) {
-  if ($op == 'create') {
-    if (!user_access('create chado_featuremap content', $account)) {
-      return FALSE;
-    }
-    return TRUE;
-  }
-
-  if ($op == 'update') {
-    if (!user_access('edit any chado_featuremap content', $account) &&
-        !user_access('edit own chado_featuremap content', $account)) {
-        return FALSE;
-    }
-    if (user_access('edit own chado_featuremap content', $account) &&
-      $account->uid != $node->uid) {
-      return FALSE;
-    }
-  }
-
-  if ($op == 'delete') {
-    if (!user_access('delete any chado_featuremap content', $account) &&
-      !user_access('delete own chado_featuremap content', $account)) {
-      return FALSE;
-    }
-    if (user_access('delete own chado_featuremap content', $account) &&
-      $account->uid != $node->uid) {
-      return FALSE;
-    }
-  }
-  return NULL;
-}
-
 
 
-/**
- *  When a new chado_featuremap node is created we also need to add information
- *  to our chado_featuremap table.  This function is called on insert of a new node
- *  of type 'chado_featuremap' and inserts the necessary information.
- *
- * @ingroup tripal_featuremap
- */
-function chado_featuremap_insert($node) {
-
-  // if the featuremap_id already exists then we got to the insert via
-  // a syncing operation.  We do not need to add the feature map
-  if ($node->featuremap_id) {
-    $featuremap['featuremap_id'] = $node->featuremap_id;
-  }
-  else {
-    $values = array(
-      'name' => $node->title,
-      'description' => $node->description,
-      'unittype_id' => $node->unittype_id
-    );
-    $featuremap = tripal_core_chado_insert('featuremap', $values);
-    if(!$featuremap) {
-      drupal_set_message(t('Unable to add featuremap.', 'warning'));
-      watchdog('tripal_featuremap', 'Unable to create feature map where values: %values',
-        array('%values' => print_r($values, TRUE)), WATCHDOG_WARNING);
-      return;
-    }
-
-    // now add the properties
-    $properties = array(); // stores all of the properties we need to add
-    $cross_refs = array(); // stores any cross references for this featuremap
-
-    // get the list of properties for easy lookup (without doing lots of database queries
-    $properties_list = array();
-    $sql = "
-      SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
-      FROM  {cvterm} CVT
-        INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
-      WHERE
-        CV.name = 'featuremap_property' AND
-        NOT CVT.is_obsolete = 1
-      ORDER BY CVT.name ASC
-    ";
-    $prop_types = chado_query($sql);
-    while ($prop = $prop_types->fetchObject()) {
-      $properties_list[$prop->cvterm_id] = $prop->name;
-    }
-
-    // get the properties that should be added. Properties are in one of two forms:
-    //  1) prop_value-[type id]-[index]
-    //  2) new_value-[type id]-[index]
-    //  3) new_id, new_value
-    foreach ($node as $name => $value) {
-      if (preg_match('/^new_value-(\d+)-(\d+)/', $name, $matches)) {
-        $type_id = $matches[1];
-        $index = $matches[2];
-        $name = $properties_list[$type_id];
-        $properties[$name][$index] = trim($value);
-      }
-    }
-    if ($node->new_id and $node->new_value) {
-      $type_id = $node->new_id;
-      $index = count($properties[$name]);
-      $name = $properties_list[$type_id];
-      $properties[$name][$index] = trim($node->new_value);
-    }
-
-    // iterate through all of the properties to see if the Map dbxref is set,
-    // if so, add it to the $cross_refs array
-    foreach ($properties as $name => $element) {
-      foreach ($element as $index => $value) {
-        if ($name == "Map Dbxref") {
-          // we will add the cross-references to the featuremap_dbxref table
-          // but we also want to keep the property in the featuremapprop table so don't unset it
-          $cross_refs[] = $value;
-        }
-      }
-    }
-
-    // now add in the properties
-    foreach ($properties as $property => $elements) {
-      foreach ($elements as $rank => $value) {
-
-        $status = tripal_featuremap_insert_property($featuremap['featuremap_id'], $property, $value, FALSE);
-        if (!$status) {
-          drupal_set_message("Error cannot add property: $property", "error");
-          watchdog('t_featuremap', "Error cannot add property: %prop",
-          array('%property' => $property), WATCHDOG_ERROR);
-        }
-      }
-    }
-
-    // add in any database cross-references
-    foreach ($cross_refs as $index => $ref) {
-      $featuremap_dbxref = tripal_featuremap_add_featuremap_dbxref($featuremap['featuremap_id'], trim($ref));
-      if (!$featuremap_dbxref) {
-        drupal_set_message("Error cannot add map cross reference: $ref", "error");
-        watchdog('t_featuremap', "Error cannot add map cross reference: %ref",
-        array('%ref' => $ref), WATCHDOG_ERROR);
-      }
-    }
-  }
-
-  // add the record to the chado_featuremap table in Drupal
-  if ($featuremap) {
-    // make sure the entry for this feature doesn't already exist in the chado_featuremap table
-    // if it doesn't exist then we want to add it.
-    $featuremap_id = chado_get_id_for_node('featuremap', $node->nid) ;
-    if (!$featuremap_id) {
-       // next add the item to the drupal table
-      $sql = "
-        INSERT INTO {chado_featuremap} (nid, vid, featuremap_id)
-        VALUES (:nid, :vid, :featuremap_id)
-      ";
-      db_query($sql, array(':nid' => $node->nid, ':vid' => $node->vid, ':featuremap_id' => $featuremap['featuremap_id']));
-    }
-  }
-}
-/**
- * Update nodes
- *
- * @ingroup tripal_featuremap
- */
-function chado_featuremap_update($node) {
-  if ($node->revision) {
-    // there is no way to handle revisions in Chado but leave
-    // this here just to make not we've addressed it.
-  }
-  $featuremap_id = chado_get_id_for_node('featuremap', $node->nid) ;
-
-  // update the map record
-  $match = array(
-    'featuremap_id' => $featuremap_id,
-  );
-  $values = array(
-    'name' => $node->title,
-    'description' => $node->description,
-    'unittype_id' => $node->unittype_id
-  );
-  $status = tripal_core_chado_update('featuremap', $match, $values);
-  if (!$status) {
-    drupal_set_message("Error updating map", "error");
-    watchdog('t_featuremap', "Error updating map", array(), WATCHDOG_ERROR);
-    return;
-  }
-
-  // now update the properties
-  $properties = array(); // stores all of the properties we need to add
-  $cross_refs = array(); // stores any cross references for this map
-
-  // get the list of properties for easy lookup (without doing lots of database queries
-  $properties_list = array();
-  $sql = "
-    SELECT DISTINCT CVT.cvterm_id, CVT.name, CVT.definition
-    FROM  {cvterm} CVT
-      INNER JOIN {cv} ON CVT.cv_id = CV.cv_id
-    WHERE
-      CV.name = 'featuremap_property' AND
-      NOT CVT.is_obsolete = 1
-    ORDER BY CVT.name ASC
-  ";
-  $prop_types = chado_query($sql);
-  while ($prop = $prop_types->fetchObject()) {
-    $properties_list[$prop->cvterm_id] = $prop->name;
-  }
-
-  // get the properties that should be added. Properties are in one of three forms:
-  //  1) prop_value-[type id]-[index]
-  //  2) new_value-[type id]-[index]
-  //  3) new_id, new_value
-  //  dpm($node);
-  foreach ($node as $key => $value) {
-    if (preg_match('/^prop_value-(\d+)-(\d+)/', $key, $matches)) {
-      $type_id = $matches[1];
-      $index = $matches[2];
-      $name = $properties_list[$type_id];
-      $properties[$name][$index] = trim($value);
-    }
-    if (preg_match('/^new_value-(\d+)-(\d+)/', $key, $matches)) {
-      $type_id = $matches[1];
-      $index = $matches[2];
-      $name = $properties_list[$type_id];
-      $properties[$name][$index] = trim($value);
-    }
-  }
-  if ($node->new_id and $node->new_value) {
-    $type_id = $node->new_id;
-    $name = $properties_list[$type_id];
-    $index = count($properties[$name]);
-    $properties[$name][$index] = trim($node->new_value);
-  }
-
-  // iterate through all of the properties to see if the Map dbxref is set,
-  // if so, add it to the $cross_refs array
-  foreach ($properties as $name => $element) {
-    foreach ($element as $index => $value) {
-      if ($name == "Map Dbxref") {
-        // we will add the cross-references to the featuremap_dbxref table
-        // but we also want to keep the property in the featuremapprop table so don't unset it
-        $cross_refs[] = $value;
-      }
-    }
-  }
-
-  // now add in the properties by first removing any the featuremap
-  // already has and adding the ones we have
-  tripal_core_chado_delete('featuremapprop', array('featuremap_id' => $featuremap_id));
-  foreach ($properties as $property => $elements) {
-    foreach ($elements as $rank => $value) {
-      $status = tripal_featuremap_insert_property($featuremap_id, $property, $value, FALSE);
-      if (!$status) {
-        drupal_set_message("Error cannot add property: '$property'", "error");
-        watchdog('t_featuremap', "Error cannot add property: '%prop'",
-        array('%prop' => $property), WATCHDOG_ERROR);
-      }
-    }
-  }
-
-  // add in any database cross-references after first removing
-  tripal_core_chado_delete('featuremap_dbxref', array('featuremap_id' => $featuremap_id));
-  foreach ($cross_refs as $index => $ref) {
-    $featuremap_dbxref = tripal_featuremap_add_featuremap_dbxref($featuremap_id, trim($ref));
-    if (!$featuremap_dbxref) {
-      drupal_set_message("Error cannot add map cross reference: $ref", "error");
-      watchdog('t_featuremap', "Error cannot add map cross reference: %ref",
-      array('%ref' => $ref), WATCHDOG_ERROR);
-    }
-  }
-}
-/**
- *  When a node is requested by the user this function is called to allow us
- *  to add auxiliary data to the node object.
- *
- * @ingroup tripal_featuremap
- */
-function chado_featuremap_load($node) {
-  // get the feature details from chado
-  $featuremap_id = chado_get_id_for_node('featuremap', $node->nid);
-
-  $values = array('featuremap_id' => $featuremap_id);
-  $featuremap = tripal_core_generate_chado_var('featuremap', $values);
-
-  // expand the description field as it is needed by the form
-  $featuremap = tripal_core_expand_chado_vars($featuremap, 'field', 'featuremap.description');
-
-  $additions = new stdClass();
-  $additions->featuremap = $featuremap;
-  return $additions;
-
-}
-/**
- *  This function customizes the view of the chado_featuremap node.  It allows
- *  us to generate the markup. This function is required for node [Preview]
- *
- * @ingroup tripal_featuremap
- */
-function chado_featuremap_view($node, $teaser = FALSE, $page = FALSE) {
-   // use drupal's default node view:
-  if (!$teaser) {
-
-    $node = node_prepare($node, $teaser);
-  }
-  return $node;
-}
-
-/**
- * Delete data from drupal and chado databases when a node is deleted
- * @ingroup tripal_featuremap
- */
-function chado_featuremap_delete(&$node) {
-
-  $featuremap_id = chado_get_id_for_node('featuremap', $node->nid);
-
-  // if we don't have a map id for this node then this isn't a node of
-  // type chado_featuremap or the entry in the chado_featuremap table was lost.
-  if (!$featuremap_id) {
-    return;
-  }
-
-  // Remove data from {chado_featuremap}, {node} and {node_revisions} tables of
-  // drupal database
-  $sql_del = "DELETE FROM {chado_featuremap} WHERE nid = :nid AND vid = :vid";
-  db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
-  $sql_del = "DELETE FROM {node} WHERE nid = :nid AND vid = :vid";
-  db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
-  $sql_del = "DELETE FROM {node_revisions} WHERE nid = :nid AND vid = :vid";
-  db_query($sql_del, array(':nid' => $node->nid, ':vid' => $node->vid));
-
-  // Remove data from map and mapprop tables of chado database as well
-  chado_query("DELETE FROM {featuremap} WHERE featuremap_id = :featuremap_id", array(':featuremap_id' => $featuremap_id));
-  chado_query("DELETE FROM {featuremapprop} WHERE featuremap_id = :featuremap_id", array(':featuremap_id' => $featuremap_id));
-}
-
 /**
  * Implementation of hook_form_alter()
  *
@@ -698,4 +377,16 @@ function tripal_featuremap_form_alter(&$form, &$form_state, $form_id) {
   if ($form_id == "chado_featuremap_node_form") {
     $form['actions']['preview']['#access'] = FALSE;
   }
+}
+
+/**
+ *
+ * @param $node
+ */
+function tripal_featuremap_node_presave($node) {
+  // if this is a chado_featuremap and the $node->featuremap object is set then we
+  // are syncing and we want to set the node title to be the same as the node name
+  if ($node->type == 'chado_featuremap' and property_exists($node, 'featuremap')) {
+    $node->title = $node->featuremap->name;
+  }
 }

+ 44 - 8
tripal_library/includes/tripal_library.chado_node.inc

@@ -152,7 +152,7 @@ function chado_library_validate($node, $form, &$form_state) {
   $lib = 0;
   // check to make sure the unique name on the library is unique
   // before we try to insert into chado.
-  if ($node->library_id) {
+  if (property_exists($node, 'library_id')) {
     $sql = "
       SELECT *
       FROM {library}
@@ -302,13 +302,49 @@ function chado_library_delete(&$node) {
 }
 
 /**
- * 
- * @param unknown $node
+ * Implement hook_access().
+ *
+ * This hook allows node modules to limit access to the node types they define.
+ *
+ *  @param $node
+ *  The node on which the operation is to be performed, or, if it does not yet exist, the
+ *  type of node to be created
+ *
+ *  @param $op
+ *  The operation to be performed
+ *
+ *  @param $account
+ *  A user object representing the user for whom the operation is to be performed
+ *
+ *  @return
+ *  If the permission for the specified operation is not set then return FALSE. If the
+ *  permission is set then return NULL as this allows other modules to disable
+ *  access.  The only exception is when the $op == 'create'.  We will always
+ *  return TRUE if the permission is set.
+ *
+ * @ingroup tripal_library
  */
-function tripal_library_node_presave($node) {
-  // if this is a chado_library and the $node->library object is set then we 
-  // are syncing and we want to set the node title to be the same as the node name
-  if ($node->type == 'chado_library' and property_exists($node, 'library')) {
-    $node->title = $node->library->name;
+function chado_library_node_access($node, $op, $account) {
+  if ($op == 'create') {
+    if (!user_access('create chado_library content', $account)) {
+      return FALSE;
+    }
+    return TRUE;
+  }
+  if ($op == 'update') {
+    if (!user_access('edit chado_library content', $account)) {
+      return FALSE;
+    }
+  }
+  if ($op == 'delete') {
+    if (!user_access('delete chado_library content', $account)) {
+      return FALSE;
+    }
+  }
+  if ($op == 'view') {
+    if (!user_access('access chado_library content', $account)) {
+      return FALSE;
+    }
   }
+  return NULL;
 }

+ 20 - 54
tripal_library/tripal_library.module

@@ -77,53 +77,7 @@ function tripal_library_permisssions() {
     ),
   );
 }
-/**
- * Implement hook_access().
- *
- * This hook allows node modules to limit access to the node types they define.
- *
- *  @param $node
- *  The node on which the operation is to be performed, or, if it does not yet exist, the
- *  type of node to be created
- *
- *  @param $op
- *  The operation to be performed
- *
- *  @param $account
- *  A user object representing the user for whom the operation is to be performed
- *
- *  @return
- *  If the permission for the specified operation is not set then return FALSE. If the
- *  permission is set then return NULL as this allows other modules to disable
- *  access.  The only exception is when the $op == 'create'.  We will always
- *  return TRUE if the permission is set.
- *
- * @ingroup tripal_library
- */
-function chado_library_node_access($node, $op, $account) {
-  if ($op == 'create') {
-    if (!user_access('create chado_library content', $account)) {
-      return FALSE;
-    }
-    return TRUE;
-  }
-  if ($op == 'update') {
-    if (!user_access('edit chado_library content', $account)) {
-      return FALSE;
-    }
-  }
-  if ($op == 'delete') {
-    if (!user_access('delete chado_library content', $account)) {
-      return FALSE;
-    }
-  }
-  if ($op == 'view') {
-    if (!user_access('access chado_library content', $account)) {
-      return FALSE;
-    }
-  }
-  return NULL;
-}
+
 /**
  * Menu items are automatically added for the new node types created
  * by this module to the 'Create Content' Navigation menu item.  This function
@@ -377,31 +331,31 @@ function tripal_library_block_view($delta = '') {
     switch ($delta) {
       case 'libreferences':
         $block['subject'] = t('Cross References');
-        $block['content'] = theme('tripal_library_references', $node);
+        $block['content'] = theme('tripal_library.references', $node);
         break;
       case 'libbase':
         $block['subject'] = t('Library Details');
-        $block['content'] = theme('tripal_library_base', $node);
+        $block['content'] = theme('tripal_library.base', $node);
         break;
       case 'libsynonyms':
         $block['subject'] = t('Synonyms');
-        $block['content'] = theme('tripal_library_synonyms', $node);
+        $block['content'] = theme('tripal_library.synonyms', $node);
         break;
       case 'libproperties':
         $block['subject'] = t('Properties');
-        $block['content'] = theme('tripal_library_properties', $node);
+        $block['content'] = theme('tripal_library.properties', $node);
         break;
       case 'libterms':
         $block['subject'] = t('Library Terms');
-        $block['content'] = theme('tripal_library_terms', $node);
+        $block['content'] = theme('tripal_library.terms', $node);
         break;
       case 'featurelibs':
         $block['subject'] = t('Libraries');
-        $block['content'] = theme('tripal_feature_libraries', $node);
+        $block['content'] = theme('tripal_feature.libraries', $node);
         break;
       case 'orglibs':
         $block['subject'] = t('Libraries');
-        $block['content'] = theme('tripal_organism_libraries', $node);
+        $block['content'] = theme('tripal_organism.libraries', $node);
         break;
       default :
     }
@@ -430,4 +384,16 @@ function tripal_library_form_alter(&$form, &$form_state, $form_id) {
   if ($form_id == "chado_library_node_form") {
     $form['actions']['preview']['#access'] = FALSE;
   }
+}
+
+/**
+ *
+ * @param $node
+ */
+function tripal_library_node_presave($node) {
+  // if this is a chado_library and the $node->library object is set then we
+  // are syncing and we want to set the node title to be the same as the node name
+  if ($node->type == 'chado_library' and property_exists($node, 'library')) {
+    $node->title = $node->library->name;
+  }
 }

+ 2 - 2
tripal_pub/api/tripal_pub.api.inc

@@ -439,8 +439,8 @@ function tripal_pub_add_publications($pubs, $do_contact, $update = FALSE) {
   print "\n";
   return $report;
 }
-/*
- *
+/**
+ * Adds a dbxref record to a publication
  */
 function tripal_pub_add_pub_dbxref($pub_id, $pub_dbxref) {