Browse Source

Merge branch '6.x-1617096-unify_coding_style' of git.drupal.org:sandbox/spficklin/1337878 into 6.x-1617096-unify_coding_style

Lacey Sanderson 12 years ago
parent
commit
b0bc5ded49

+ 92 - 84
tripal_db/tripal_db.api.inc

@@ -1,10 +1,12 @@
 <?php
 
 /**
+ * @file
+ * Provides an application programming interface (API) to manage references to external databases
+ *
  * @defgroup tripal_db_api DB Module API
  * @ingroup tripal_api
  * @ingroup tripal_db
- * Provides an application programming interface (API) to manage references to external databases
  */
 
 /**
@@ -17,7 +19,7 @@
  *   Chado database object
  *
  * The database is selected using tripal_core_chado select and as such the
- * $select_values array parameter meant to uniquely identify the database to be 
+ * $select_values array parameter meant to uniquely identify the database to be
  * returned follows the same form as when using tripal_core_chado_select directly.
  *
  * Example Usage:
@@ -29,22 +31,22 @@
  * @endcode
  *  The above code selects the SOFP db and returns the following object:
  * @code
-    $db_object = stdClass Object ( 
+    $db_object = stdClass Object (
       [db_id] => 49
       [name] => SOFP
-      [description] => 
-      [urlprefix] => 
-      [url] =>     
-    ); 
+      [description] =>
+      [urlprefix] =>
+      [url] =>
+    );
  * @endcode
  *
  * @ingroup tripal_db_api
  */
-function tripal_db_get_db ($select_values) {
+function tripal_db_get_db($select_values) {
 
   $columns = array(
-    'db_id', 
-    'name', 
+    'db_id',
+    'name',
     'description',
     'urlprefix',
     'url'
@@ -52,21 +54,23 @@ function tripal_db_get_db ($select_values) {
   $results = tripal_core_chado_select('db', $columns, $select_values);
   if (sizeof($results) == 1) {
     return $results[0];
-  } elseif (empty($results)) {
-    watchdog('tripal_cdb', 
+  }
+  elseif (empty($results)) {
+    watchdog('tripal_cdb',
       'tripal_db_get_db: No db matches criteria values:%values',
       array('%values' => print_r($select_values, TRUE)),
       WATCHDOG_WARNING
     );
     return FALSE;
-  } else {
-    watchdog('tripal_db', 
+  }
+  else {
+    watchdog('tripal_db',
       'tripal_db_get_db: 2+ dbs match criteria values:%values',
       array('%values' => print_r($select_values, TRUE)),
       WATCHDOG_WARNING
     );
   }
-  
+
 }
 
 /**
@@ -74,16 +78,16 @@ function tripal_db_get_db ($select_values) {
  *
  * @param $db_id
  *   db.db_id
- * @return 
+ * @return
  *   Chado db object with all fields from the chado db table
  *
  * @ingroup tripal_db_api
  */
-function tripal_db_get_db_by_db_id ($db_id) {
+function tripal_db_get_db_by_db_id($db_id) {
 
-	$previous_db = tripal_db_set_active('chado');
+  $previous_db = tripal_db_set_active('chado');
   $r = db_fetch_object(db_query(
-    "SELECT * FROM db WHERE db_id=%d", $db_id
+    "SELECT * FROM {db} WHERE db_id=%d", $db_id
   ));
   tripal_db_set_active($previous_db);
 
@@ -95,16 +99,16 @@ function tripal_db_get_db_by_db_id ($db_id) {
  *
  * @param $name
  *   db.name
- * @return 
+ * @return
  *   chado db object with all fields from the chado db table
  *
  * @ingroup tripal_db_api
  */
-function tripal_db_get_db_by_name ($name) {
+function tripal_db_get_db_by_name($name) {
 
-	$previous_db = tripal_db_set_active('chado');
+  $previous_db = tripal_db_set_active('chado');
   $r = db_fetch_object(db_query(
-    "SELECT * FROM db WHERE name='%s'", $name
+    "SELECT * FROM {db} WHERE name='%s'", $name
   ));
   tripal_db_set_active($previous_db);
 
@@ -114,12 +118,12 @@ function tripal_db_get_db_by_name ($name) {
 // Purpose: To retrieve a chado db object
 //
 // @params where_options: array(
-//													<column_name> => array(
-//														'type' => <type of column: INT/**STRING>,
-//														'value' => <the vlaue you want to filter on>,
-//														'exact' => <if TRUE use =; if FALSE use ~>,
-//													)
-//				)
+//                          <column_name> => array(
+//                            'type' => <type of column: INT/**STRING>,
+//                            'value' => <the vlaue you want to filter on>,
+//                            'exact' => <if TRUE use =; if FALSE use ~>,
+//                          )
+//        )
 // @return chado db object with all fields from the chado db table
 //
 //function tripal_db_get_db ($where_options) {
@@ -128,7 +132,7 @@ function tripal_db_get_db_by_name ($name) {
  * Purpose: Create an options array to be used in a form element
  *   which provides a list of all chado dbs
  *
- * @return 
+ * @return
  *   An array(db_id => name) for each db in the chado db table
  *
  * @ingroup tripal_db_api
@@ -137,7 +141,7 @@ function tripal_db_get_db_options() {
 
   $previous_db = tripal_db_set_active('chado');
   $result = db_query(
-    "SELECT db_id, name FROM db"
+    "SELECT db_id, name FROM {db}"
   );
   tripal_db_set_active($previous_db);
 
@@ -153,12 +157,12 @@ function tripal_db_get_db_options() {
 // Purpose: To retrieve a chado dbxref object
 //
 // @param where_options: array(
-//													<column_name> => array(
-//														'type' => <type of column: INT/**STRING>,
-//														'value' => <the vlaue you want to filter on>,
-//														'exact' => <if TRUE use =; if FALSE use ~>,
-//													)
-//				)
+//                          <column_name> => array(
+//                            'type' => <type of column: INT/**STRING>,
+//                            'value' => <the vlaue you want to filter on>,
+//                            'exact' => <if TRUE use =; if FALSE use ~>,
+//                          )
+//        )
 // @return chado dbxref object with all fields from the chado dbxref table
 //
 //function tripal_db_get_dbxref ($where_options) {
@@ -173,7 +177,7 @@ function tripal_db_get_db_options() {
  *   Chado database reference object
  *
  * The database reference is selected using tripal_core_chado select and as such the
- * $select_values array parameter meant to uniquely identify the database reference to be 
+ * $select_values array parameter meant to uniquely identify the database reference to be
  * returned follows the same form as when using tripal_core_chado_select directly.
  *
  * Example Usage:
@@ -188,27 +192,27 @@ function tripal_db_get_db_options() {
  * @endcode
  *  The above code selects the synonym database reference and returns the following object:
  * @code
-    $dbxref_object = stdClass Object ( 
+    $dbxref_object = stdClass Object (
       [dbxref_id] => 2581
       [accession] => synonym
-      [description] => 
-      [version] => 
+      [description] =>
+      [version] =>
       [db_db_id] => 49
       [db_name] => SOFP
-      [db_description] => 
-      [db_urlprefix] => 
-      [db_url] =>     
-    ); 
+      [db_description] =>
+      [db_urlprefix] =>
+      [db_url] =>
+    );
  * @endcode
  *
  * @ingroup tripal_db_api
  */
-function tripal_db_get_dbxref ($select_values) {
+function tripal_db_get_dbxref($select_values) {
 
   $columns = array(
     'dbxref_id',
-    'db_id', 
-    'accession', 
+    'db_id',
+    'accession',
     'description',
     'version'
   );
@@ -218,15 +222,17 @@ function tripal_db_get_dbxref ($select_values) {
     unset($dbxref->db_id);
 
     return $dbxref;
-  } elseif (empty($results)) {
-    watchdog('tripal_db', 
+  }
+  elseif (empty($results)) {
+    watchdog('tripal_db',
       'tripal_db_get_dbxref: No dbxref matches criteria values:%values',
       array('%values' => print_r($select_values, TRUE)),
       WATCHDOG_WARNING
     );
     return FALSE;
-  } else {
-    watchdog('tripal_db', 
+  }
+  else {
+    watchdog('tripal_db',
       'tripal_db_get_dbxref: 2+ dbxrefs match criteria values:%values',
       array('%values' => print_r($select_values, TRUE)),
       WATCHDOG_WARNING
@@ -242,29 +248,30 @@ function tripal_db_get_dbxref ($select_values) {
  *   dbxref.accession
  * @param $db_id
  *   dbxref.db_id
- * @return 
+ * @return
  *   chado dbxref object with all fields from the chado dbxref table
  *
  * @ingroup tripal_db_api
  */
-function tripal_db_get_dbxref_by_accession ($accession, $db_id=0) {
+function tripal_db_get_dbxref_by_accession($accession, $db_id=0) {
 
   if (!empty($db_id)) {
-	  $previous_db = tripal_db_set_active('chado');
+    $previous_db = tripal_db_set_active('chado');
     $r = db_fetch_object(db_query(
-      "SELECT * FROM dbxref WHERE accession='%s' AND db_id=%d",
+      "SELECT * FROM {dbxref} WHERE accession='%s' AND db_id=%d",
       $accession, $db_id
     ));
     tripal_db_set_active($previous_db);
-  } else {
-	  $previous_db = tripal_db_set_active('chado');
+  }
+  else {
+    $previous_db = tripal_db_set_active('chado');
     $r = db_fetch_object(db_query(
-      "SELECT * FROM dbxref WHERE accession='%s'",
+      "SELECT * FROM {dbxref} WHERE accession='%s'",
       $accession
     ));
-    tripal_db_set_active($previous_db);  
+    tripal_db_set_active($previous_db);
   }
-  
+
   return $r;
 }
 
@@ -286,7 +293,7 @@ function tripal_db_chado_dbxref_schema() {
         'columns' => array(
           'db_id' => 'db_id',
         ),
-  ); 
+  );
 
   return $description;
 }
@@ -304,7 +311,7 @@ function tripal_db_chado_dbxref_schema() {
 *   Optional. The URL that is to be used as a prefix when constructing a link to
 *   a database term
 * @param $update
-*   Optional. Set this to '1' to force an update of the database if it 
+*   Optional. Set this to '1' to force an update of the database if it
 *   already exists. The default is to not update. If the database exists
 *   then nothing is added.
 *
@@ -313,7 +320,7 @@ function tripal_db_chado_dbxref_schema() {
 *
 * @ingroup tripal_db_api
 */
-function tripal_db_add_db($dbname,$description='',$url='',$urlprefix='',$update=0){
+function tripal_db_add_db($dbname, $description='', $url='', $urlprefix='', $update=0) {
 
 
    $values = array(
@@ -322,24 +329,25 @@ function tripal_db_add_db($dbname,$description='',$url='',$urlprefix='',$update=
       'url' => $url,
       'urlprefix' => $urlprefix
    );
-      
+
    $db_sql = "SELECT * FROM {db} WHERE name ='%s'";
-   $db = db_fetch_object(db_query($db_sql,$dbname));
-   if(!$db){
-      if(!tripal_core_chado_insert('db',$values)){
-         watchdog('tripal_db', "Cannot create db '$dbname'.",NULL,WATCHDOG_WARNING);
+   $db = db_fetch_object(db_query($db_sql, $dbname));
+   if (!$db) {
+      if (!tripal_core_chado_insert('db', $values)) {
+         watchdog('tripal_db', "Cannot create db '$dbname'.", NULL, WATCHDOG_WARNING);
          return 0;
-      }      
-      $db = tripal_core_chado_select('db',array('*'),$values);
-   } 
-   elseif($update) {
+      }
+      $db = tripal_core_chado_select('db', array('*'), $values);
+   }
+   elseif ($update) {
       $match = array('db_id' => $db->db_id);
-      if(!tripal_core_chado_update('db',$match,$values)){
-         watchdog('tripal_db', "Cannot update db '$dbname'.",NULL,WATCHDOG_WARNING);
+      if (!tripal_core_chado_update('db', $match, $values)) {
+         watchdog('tripal_db', "Cannot update db '$dbname'.", NULL, WATCHDOG_WARNING);
          return 0;
-      }      
-      $db = tripal_core_chado_select('db',array('*'),$values);
-   } else {
+      }
+      $db = tripal_core_chado_select('db', array('*'), $values);
+   }
+   else {
       return $db;
    }
 }
@@ -347,7 +355,7 @@ function tripal_db_add_db($dbname,$description='',$url='',$urlprefix='',$update=
 *
 * @ingroup tripal_db_api
 */
-function tripal_db_add_dbxref($db_id,$accession,$version='',$description=''){
+function tripal_db_add_dbxref($db_id, $accession, $version='', $description='') {
 
    // check to see if the dbxref exists if not, add it
    $dbxsql = "
@@ -357,18 +365,18 @@ function tripal_db_add_dbxref($db_id,$accession,$version='',$description=''){
          INNER JOIN db DB on DB.db_id = DBX.db_id
       WHERE DBX.db_id = %d and DBX.accession = '%s'
    ";
-   $dbxref = db_fetch_object(db_query($dbxsql,$db_id,$accession));
-   if(!$dbxref){
+   $dbxref = db_fetch_object(db_query($dbxsql, $db_id, $accession));
+   if (!$dbxref) {
       $sql = "
          INSERT INTO {dbxref} (db_id, accession, version, description)
          VALUES (%d,'%s','%s','%s')
       ";
-      if(!db_query($sql,$db_id,$accession,$version,$description)){
-         watchdog('tripal_cv', "Failed to insert the dbxref record $accession",NULL,WATCHDOG_WARNING);
+      if (!db_query($sql, $db_id, $accession, $version, $description)) {
+         watchdog('tripal_cv', "Failed to insert the dbxref record $accession", NULL, WATCHDOG_WARNING);
          return 0;
       }
       print "Added Dbxref accession: $accession\n";
-      $dbxref = db_fetch_object(db_query($dbxsql,$db_id,$accession));
+      $dbxref = db_fetch_object(db_query($dbxsql, $db_id, $accession));
    }
    return $dbxref;
 

+ 7 - 2
tripal_db/tripal_db.install

@@ -1,11 +1,16 @@
 <?php
 
+/**
+ * @file
+ * Contains functions related to the installation of this module
+ */
+
 /**
 *  Implementation of hook_install();
 *
 * @ingroup tripal_db
 */
-function tripal_db_install(){
+function tripal_db_install() {
 
    // create the module's data directory
    tripal_create_moddir('tripal_db');
@@ -17,7 +22,7 @@ function tripal_db_install(){
 *
 * @ingroup tripal_db
 */
-function tripal_db_uninstall(){
+function tripal_db_uninstall() {
 
 }
 

+ 80 - 75
tripal_db/tripal_db.module

@@ -6,16 +6,16 @@ require_once "tripal_db.api.inc";
  * @defgroup tripal_db DB Module
  * @ingroup tripal_modules
  */
- 
+
 /**
 *
 * @ingroup tripal_db
 */
-function tripal_db_init(){
+function tripal_db_init() {
 
    // add the tripal_db JS and CSS
-   drupal_add_css(drupal_get_path('theme', 'tripal').'/css/tripal_db.css');
-   drupal_add_js(drupal_get_path('theme', 'tripal').'/js/tripal_db.js');
+   drupal_add_css(drupal_get_path('theme', 'tripal') . '/css/tripal_db.css');
+   drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_db.js');
 }
 /**
 *
@@ -39,7 +39,7 @@ function tripal_db_menu() {
      'access arguments' => array('administer site configuration'),
      'type' => MENU_NORMAL_ITEM,
    );
-   
+
    $items['admin/tripal/tripal_db/add_db'] = array(
      'title' => 'Add a Database',
      'page callback' => 'drupal_get_form',
@@ -64,7 +64,7 @@ function tripal_db_menu() {
 *
 * @ingroup tripal_db
 */
-function tripal_db_perm(){
+function tripal_db_perm() {
    return array(
       'access chado_db content',
       'create chado_db content',
@@ -82,7 +82,7 @@ function tripal_db_perm(){
  * @ingroup tripal_db
  */
 function tripal_db_views_api() {
-	return array('api' => 2.0);
+  return array('api' => 2.0);
 }
 
 /**
@@ -97,42 +97,42 @@ function tripal_db_module_description_page() {
 
   $text = '<h3>Tripal External Database Administrative Tools Quick Links</h3>';
     $text .= '<ul>';
-      $text .= '<li>'.l('Add External DB', 'admin/tripal/tripal_db/add_db').'</li>';
-      $text .= '<li>'.l('Update/Delete External DBs', 'admin/tripal/tripal_db/edit_db').'</li>';
-      $text .= '<li>'.l('Database References Listing', 'admin/tripal/tripal_db/list_dbxrefs').'</li>';
+      $text .= '<li>' . l('Add External DB', 'admin/tripal/tripal_db/add_db') . '</li>';
+      $text .= '<li>' . l('Update/Delete External DBs', 'admin/tripal/tripal_db/edit_db') . '</li>';
+      $text .= '<li>' . l('Database References Listing', 'admin/tripal/tripal_db/list_dbxrefs') . '</li>';
     $text .= '</ul>';
-    
+
   $text .= '<h3>Module Description:</h3>';
   $text .= '<p>The Tripal DB Module provides functionality for linking the data in your Tripal Website with other biological websites out there. Essentially you register an enternal database with your website and then associate any of your data (usually sequence features) with that external database by providing the accession for your data in the other database. If the other database is online and you provided a URL prefix when you registered the external database with your site then there will be a link on the details page for your data that takes the user to the same record in the external database.</p>';
 
   $text .= '<h3>Setup Instructions:</h3>';
   $text .= '<ol>';
-  $text .= '<li><p><b>Set Permissions</b>: The feature module supports the Drupal user permissions interface for 
-               controlling access to feature content and functions. These permissions include viewing, 
+  $text .= '<li><p><b>Set Permissions</b>: The feature module supports the Drupal user permissions interface for
+               controlling access to feature content and functions. These permissions include viewing,
                creating, editing or administering of
-               feature content. The default is that only the original site administrator has these 
-               permissions.  You can <a href="'.url('admin/user/roles').'">add roles</a> for classifying users, 
-               <a href="'.url('admin/user/user').'">assign users to roles</a> and
-               <a href="'.url('admin/user/permissions').'">assign permissions</a> for the feature content to 
-               those roles.  For a simple setup, allow anonymous users access to view organism content and 
+               feature content. The default is that only the original site administrator has these
+               permissions.  You can <a href="' . url('admin/user/roles') . '">add roles</a> for classifying users,
+               <a href="' . url('admin/user/user') . '">assign users to roles</a> and
+               <a href="' . url('admin/user/permissions') . '">assign permissions</a> for the feature content to
+               those roles.  For a simple setup, allow anonymous users access to view organism content and
                allow the site administrator all other permissions.</p></li>';
   $text .= '<li><b>Register any external databases</b> with data pertinent to your site.</li>';
   $text .= '<li><b>Create Database References</b>: Then as you load in your data, create database references linking your data to the external database.</li>';
   $text .= '</ol>';
-  
-  
+
+
   $text .= '<h3>Features of this Module:</h3>';
   $text .= '<ul>';
   $text .= '<li><b>Add/Register External Databases</b>:';
   $text .= 'By entering the name and any additional details into the <a href="tripal_db/add_db">add database form</a> you register an external database with your website. This allows you to specify that a sequence feature or other data is also stored in an external database. This is escpecially useful if the external database may contain additional details not stored in yours. If the external database is online you can even provide a URL prefix which will automatically link any data in your website to theirs via a web link.</li>';
-  
+
   $text .= '<li><b>Update/Delete External Databases</b>';
   $text .= 'To edit the details of an external database record or to delete an already existing external database, go to the <a href="tripal_db/edit_db">Update/Delete DBs form</a>. This will allow you to change details or enter new details.</li>';
 
   $text .= '<li><b>List all External Database References</b>';
   $text .= 'If you have views installed, there will be a link to a default listing of all database references currently in your database. This listing can be accessed <a href="tripal_db/list_dbxrefs">here</a>. It requires the Drupal Module Views version 2 to be installed (<a href="http://drupal.org/project/views">Drupal Views</a>)</li>';
-  $text .= '</ul>';  
-  
+  $text .= '</ul>';
+
   return $text;
 }
 
@@ -141,9 +141,9 @@ function tripal_db_module_description_page() {
 *
 * @ingroup tripal_db
 */
-function tripal_db_admin_page(){
+function tripal_db_admin_page() {
    $add_url = url("admin/tripal/tripal_db/add_db");
-   $output = "<a href=\"$add_url\">Add a new external database</a>"; 
+   $output = "<a href=\"$add_url\">Add a new external database</a>";
    $output .= drupal_get_form('tripal_db_select_form');
    $output .= '<div id="db-edit-div">Please select a database above to view or edit</div>';
    return $output;
@@ -153,21 +153,21 @@ function tripal_db_admin_page(){
 *
 * @ingroup tripal_db
 */
-function tripal_db_select_form(){
+function tripal_db_select_form() {
 
-	$previous_db = tripal_db_set_active('chado');  // use chado database
-	// get a list of db from chado for user to choose
-	$sql = "SELECT * FROM {db} WHERE NOT name = 'tripal' ORDER BY name ";
-	$results = db_query ($sql);
-	tripal_db_set_active($previous_db); // use drupal database
+  $previous_db = tripal_db_set_active('chado');  // use chado database
+  // get a list of db from chado for user to choose
+  $sql = "SELECT * FROM {db} WHERE NOT name = 'tripal' ORDER BY name ";
+  $results = db_query($sql);
+  tripal_db_set_active($previous_db); // use drupal database
 
-	$dbs = array();
+  $dbs = array();
    $dbs[] = '';
-	while ($db = db_fetch_object($results)){
-		$dbs[$db->db_id] = $db->name;
-	}
+  while ($db = db_fetch_object($results)) {
+    $dbs[$db->db_id] = $db->name;
+  }
 
-	$form['dbid'] = array(
+  $form['dbid'] = array(
       '#title' => t('External Database Name'),
       '#type' => 'select',
       '#options' => $dbs,
@@ -178,7 +178,7 @@ function tripal_db_select_form(){
          'event' => 'change',
          'method' => 'replace',
       ),
-	);
+  );
 
    return $form;
 }
@@ -186,47 +186,48 @@ function tripal_db_select_form(){
 *
 * @ingroup tripal_db
 */
-function tripal_ajax_db_edit (){ 
+function tripal_ajax_db_edit() {
    // get the database id, build the form and then return the JSON object
    $dbid = $_POST['dbid'];
-   $form = drupal_get_form('tripal_db_form',$dbid);
+   $form = drupal_get_form('tripal_db_form', $dbid);
    drupal_json(array('status' => TRUE, 'data' => $form));
 }
 /**
 *
 * @ingroup tripal_db
 */
-function tripal_db_form(&$form_state = NULL,$dbid = NULL){
+function tripal_db_form(&$form_state = NULL, $dbid = NULL) {
 
    // get this requested database
-   if($dbid){
-      $sql = "SELECT * FROM {db} WHERE db_id = $dbid ";
+   if ($dbid) {
+      $sql = "SELECT * FROM {db} WHERE db_id = %d ";
       $previous_db = tripal_db_set_active('chado');
-      $db = db_fetch_object(db_query($sql));
+      $db = db_fetch_object(db_query($sql, $dbid));
       tripal_db_set_active($previous_db);
 
 
-      # set the default values.  If there is a value set in the 
-      # form_state then let's use that, otherwise, we'll pull 
-      # the values from the database 
+      // set the default values.  If there is a value set in the
+      // form_state then let's use that, otherwise, we'll pull
+      // the values from the database
       $default_db = $form_state['values']['name'];
       $default_desc = $form_state['values']['description'];
       $default_url = $form_state['values']['url'];
       $default_urlprefix = $form_state['values']['urlprefix'];
-      if(!$default_db){
+      if (!$default_db) {
          $default_db = $db->name;
       }
-      if(!$default_desc){
+      if (!$default_desc) {
          $default_desc = $db->description;
       }
-      if(!$default_url){
+      if (!$default_url) {
          $default_url = $db->url;
       }
-      if(!$default_urlprefix){
+      if (!$default_urlprefix) {
          $default_urlprefix = $db->urlprefix;
       }
       $action = 'Update';
-   } else {
+   }
+   else {
       $action = 'Add';
    }
 
@@ -267,21 +268,22 @@ function tripal_db_form(&$form_state = NULL,$dbid = NULL){
    );
 
 
-   if(strcmp($action,'Update')==0){
-      $form['update'] = array (
+   if (strcmp($action, 'Update')==0) {
+      $form['update'] = array(
         '#type'         => 'submit',
         '#value'        => t('Update'),
         '#weight'       => 5,
         '#executes_submit_callback' => TRUE,
       );
-      $form['delete'] = array (
+      $form['delete'] = array(
         '#type'         => 'submit',
         '#value'        => t('Delete'),
         '#weight'       => 6,
         '#executes_submit_callback' => TRUE,
       );
-   } else {
-      $form['add'] = array (
+   }
+   else {
+      $form['add'] = array(
         '#type'         => 'submit',
         '#value'        => t('Add'),
         '#weight'       => 5,
@@ -297,7 +299,7 @@ function tripal_db_form(&$form_state = NULL,$dbid = NULL){
 *
 * @ingroup tripal_db
 */
-function tripal_db_form_submit($form, &$form_state){
+function tripal_db_form_submit($form, &$form_state) {
 
    $name =  $form_state['values']['name'];
    $desc =  $form_state['values']['description'];
@@ -306,10 +308,10 @@ function tripal_db_form_submit($form, &$form_state){
    $dbid =  $form_state['values']['dbid'];
    $op   =  $form_state['values']['op'];
 
-   if($dbid){ 
-      if(strcmp($op,'Update')==0){
+   if ($dbid) {
+      if (strcmp($op, 'Update')==0) {
          $sql = "
-            UPDATE {db} SET 
+            UPDATE {db} SET
               name = '%s',
               description = '%s',
               url = '%s',
@@ -317,45 +319,48 @@ function tripal_db_form_submit($form, &$form_state){
             WHERE db_id = %d
          ";
          $previous_db = tripal_db_set_active('chado');
-         $db = db_query($sql,$name,$desc,$url,$urlp,$dbid);
+         $db = db_query($sql, $name, $desc, $url, $urlp, $dbid);
          tripal_db_set_active($previous_db);
-         if($db){
+         if ($db) {
            drupal_set_message("External database updated");
-         } else {
+         }
+         else {
            drupal_set_message("Failed to update external database.");
          }
-      } 
-      if(strcmp($op,'Delete')==0){
+      }
+      if (strcmp($op, 'Delete')==0) {
          $sql = "
             DELETE FROM {db}
             WHERE db_id = %d
          ";
          $previous_db = tripal_db_set_active('chado');
-         $db = db_query($sql,$dbid);
+         $db = db_query($sql, $dbid);
          tripal_db_set_active($previous_db);
-         if($db){
+         if ($db) {
            drupal_set_message("External database deleted");
-         } else {
+         }
+         else {
            drupal_set_message("Failed to delete external database.");
          }
       }
-   } 
-   else { 
+   }
+   else {
       $sql = "
          INSERT INTO {db}
           (name,description,url,urlprefix)
-         VALUES 
+         VALUES
           ('%s','%s','%s','%s')
       ";
       $previous_db = tripal_db_set_active('chado');
-      $db = db_query($sql,$name,$desc,$url,$urlp);
+      $db = db_query($sql, $name, $desc, $url, $urlp);
       tripal_db_set_active($previous_db);
-      if($db){
+      if ($db) {
         drupal_set_message("External database added");
-      } else {
+      }
+      else {
         drupal_set_message("Failed to add external database.");
       }
-   } 
+   }
 
    return '';
 }

+ 6 - 6
tripal_db/tripal_db.views.inc

@@ -6,7 +6,7 @@
  *  chado/tripal db tables. Supplementary functions can be found in
  *  ./views/
  *
- *  Documentation on views integration can be found at 
+ *  Documentation on views integration can be found at
  *  http://views2.logrus.com/doc/html/index.html.
  */
 
@@ -17,13 +17,13 @@
  */
 
 require_once('views/dbxref.views.inc');
-require_once('views/db.views.inc'); 
+require_once('views/db.views.inc');
 /**
  * Implements hook_views_data()
  * Purpose: Describe chado/tripal tables & fields to views
  * @return: a data array which follows the structure outlined in the
  *   views2 documentation for this hook. Essentially, it's an array of table
- *   definitions keyed by chado/tripal table name. Each table definition 
+ *   definitions keyed by chado/tripal table name. Each table definition
  *   includes basic details about the table, fields in that table and
  *   relationships between that table and others (joins)
  *
@@ -42,9 +42,9 @@ function tripal_db_views_data()  {
  *
  * @ingroup tripal_db_views
  */
-function tripal_db_views_default_views () {
+function tripal_db_views_default_views() {
   $views = array();
-  
+
   // Main default view
   // List all cvterms based on cv
   $view = new view;
@@ -306,6 +306,6 @@ function tripal_db_views_default_views () {
     'name' => 'navigation',
   ));
   $views[$view->name] = $view;
-  
+
   return $views;
 }

+ 0 - 45
tripal_db/views/README

@@ -1,45 +0,0 @@
-
-This directory contains all additional views code needed to integrate this module with views2.
-
-FILE/FOLDER DESCRIPTIONS
----------------------------
-<chado table name>.views.inc:
-	contains a single function retrieve_<chado table name>_views_data()
-	which describes that table to views. This function is called by
-	tripal_db_views_data() in ../tripal_db.views.inc.
-	For more information on the form of this data array look up the
-	views2 documentation for hook_views_data() 
-	-http://views2.logrus.com/doc/html/index.html
-	
-handlers/
-	Each file contained within this folder defines a views handler. Only custom
-	handlers are included in this folder and each must be described in 
-	hook_views_handlers() in ../tripal_db.views.inc.
-	A views handler does one of the following:
-		1) describe the type of a field and how it should be displayed
-		2) describe a method to sort this field
-		3) describe a method to filter this field
-
-
-STANDARDS TO FOLLOW
----------------------------
-
-1. All table definition files should be named tablename.views.inc
-2. All handlers should be in a handlers sub-directory and follow the naming convention of
-   views handlers (ie: views_handler_field/filter/sort_handlername.inc )
-
-Views Table Definitions:
-- Please use the template files provided whenever you are describing a new table to views.
-   For any table in chado simply copy template.table_defn.views.inc to tablename.views.inc and 
-   follow the instructions listed at the top of the template file.
-- ONLY ONE TABLE DEFINITION PER FILE
-- To join a chado table to it's drupal node simply copy template.node_join.views.inc to 
-   basetablename.views.inc and replace all XXX with basetablename.
-   
-   NOTE: Creating the table definition file is not enough. You also need to call the 
-         retrieve_XXX_views_data() function from ../tripal_db.views.inc:tripal_db_views_data()
-         by adding the following line:
-            $data = array_merge($data, retrieve_XXX_views_data());
-         to the function and including the file directly above the function (blow the function 
-         header by adding:
-            require_once('views/XXX.views.inc');

+ 21 - 20
tripal_db/views/db.views.inc

@@ -1,7 +1,8 @@
 <?php
 
   /**
- * Purpose: this function returns the portion of the data array 
+ * @file
+ * Purpose: this function returns the portion of the data array
  *   which describes the cv table, it's fields and any joins between it and other tables
  * @see tripal_cv_views_data() --in tripal_cv.views.inc
  *
@@ -21,7 +22,7 @@
  * @ingroup tripal_db_views
  */
 function retrieve_db_views_data() {
-  
+
   // Basic table definition
   $data['db']['table'] = array(
     'field' => 'db_id',
@@ -30,7 +31,7 @@ function retrieve_db_views_data() {
     'help' => 'Database Records existing in the Chado Database',
     'database' => 'chado'
   );
-  
+
   // Define relationships between this table and others
   $data['db']['table']['join'] = array(
     'dbxref' => array(
@@ -38,22 +39,22 @@ function retrieve_db_views_data() {
       'field' => 'db_id',
     ),
     'stock' => array(
-    	'left_table' => 'dbxref',
-    	'left_field' => 'db_id',
-    	'field' => 'db_id',
+      'left_table' => 'dbxref',
+      'left_field' => 'db_id',
+      'field' => 'db_id',
     ),
     'cvterm' => array(
-    	'left_table' => 'dbxref',
-    	'left_field' => 'db_id',
-    	'field' => 'db_id',
+      'left_table' => 'dbxref',
+      'left_field' => 'db_id',
+      'field' => 'db_id',
     ),
     'feature' => array(
-    	'left_table' => 'dbxref',
-    	'left_field' => 'db_id',
-    	'field' => 'db_id',
+      'left_table' => 'dbxref',
+      'left_field' => 'db_id',
+      'field' => 'db_id',
     ),
   );
-  
+
   // Table Field Definitions----------------------
   // Field: db_id (primary key)
   $data['db']['db_id'] = array(
@@ -70,7 +71,7 @@ function retrieve_db_views_data() {
       'handler' => 'views_handler_sort',
     ),
   );
-  
+
   // Field: name (varchar 255)
   $data['db']['name'] = array(
     'title' => 'Name',
@@ -88,7 +89,7 @@ function retrieve_db_views_data() {
       'handler' => 'views_handler_argument_string',
     ),
   );
-  
+
   // Field: description (varchar 255)
   $data['db']['description'] = array(
     'title' => 'Description',
@@ -106,7 +107,7 @@ function retrieve_db_views_data() {
       'handler' => 'views_handler_argument_string',
     ),
   );
-  
+
   // Field: urlprefix (varchar 255)
   $data['db']['urlprefix'] = array(
     'title' => 'URL Prefix',
@@ -125,7 +126,7 @@ function retrieve_db_views_data() {
       'handler' => 'views_handler_argument_string',
     ),
   );
-  
+
   // Field: url (varchar 255)
   $data['db']['url'] = array(
     'title' => 'URL',
@@ -144,7 +145,7 @@ function retrieve_db_views_data() {
       'handler' => 'views_handler_argument_string',
     ),
   );
-  
+
   return $data;
-  
-}
+
+}

+ 5 - 4
tripal_db/views/dbxref.views.inc

@@ -1,7 +1,8 @@
 <?php
 
 /**
- * Purpose: this function returns the portion of the data array 
+ * @file
+ * Purpose: this function returns the portion of the data array
  *   which describes the db table, it's fields and any joins between it and other tables
  * @see tripal_db_views_data() --in tripal_db.views.inc
  *
@@ -45,7 +46,7 @@ function retrieve_dbxref_views_data() {
     'stock' => array(
       'left_field' => 'dbxref_id',
       'field' => 'dbxref_id',
-    ),  
+    ),
   );
 
   // Table Field Definitions----------------------
@@ -64,7 +65,7 @@ function retrieve_dbxref_views_data() {
       'handler' => 'views_handler_sort',
     ),
   );
-   
+
   //Field: cv_id (foreign key: cv)
   //  join between cv table and this one in cv.views.inc
 
@@ -146,4 +147,4 @@ function retrieve_dbxref_views_data() {
 
   return $data;
 
-}
+}

+ 0 - 84
tripal_db/views/template.node_join.views.inc

@@ -1,84 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *  - simply replace all XXX with the original chado table you want to join to it's drupal nodes.
- *    (ie: If you want to join features to their drupal nodes then XXX=feature)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_db.views.inc:tripal_db_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_db.views.inc --in tripal_db_views_data()
- *
- *  Note: All chado tables are joined to their drupal nodes through the chado_XXX linking table. 
- *        This file simply defines this linking table and joins the three tables together.
- *        No modification of XXX.views.inc is needed.
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
- 
-/**
- * Purpose: this function returns the portion of the data array 
- *   which describes the chado_XXX drupal table, it's fields and any joins between it 
- *   and other tables
- * @see tripal_db_views_data() --in tripal_db.views.inc
- *
- * The main need for description of this table to views is to join chado data with drupal nodes
- *
- */
-function retrieve_chado_XXX_views_data () {
-	global $db_url;
-  $data = array();
-  
-  // if the chado database is not local to the drupal database
-  // then we need to set the database name.  This should always
-  // be 'chado'.
-  if(is_array($db_url) and array_key_exists('chado',$db_url)){
-     // return empty data array b/c if chado is external then no join to the nodetable can be made
-     return $data;
-  }
-
-  //Basic table definition-----------------------------------
-  $data['chado_XXX']['table'] = array(
-    'field' => 'nid',
-  );
-  
-  //Relationship Definitions---------------------------------
-  // Note: No joins need to be made from $data['XXX']['table']
-  
-  // Join the chado_XXX table to XXX
-  $data['chado_XXX']['table']['join']['XXX'] = array(
-  	'left_field' => 'XXX_id',
-  	'field' => 'XXX_id',
-  );
-  
-  // Join the node table to chado_XXX
-  $data['node']['table']['join']['chado_XXX'] = array(
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );
-  
-  // Join the node table to XXX
-  $data['node']['table']['join']['XXX'] = array(
-  	'left_table' => 'chado_XXX',
-  	'left_field' => 'nid',
-  	'field' => 'nid',
-  );  
-
-	return $data;
-}

+ 0 - 211
tripal_db/views/template.table_defn.views.inc

@@ -1,211 +0,0 @@
-<?php
-
-/*************************************************************************
- * @file: THIS IS A TEMPLATE AND SHOULD NOT BE INCLUDED IN THE MODULE CODE
- *
- *   - Every instance of XXX should be replaced with the name of your table
- *   - If this is a base table (you want a view where every row is a row from this table)
- *     then change $data['XXX']['table'] to $data['XXX']['table']['base'] 
- *     and $data['XXX']['table']['database'] to $data['XXX']['table']['base']['database']
- *   - Relationships between this table and others: YYY is the table you are trying to join to this
- *     one. You want to join a table to this one if this table contains a foreign key to the other
- *     table. If the join between this table and another is through a linking table
- *     (ie: library-XXX/YYY => library_feature-XY => feature-XXX/YYY) then make the join in both
- *     directions (ie: in the file XXX.views.inc and the file YYY.views.inc
- *   - Create a field definition for each field in this table using the example fields already
- *     listed. Match the type of the database field to the field definition listed below.
- *     (ie: for a text/varchar field from the database use plain_text_field below)
- * 
- *  NOTE: Creating the table definition file is not enough. You also need to call the 
- *        retrieve_XXX_views_data() function from ../tripal_db.views.inc:tripal_db_views_data()
- *        by adding the following line:
- *           $data = array_merge($data, retrieve_XXX_views_data());
- *        to the function and including the file directly above the function (blow the function 
- *        header by adding:
- *           require_once('views/XXX.views.inc');
- *
- *  REMOVE THIS COMMENT IN THE COPY!
- */ 
- 
-/**
- *  @file
- *  This file defines the data array for a given chado table. This array
- *  is merged into a larger array containing definitions of all tables associated
- *  with this module in:
- *  @see tripal_db.views.inc --in tripal_db_views_data()
- *
- *  Documentation on views integration can be found at 
- *  http://views2.logrus.com/doc/html/index.html.
- */
-
-/*************************************************************************
- * Purpose: this function returns the portion of the data array 
- *   which describes the XXX table, it's fields and any joins between it and other tables
- * @see tripal_db_views_data() --in tripal_db.views.inc
- *
- * Table: XXX
- * @code
- * XXX-Copy/Paste Table SQL code here-XXX
- * @endcode
- */
- function retrieve_XXX_views_data() {
-  global $db_url;
-  $data = array();
-
-  // if the chado database is not local to the drupal database
-  // then we need to set the database name.  This should always
-  // be 'chado'.
-  if(is_array($db_url) and array_key_exists('chado',$db_url)){
-    $database = 'chado';
-  }
-   
-  //Basic table definition-----------------------------------
-  $data['XXX']['table']['group'] = t('Chado XXX');
-  
-  $data['XXX']['table'] = array(
-    'field' => 'primary_id',
-    'title' => t('Chado XXX'),
-    'help' => t('Enter some user-friendly description of this tables purpose to the user.'),
-  );
-  if($database){
-     $data['XXX']['table']['database'] = $database;
-  }
-
-  
-  //Relationship Definitions---------------------------------
-  //Join: YYY => XXX
-  // Notice that this relationship tells the primary table to show it's fields to the
-  // table referencing it by a foreign key and thus the relationship is from
-  // primary table to table referenceing it (ie: cvterm => feature)
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_field' => 'foreign key in YYY table',
-    'field' => 'primary key in XXX table',
-  );  
-  
-  //Join: XXX => XY => YYY
-  // This relationship should be described in both directions
-  // in the appropriate files (ie: for feature => library 
-  // describe in both feature.views.inc and library.views.inc)
-  $data['XXX']['table']['join']['XY'] = array(
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );  
-  $data['XXX']['table']['join']['YYY'] = array(
-    'left_table' => 'XY',
-    'left_field' => 'matching XXX key in the XY table',
-    'field' => 'primary key in XXX table',
-  );
-  $data['XY']['table']['join']['YYY'] = array(
-    'left_field' => 'primary key in YYY table',
-    'field' => 'matching YYY key in the XY table',
-  );
-   
-  //Table Field Definitions----------------------------------
-      
-  //Field: XXX_id (primary key)
-  $data['XXX']['field_name'] = array(
-    'title' => t('XXX Primary Key'),
-    'help' => t('A unique index for every XXX.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  /*.......................................................
-   * Beginning of Example Field definitions
-   * Remove this section when done
-   */
-
-  //Field: plain_text_field (chado datatype)   
-  $data['XXX']['plain_text_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_string',
-    ),
-    'argument' => array(
-      'handler' => 'views_handler_argument_string',
-    ),
-  );
-
-  //Field: numeric_field (chado datatype)   
-  $data['XXX']['numeric_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_numeric',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_numeric',
-    ),
-  );
-
-  //Field: boolean_field (chado datatype)   
-  $data['XXX']['boolean_field'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_boolean',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_boolean_operator',
-    ),
-  );
-
-  //Field: unix_timestamp (chado datatype)   
-  $data['XXX']['unix_timestamp'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-    'filter' => array(
-      'handler' => 'views_handler_filter_date',
-    ),
-  );
-
-  //Field: human_readable_date (chado datatype)   
-  $data['XXX']['human_readable_date'] = array(
-    'title' => t('Human-Readable Name'),
-    'help' => t('Description of this field.'),
-    'field' => array(
-      'handler' => 'views_handler_field_readble_date',
-      'click sortable' => TRUE,
-     ),
-    'sort' => array(
-      'handler' => 'views_handler_sort_date',
-    ),
-  );
-   
-   /*
-    * End of Example Field definitions
-    */
-    
-  return $data;
-}