Browse Source

Stocks: cleaned up module including documentation and removing no longer used code

Lacey Sanderson 11 years ago
parent
commit
f7024f708a

+ 3 - 4
tripal_stock/api/tripal_stock.api.inc

@@ -53,7 +53,7 @@ function tripal_stock_get_stock_by_stock_id($stock_id) {
 }
 
 /**
- * Purpose: Returns all stocks currently sync'd with drupal
+ * Returns all stocks currently sync'd with drupal
  *
  * @return
  *   An array of node objects keyed by stock_id
@@ -129,7 +129,7 @@ function tripal_stock_get_stocks($values) {
 }
 
 /**
- * Purpose: Retrieve stocks based on associated stock properties
+ * Retrieve stocks based on associated stock properties
  *
  * @param $stockprop_values
  *   An array of column_name => value where column_name is any column in the stockprop table
@@ -194,7 +194,7 @@ function tripal_stock_get_stocks_by_stockprop($stockprop_values, $stock_values)
 }
 
 /**
- * Purpose: Return all stocks with a given name identifier
+ * Return all stocks with a given name identifier
  *  which might match stock.name, stock.uniquename, dbxref.accession,
  *  stockprop.value where stockprop.type='synonym'
  *
@@ -320,4 +320,3 @@ function tripal_stock_get_stock_by_name_identifier($name, $organism_id) {
 
   return $stocks;
 }
-

+ 0 - 64
tripal_stock/includes/other_module_api_functions.inc

@@ -1,64 +0,0 @@
-<?php
-/**
- * @file
- * @todo Add file header description
- */
-
-/*************************************************************************
- * Purpose: Get max rank for a given set of criteria
- *   This function was developed with the many property tables in chado in mind
- *
- * @params tablename: the name of the chado table you want to select the max rank from
- *    this table must contain a rank column of type integer
- * @params where_options: array(
- *                          <column_name> => array(
- *                            'type' => <type of column: INT/STRING>,
- *                            'value' => <the value you want to filter on>,
- *                            'exact' => <if TRUE use =; if FALSE use ~>,
- *                          )
- *        )
- *     where options should include the id and type for that table to correctly
- *     group a set of records together where the only difference are the value and rank
- * @return the maximum rank
- *
- */
-function get_max_chado_rank($tablename, $where_options) {
-
-  $where = array();
-  //generate the where clause from supplied options
-  // the key is the column name
-  $args = array();
-  $i = 0;
-  $sql = "
-    SELECT max(rank) as max_rank, count(rank) as count 
-    FROM {:table} 
-    WHERE 1=1
-  ";
-  $args[":table"] = $tablename;
-  foreach ($where_options as $key => $val_array) {
-    if (preg_match('/INT/', $val_array['type'])) {
-      $sql .= " AND $key = :$key$i ";
-      $args[":$key$i"] = $val_array['value'];
-    }
-    else {
-      if ($val_array['exact']) {
-        $operator = '='; 
-      }
-      else { 
-        $operator = '~'; 
-      }
-      $sql .= " AND $key $operator :$key$i ";
-      $args[":$key$i"] = $val_array['value'];
-    }
-    $i++;
-  }
-   
-  $result = chado_query($sql, $tablename, $args)->fetchObject();
-  //drupal_set_message("Max Rank Query=SELECT max(rank) as max_rank, count(rank) as count FROM ".$tablename." WHERE ".implode(' AND ',$where));
-  if ($result->count > 0) {
-    return $result->max_rank;
-  }
-  else {
-    return -1;
-  }
-}

+ 12 - 6
tripal_stock/includes/tripal_stock.admin.inc

@@ -1,11 +1,13 @@
 <?php
 /**
  * @file
- * @todo Add file header description
+ * Administration of stocks
  */
 
 /**
+ * Admin launchpad
  *
+ * @ingroup tripal_stock
  */
 function tripal_stock_admin_stock_view() {
   $output = '';
@@ -37,9 +39,8 @@ function tripal_stock_admin_stock_view() {
   return $output;
 }
 
-
 /**
- * Purpose: Provide administration options for chado_stocks
+ * Provide administration options for chado_stocks
  *
  * @return
  *   Form array (as described by the drupal form api)
@@ -96,8 +97,9 @@ function tripal_stock_admin_validate($form, &$form_state) {
 }
 
 /**
+ * Form: Set the title type to be used for all stocks
  *
- * @param $form
+ * @ingroup tripal_stock
  */
 function get_tripal_stock_admin_form_title_set(&$form) {
 
@@ -132,9 +134,11 @@ function get_tripal_stock_admin_form_title_set(&$form) {
     '#default_value' => variable_get('chado_stock_title', 'unique_constraint'),
   );
 }
+
 /**
+ * Form: Set UR for stocks
  *
- * @param  $form
+ * @ingroup tripal_stock
  */
 function get_tripal_stock_admin_form_url_set(&$form) {
 
@@ -197,9 +201,11 @@ function get_tripal_stock_admin_form_url_set(&$form) {
     '#value' => t('Set Stock URLs'),
   );
 }
+
 /**
+ * Set Controlled vocabularies used in stock tables
  *
- * @param $form
+ * @ingroup tripal_stock
  */
 function get_tripal_stock_admin_form_vocabulary_set(&$form) {
 

+ 25 - 11
tripal_stock/includes/tripal_stock.chado_node.inc

@@ -1,11 +1,11 @@
 <?php
-
 /**
  * @file Stock Node Functionality
  */
 
 /**
- * Implements hook_node_info(): registers a stock node type
+ * Implements hook_node_info().
+ * Registers a stock node type
  *
  * @return
  *   An array describing various details of the node
@@ -37,7 +37,8 @@ function tripal_stock_node_info() {
 }
 
 /**
- * Implements hook_load(): Prepares the chado_stock node
+ * Implements hook_load().
+ * Prepares the chado_stock node
  *
  * @param $node
  *   The basic node containing all variables common to all nodes
@@ -100,9 +101,9 @@ function chado_stock_load($nodes) {
   return $new_nodes;
 }
 
-
 /**
- * Implements hook_form(): Creates the main Add/Edit/Delete Form for chado stocks
+ * Implements hook_form().
+ * Creates the main Add/Edit/Delete Form for chado stocks
  *
  * Parts to be added by this form
  *     name,
@@ -332,7 +333,8 @@ function chado_stock_form($node, $form_state) {
 }
 
 /**
- * Implements hook_validate(): Validate the input from the chado_stock node form
+ * Implements hook_validate().
+ * Validate the input from the chado_stock node form
  *
  * @param $node
  *   The current node including fields with the form element names and submitted values
@@ -448,9 +450,9 @@ function chado_stock_validate(&$node, $form, &$form_state) {
   }
 }
 
-
 /**
- * Implements hook_insert(): Inserts data from chado_stock_form() into drupal and chado
+ * Implements hook_insert().
+ * Inserts data from chado_stock_form() into drupal and chado
  *
  * @param $node
  *   The current node including fields with the form element names and submitted values
@@ -584,7 +586,8 @@ function chado_stock_insert($node) {
 }
 
 /**
- * Implements hook_update(): Handles Editing/Updating of main stock info
+ * Implements hook_update().
+ * Handles Editing/Updating of main stock info
  *
  * NOTE: Currently just writes over all old data
  *
@@ -729,7 +732,8 @@ function chado_stock_update($node) {
 }
 
 /**
- * Implements hook_delete(): Handles deleting of chado_stocks
+ * Implements hook_delete().
+ * Handles deleting of chado_stocks
  *
  * NOTE: Currently deletes data -no undo or record-keeping functionality
  *
@@ -752,6 +756,8 @@ function chado_stock_delete($node) {
 
 /**
  * Used by Tripal Chado Node API during sync'ing of nodes
+ *
+ * @ingroup tripal_stock
  */
 function chado_stock_chado_node_sync_create_new_node($new_node, $record) {
 
@@ -764,6 +770,8 @@ function chado_stock_chado_node_sync_create_new_node($new_node, $record) {
 }
 
 /**
+ * Implements hook_node_presave(). Acts on all content types.
+ *
  * @ingroup tripal_stock
  */
 function tripal_stock_node_presave($node) {
@@ -802,6 +810,8 @@ function tripal_stock_node_presave($node) {
 }
 
 /**
+ * Implements hook_node_insert(). Acts on all content types.
+ *
  * @ingroup tripal_stock
  */
 function tripal_stock_node_insert($node) {
@@ -825,6 +835,8 @@ function tripal_stock_node_insert($node) {
 }
 
 /**
+ * Implements hook_node_update(). Acts on all content types.
+ *
  * @ingroup tripal_stock
  */
 function tripal_stock_node_update($node) {
@@ -844,6 +856,8 @@ function tripal_stock_node_update($node) {
 }
 
 /**
+ * Implements hook_node_view(). Acts on all content types.
+ *
  * @ingroup tripal_stock
  */
 function tripal_stock_node_view($node, $view_mode, $langcode) {
@@ -904,4 +918,4 @@ function tripal_stock_node_view($node, $view_mode, $langcode) {
       }
       break;
   }
-}
+}

+ 0 - 292
tripal_stock/includes/tripal_stock.sync_stocks.inc

@@ -1,292 +0,0 @@
-<?php
-
-/**
- * @file
- * @todo Add file header description
- */
-
-
-# This script can be run as a stand-alone script to sync all the stocks from chado to drupal
-// Parameter f specifies the stock_id to sync
-// -f 0 will sync all stocks
-
-$arguments = getopt("f:t:");
-
-if (isset($arguments['f']) and isset($arguments['t']) and $arguments['t'] == 'chado_stock') {
-  $drupal_base_url = parse_url('http://www.example.com');
-  $_SERVER['HTTP_HOST'] = $drupal_base_url['host'];
-  $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'];
-  $_SERVER['REMOTE_ADDR'] = NULL;
-  $_SERVER['REQUEST_METHOD'] = NULL;
-
-  require_once 'includes/bootstrap.inc';
-  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
-
-  $stock_id = $arguments['f'];
-
-  if ($stock_id > 0 ) {
-    tripal_stock_sync_stock($stock_id);
-  }
-  else{
-    print "syncing all stocks...\n";
-    tripal_stock_sync_stocks();
-  }
-}
-/**
- *
- */
-function tripal_stock_sync_form() {
-
-  $form['description'] = array(
-  '#type' => 'item',
-  '#value' => t("Stocks of the types listed ".
-     "below in the Stock Types box will be synced (leave blank to sync all types). You may limit the ".
-     "stocks to be synced by a specific organism. Depending on the ".
-     "number of stocks in the chado database this may take a long ".
-     "time to complete. "),
-  );
-
-  $form['stock_types'] = array(
-    '#title'       => t('Stock Types'),
-    '#type'        => 'textarea',
-    '#description' => t("Enter the names of the stock types to sync. " .
-       "Leave blank to sync all stocks. Pages for these stock ".
-       "types will be created automatically for stocks that exist in the ".
-       "chado database.  The names listed here should be spearated by ".
-       "spaces or entered separately on new lines. The names must match ".
-       "exactly (spelling and case) with terms in the sequence ontology"),
-    '#default_value' => variable_get('chado_sync_stock_types', ''),
-  );
-
-  // get the list of organisms
-  $sql = "SELECT * FROM {organism} ORDER BY genus, species";
-  $orgs = tripal_organism_get_synced();
-  $organisms[] = '';
-  foreach ($orgs as $organism) {
-    $organisms[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
-  }
-  $form['organism_id'] = array(
-    '#title'       => t('Organism'),
-    '#type'        => t('select'),
-    '#description' => t("Choose the organism for which stocks types set above will be synced. Only organisms which also have been synced will appear in this list."),
-    '#options'     => $organisms,
-  );
-
-
-  $form['button'] = array(
-    '#type' => 'submit',
-    '#value' => t('Sync all Stocks'),
-    '#weight' => 3,
-  );
-
-  return $form;
-}
-/**
- *
- */
-function tripal_stock_sync_form_validate($form, &$form_state) {
-  $organism_id   = $form_state['values']['organism_id'];
-  $stock_types = $form_state['values']['stock_types'];
-
-  // nothing to do
-}
-/**
- *
- */
-function tripal_stock_sync_form_submit($form, &$form_state) {
-
-  global $user;
-
-  $organism_id   = $form_state['values']['organism_id'];
-  $stock_types = $form_state['values']['stock_types'];
-
-  $job_args = array(0, $organism_id, $stock_types);
-
-  if ($organism_id) {
-    $organism = chado_select_record('organism', array('genus', 'species'), array('organism_id' => $organism_id));
-    $title = "Sync stocks for " .  $organism[0]->genus . " " . $organism[0]->species;
-  }
-  else {
-    $title = 'Sync stocks';
-  }
-
-  variable_set('chado_sync_stock_types', $stock_types);
-
-  tripal_add_job($title, 'tripal_stock', 'tripal_stock_sync_stocks', $job_args, $user->uid);
-}
-/**
- *
- * @param $na
- *   Tripal expects all jobs to have at least one argument. For this function
- *   we don't need any, so we have this dummy argument as a filler
- * @param $job_id
- */
-function tripal_stock_set_urls($na = NULL, $job = NULL) {
-
-  // begin the transaction
-  db_query("BEGIN");
-
-  print "\nNOTE: Setting of URLs is performed using a database transaction. \n" .
-        "If the load fails or is terminated prematurely then the entire set of \n" .
-        "new URLs will be rolled back and no changes will be made\n\n";
-
-  // get the number of records we need to set URLs for
-  $csql = "SELECT count(*) FROM {chado_stock}";
-  $num_nodes = db_query($csql)->fetchField();
-
-  // calculate the interval at which we will print an update on the screen
-  $num_set = 0;
-  $num_per_interval = 100;
-
-  // prepate the statements which will quickly add url alias. Because these
-  // are not Chado tables we must manually prepare them
-  $psql = "
-    PREPARE del_url_alias_by_src (text) AS
-    DELETE FROM {url_alias} WHERE src = \$1
-  ";
-  db_query($psql);
-  $psql = "
-    PREPARE ins_url_alias_nisrds (text, text) AS
-    INSERT INTO url_alias (src, dst) VALUES (\$1, \$2)
-  ";
-  db_query($psql);
-
-  // get the URL alias syntax string
-  $url_alias = variable_get('chado_stock_url_string', '/stock/[genus]/[species]/[type]/[uniquename]');
-  if (!$url_alias) {
-    $url_alias = '/stock/[genus]/[species]/[type]/[uniquename]';
-  }
-  $url_alias = preg_replace('/^\//', '', $url_alias); // remove any preceeding forward slash
-
-
-  // get the list of stocks that have been synced
-  $sql = "SELECT * FROM {chado_stock}";
-  $nodes = db_query($sql);
-  while ($node = $nodes->fetchObject()) {
-
-    // get the URL alias
-    $src = "node/$node->nid";
-    $dst = tripal_stock_get_stock_url($node, $url_alias);
-    if (!$dst) {
-      db_query('DEALLOCATE "del_url_alias_by_src"');
-      db_query('DEALLOCATE "ins_url_alias_nisrds"');
-      db_query("ROLLBACK");
-      return;
-    }
-
-    // if the src and dst is the same (the URL alias couldn't be set)
-    // then skip to the next one. There's nothing we can do about this one.
-    if($src == $dst) {
-      continue;
-    }
-
-    // remove any previous alias and then add the new one
-    $success = db_query("EXECUTE del_url_alias_by_src(':src')", array(':src' => $src));
-    if (!$success) {
-      db_query('DEALLOCATE "del_url_alias_by_src"');
-      db_query('DEALLOCATE "ins_url_alias_nisrds"');
-      db_query("ROLLBACK");
-      tripal_report_error('trp-seturl', TRIPAL_ERROR, "Failed Removing URL Alias: %src", array('%src' => $src));
-      return;
-    }
-    $success = db_query("EXECUTE ins_url_alias_nisrds(:src, :dst)", array(':src' => $src, ':dst' => $dst));
-    if (!$success) {
-      db_query('DEALLOCATE "del_url_alias_by_src"');
-      db_query('DEALLOCATE "ins_url_alias_nisrds"');
-      db_query("ROLLBACK");
-      tripal_report_error('trp-seturl', TRIPAL_ERROR, "Failed Adding URL Alias: %dst", array('%dst' => $dst));
-      return;
-    }
-
-    // update the job status every 1% stocks
-    if ($job and $num_set % $num_per_interval == 0) {
-      $percent = ($num_set / $num_nodes) * 100;
-      tripal_set_job_progress($job, intval($percent));
-      $percent = sprintf("%.2f", $percent);
-      print "Setting URLs (" . $percent . "%). Memory: " . number_format(memory_get_usage()) . " bytes.\r";
-
-    }
-    $num_set++;
-  }
-  $percent = ($num_set / $num_nodes) * 100;
-  tripal_set_job_progress($job, intval($percent));
-  $percent = sprintf("%.2f", $percent);
-  print "Setting URLs (" . $percent . "%). Memory: " . number_format(memory_get_usage()) . " bytes.\r";
-  print "\nDone. Set " . number_format($num_set) . " URLs\n";
-
-  // unprepare the statements
-  db_query('DEALLOCATE "del_url_alias_by_src"');
-  db_query('DEALLOCATE "ins_url_alias_nisrds"');
-
-  db_query("COMMIT");
-}
-/**
- *
- * @param $node
- *   A node object containing at least the stock_id and nid
- * @param $url_alias
- *   Optional.  This should be the URL alias syntax string that contains
- *   placeholders such as [id], [genus], [species], [name], [uniquename],
- *   and [type].  These placeholders will be substituted for actual values.
- *   If this parameter is not provided then the value of the
- *   chado_stock_url_string Drupal variable will be used.
- */
-function tripal_stock_get_stock_url($node, $url_alias = NULL) {
-
-  // get the starting URL alias
-  if(!$url_alias) {
-    $url_alias = variable_get('chado_stock_url_string', '/stock/[genus]/[species]/[type]/[uniquename]');
-    if (!$url_alias) {
-      $url_alias = '/stock/[genus]/[species]/[type]/[uniquename]';
-    }
-    $url_alias = preg_replace('/^\//', '', $url_alias); // remove any preceeding forward slash
-  }
-
-  // get the stock
-  $values = array('stock_id' => $node->stock_id);
-  $options = array('statement_name' => 'sel_stock_id');
-  $stock = chado_select_record('stock', array('*'), $values, $options);
-  if (!$stock) {
-    tripal_report_error('trp-seturl', TRIPAL_ERROR, "Cannot find stock when setting URL alias for stock: %id", array('%id' => $node->stock_id));
-    return FALSE;
-  }
-  $stock = (object) $stock[0];
-
-  // get the organism
-  $values = array('organism_id' => $stock->organism_id);
-  $options = array('statement_name' => 'sel_organism_id');
-  $organism  = chado_select_record('organism', array('*'), $values, $options);
-  if (!$organism) {
-    tripal_report_error('trp-seturl', TRIPAL_ERROR, "Cannot find organism when setting URL alias for stock: %id", array('%id' => $node->stock_id));
-    return FALSE;
-  }
-  $genus = preg_replace('/\s/', '_', strtolower($organism[0]->genus));
-  $species = preg_replace('/\s/', '_', strtolower($organism[0]->species));
-
-  // get the type
-  $values = array('cvterm_id' => $stock->type_id);
-  $options = array('statement_name' => 'sel_cvterm_id');
-  $cvterm = chado_select_record('cvterm', array('name'), $values, $options);
-  if (!$cvterm) {
-    tripal_report_error('trp-seturl', TRIPAL_ERROR, "Cannot find type when setting URL alias for stock: %id", array('%id' => $node->stock_id));
-    return FALSE;
-  }
-  $type = preg_replace('/\s/', '_', $cvterm[0]->name);
-
-  // now substitute in the values
-  $url_alias = preg_replace('/\[id\]/', $stock->stock_id, $url_alias);
-  $url_alias = preg_replace('/\[genus\]/', $genus, $url_alias);
-  $url_alias = preg_replace('/\[species\]/', $species, $url_alias);
-  $url_alias = preg_replace('/\[type\]/', $type, $url_alias);
-  $url_alias = preg_replace('/\[name\]/', $stock->name, $url_alias);
-  $url_alias = preg_replace('/\[uniquename\]/', $stock->uniquename, $url_alias);
-
-  // the dst field of the url_alias table is only 128 characters long.
-  // if this is the case then simply return the node URL, we can't set this one
-  if (strlen($url_alias) > 128) {
-    tripal_report_error('trp-seturl', TRIPAL_ERROR, "Cannot set alias longer than 128 characters: %alias.", array('%alias' => $url_alias));
-    return "node/" . $node->nid;
-  }
-
-  return $url_alias;
-}

+ 100 - 0
tripal_stock/theme/tripal_stock.theme.inc

@@ -0,0 +1,100 @@
+<?php
+/**
+ * @file
+ * Contains functions related to theme-ing including preprocess hooks
+ */
+
+ /**
+ * Implements hook_preprocess_tripal_stock_relationships() which is the preprocess
+ * hook for the tripal_stock_relationships template
+ *
+ * @ingroup tripal_stock
+ */
+function tripal_stock_preprocess_tripal_stock_relationships(&$variables) {
+  // we want to provide a new variable that contains the matched stocks.
+  $stock = $variables['node']->stock;
+
+  // expand the stock object to include the stock relationships.
+  $options = array(
+    'return_array' => 1,
+    'order_by' => array('rank' => 'ASC'),
+    // we don't want to fully recurse we only need information about the
+    // relationship type and the object and subject stocks (including stock type
+    // and organism)
+    'include_fk' => array(
+      'type_id' => 1,
+      'object_id' => array(
+        'type_id' => 1,
+        'organism_id' => 1
+      ),
+      'subject_id'  => array(
+        'type_id' => 1,
+        'organism_id' => 1
+      ),
+    ),
+  );
+  $stock = chado_expand_var($stock, 'table', 'stock_relationship', $options);
+
+  // get the subject relationships
+  $srelationships = $stock->stock_relationship->subject_id;
+  $orelationships = $stock->stock_relationship->object_id;
+
+  // combine both object and subject relationshisp into a single array
+  $relationships = array();
+  $relationships['object'] = array();
+  $relationships['subject'] = array();
+
+  // iterate through the object relationships
+  if ($orelationships) {
+    foreach ($orelationships as $relationship) {
+      $rel = new stdClass();
+      $rel->record = $relationship;
+
+      // get the relationship and child types
+      $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
+      $child_type = $relationship->subject_id->type_id->name;
+
+      // get the node id of the subject
+      $sql = "SELECT nid FROM {chado_stock} WHERE stock_id = :stock_id";
+      $n = db_query($sql, array(':stock_id' => $relationship->subject_id->stock_id))->fetchObject();
+      if ($n) {
+        $rel->record->nid = $n->nid;
+      }
+
+      if (!array_key_exists($rel_type, $relationships['object'])) {
+        $relationships['object'][$rel_type] = array();
+      }
+      if (!array_key_exists($child_type, $relationships['object'][$rel_type])) {
+        $relationships['object'][$rel_type][$child_type] = array();
+      }
+      $relationships['object'][$rel_type][$child_type][] = $rel;
+    }
+  }
+
+  // now add in the subject relationships
+  if ($srelationships) {
+    foreach ($srelationships as $relationship) {
+      $rel = new stdClass();
+      $rel->record = $relationship;
+      $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
+      $parent_type = $relationship->object_id->type_id->name;
+
+      // get the node id of the subject
+      $sql = "SELECT nid FROM {chado_stock} WHERE stock_id = :stock_id";
+      $n = db_query($sql, array(':stock_id' => $relationship->object_id->stock_id))->fetchObject();
+      if ($n) {
+        $rel->record->nid = $n->nid;
+      }
+
+      if (!array_key_exists($rel_type, $relationships['subject'])) {
+        $relationships['subject'][$rel_type] = array();
+      }
+      if (!array_key_exists($parent_type, $relationships['subject'][$rel_type])) {
+        $relationships['subject'][$rel_type][$parent_type] = array();
+      }
+      $relationships['subject'][$rel_type][$parent_type][] = $rel;
+    }
+  }
+  $stock->all_relationships = $relationships;
+
+}

+ 10 - 3
tripal_stock/tripal_stock.install

@@ -1,13 +1,14 @@
 <?php
-
-
 /**
  * Install the tripal stock module including it's content type
  * @file
  */
 
 /**
+ * Implements hook_disable().
  * Disable default views when module is disabled
+ *
+ * @ingroup tripal_stock
  */
 function tripal_stock_disable() {
 
@@ -23,6 +24,7 @@ function tripal_stock_disable() {
 /**
  * Implementation of hook_requirements().
  *
+ * @ingroup tripal_stock
  */
 function tripal_stock_requirements($phase) {
   $requirements = array();
@@ -41,6 +43,8 @@ function tripal_stock_requirements($phase) {
 
 /**
  * Implementation of hook_install().
+ *
+ * @ingroup tripal_stock
  */
 function tripal_stock_install() {
   // create the module's data directory
@@ -49,14 +53,17 @@ function tripal_stock_install() {
 
 /**
  * Implementation of hook_uninstall().
+ *
+ * @ingroup tripal_stock
  */
-
 function tripal_stock_uninstall() {
 
 }
 
 /**
  * Implementation of hook_schema().
+ *
+ * @ingroup tripal_stock
  */
 function tripal_stock_schema() {
   $schema['chado_stock'] = array(

+ 33 - 116
tripal_stock/tripal_stock.module

@@ -1,10 +1,16 @@
 <?php
-
 /**
  * @file
- * Implements Tripal Stock Module hooks
+ * Basic functionality for stocks
  */
 
+require_once 'api/tripal_stock.api.inc';
+
+require_once 'theme/tripal_stock.theme.inc';
+
+require_once 'includes/tripal_stock.admin.inc';
+require_once 'includes/tripal_stock.chado_node.inc';
+
 /**
  * @defgroup tripal_stock Stock Module
  * @ingroup tripal_modules
@@ -21,15 +27,10 @@
  * Stock Module see the GMOD Wiki Page (http://gmod.org/wiki/Chado_Stock_Module)
  * @}
  */
-require_once("includes/tripal_stock.admin.inc");
-require_once("includes/tripal_stock.sync_stocks.inc");
-require_once("includes/other_module_api_functions.inc");
-require_once("includes/tripal_stock.chado_node.inc");
-
-require_once("api/tripal_stock.api.inc");
 
 /**
- * Implements hook_menu(): Adds menu items for the tripal_stock
+ * Implements hook_menu().
+ * Adds menu items for the tripal_stock
  *
  * @return
  *   Menu definitions for the tripal_stock
@@ -94,7 +95,7 @@ function tripal_stock_menu() {
 /**
  * Implements Menu wildcard_load hook
  *
- * Purpose: Allows the node ID of a chado stock to be dynamically
+ * Allows the node ID of a chado stock to be dynamically
  *   pulled from the path. The node is loaded from this node ID
  *   and supplied to the page as an arguement. This is an example
  *   of dynamic argument replacement using wildcards in the path.
@@ -119,9 +120,8 @@ function cs_node_load($nid) {
 }
 
 /**
- * Implementation of hook_permission().
- *
- * Purpose: Set the permission types that the chado stock module uses
+ * Implements hook_permission().
+ * Set the permission types that the chado stock module uses
  *
  * @return
  *   Listing of the possible permission catagories
@@ -154,7 +154,7 @@ function tripal_stock_permission() {
 }
 
 /**
- * Implement hook_access().
+ * Implement hook_node_access().
  *
  * This hook allows node modules to limit access to the node types they define.
  *
@@ -202,7 +202,7 @@ function chado_stock_node_access($node, $op, $account) {
 }
 
 /**
- * Implements hook_views_api()
+ * Implements hook_views_api().
  *
  * Purpose: Essentially this hook tells drupal that there is views support for
  *  for this module which then includes tripal_stock.views.inc where all the
@@ -215,12 +215,13 @@ function chado_stock_node_access($node, $op, $account) {
  */
 function tripal_stock_views_api() {
   return array(
-    'api' => 2.0,
+    'api' => 3.0,
   );
 }
 
 /**
- * Implements hook_theme(): Register themeing functions for this module
+ * Implements hook_theme().
+ * Register themeing functions for this module
  *
  * @return
  *   An array of themeing functions to register
@@ -318,9 +319,12 @@ function tripal_stock_theme($existing, $type, $theme, $path) {
   );
   return $items;
 }
+
 /**
- * Implements hook_help()
- * Purpose: Adds a help page to the module list
+ * Implements hook_help().
+ * Adds a help page to the module list
+ *
+ * @ingroup tripal_stock
  */
 function tripal_stock_help ($path, $arg) {
   if ($path == 'admin/help#tripal_stock') {
@@ -329,6 +333,8 @@ function tripal_stock_help ($path, $arg) {
 }
 
 /**
+ * Implements hook_block_info().
+ *
  * @ingroup tripal_stock
  */
 function tripal_stock_block_info() {
@@ -364,7 +370,9 @@ function tripal_stock_block_info() {
 
   return $blocks;
 }
+
 /**
+ * Implements hook_block_view().
  *
  * @ingroup tripal_stock
  */
@@ -431,105 +439,13 @@ function tripal_stock_block_view($delta = '') {
   }
 }
 
-/**
- *
- *
- * @ingroup tripal_stock
- */
-function tripal_stock_preprocess_tripal_stock_relationships(&$variables) {
-  // we want to provide a new variable that contains the matched stocks.
-  $stock = $variables['node']->stock;
-
-  // expand the stock object to include the stock relationships.
-  $options = array(
-    'return_array' => 1,
-    'order_by' => array('rank' => 'ASC'),
-    // we don't want to fully recurse we only need information about the
-    // relationship type and the object and subject stocks (including stock type
-    // and organism)
-    'include_fk' => array(
-      'type_id' => 1,
-      'object_id' => array(
-        'type_id' => 1,
-        'organism_id' => 1
-      ),
-      'subject_id'  => array(
-        'type_id' => 1,
-        'organism_id' => 1
-      ),
-    ),
-  );
-  $stock = chado_expand_var($stock, 'table', 'stock_relationship', $options);
-
-  // get the subject relationships
-  $srelationships = $stock->stock_relationship->subject_id;
-  $orelationships = $stock->stock_relationship->object_id;
-
-  // combine both object and subject relationshisp into a single array
-  $relationships = array();
-  $relationships['object'] = array();
-  $relationships['subject'] = array();
-
-  // iterate through the object relationships
-  if ($orelationships) {
-    foreach ($orelationships as $relationship) {
-      $rel = new stdClass();
-      $rel->record = $relationship;
-
-      // get the relationship and child types
-      $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
-      $child_type = $relationship->subject_id->type_id->name;
-
-      // get the node id of the subject
-      $sql = "SELECT nid FROM {chado_stock} WHERE stock_id = :stock_id";
-      $n = db_query($sql, array(':stock_id' => $relationship->subject_id->stock_id))->fetchObject();
-      if ($n) {
-        $rel->record->nid = $n->nid;
-      }
-
-      if (!array_key_exists($rel_type, $relationships['object'])) {
-        $relationships['object'][$rel_type] = array();
-      }
-      if (!array_key_exists($child_type, $relationships['object'][$rel_type])) {
-        $relationships['object'][$rel_type][$child_type] = array();
-      }
-      $relationships['object'][$rel_type][$child_type][] = $rel;
-    }
-  }
-
-  // now add in the subject relationships
-  if ($srelationships) {
-    foreach ($srelationships as $relationship) {
-      $rel = new stdClass();
-      $rel->record = $relationship;
-      $rel_type = t(preg_replace('/_/', " ", $relationship->type_id->name));
-      $parent_type = $relationship->object_id->type_id->name;
-
-      // get the node id of the subject
-      $sql = "SELECT nid FROM {chado_stock} WHERE stock_id = :stock_id";
-      $n = db_query($sql, array(':stock_id' => $relationship->object_id->stock_id))->fetchObject();
-      if ($n) {
-        $rel->record->nid = $n->nid;
-      }
-
-      if (!array_key_exists($rel_type, $relationships['subject'])) {
-        $relationships['subject'][$rel_type] = array();
-      }
-      if (!array_key_exists($parent_type, $relationships['subject'][$rel_type])) {
-        $relationships['subject'][$rel_type][$parent_type] = array();
-      }
-      $relationships['subject'][$rel_type][$parent_type][] = $rel;
-    }
-  }
-  $stock->all_relationships = $relationships;
-
-}
-
 /*
  * Uses the value provided in the $id argument to find all stocks that match
  * that ID by name, stockname or synonym.  If it matches uniquenly to a single
  * stock it will redirect to that stock page, otherwise, a list of matching
  * stocks is shown.
+ *
+ * @ingroup tripal_stock
  */
 function tripal_stock_match_stocks_page($id) {
 
@@ -545,7 +461,6 @@ function tripal_stock_match_stocks_page($id) {
     drupal_goto($id);
   }
 
-
   $sql = "
     SELECT
       S.name, S.uniquename, S.stock_id,
@@ -596,15 +511,17 @@ function tripal_stock_match_stocks_page($id) {
 }
 
 /**
- * Implementation of hook_form_alter()
+ * Implementation of hook_form_alter().
  *
  * @param $form
  * @param $form_state
  * @param $form_id
+ *
+ * @ingroup tripal_stock
  */
 function tripal_stock_form_alter(&$form, &$form_state, $form_id) {
   // turn of preview button for insert/updates
   if ($form_id == "chado_stock_node_form") {
     $form['actions']['preview']['#access'] = FALSE;
   }
-}
+}

+ 12 - 2
tripal_stock/tripal_stock.views_default.inc

@@ -1,8 +1,13 @@
 <?php
+/**
+ * @file
+ * Describes stock default views.
+ */
 
 /**
+ * Implements hook_views_default_views().
  *
- *
+ * @ingroup tripal_stock
  */
 function tripal_stock_views_default_views() {
   $views = array();
@@ -13,6 +18,11 @@ function tripal_stock_views_default_views() {
   return $views;
 }
 
+/**
+ * Default stock administration view
+ *
+ * @ingroup tripal_stock
+ */
 function tripal_stock_defaultview_admin_stocks() {
 
   $view = new view();
@@ -242,4 +252,4 @@ function tripal_stock_defaultview_admin_stocks() {
   $handler->display->display_options['filters']['type_id']['expose']['max_length'] = 40;
   */
   return $view;
-}
+}