Parcourir la source

Merge branch '6.x-tripal_views_int_edit-og' into 6.x-0.4-dev

stephen il y a 13 ans
Parent
commit
42977ff1ad

+ 18 - 0
base/ahah_helper-submit-1231140-12.patch

@@ -0,0 +1,18 @@
+diff --git a/ahah_helper.module b/ahah_helper.module
+index dfd222a..efe3f55 100644
+--- a/ahah_helper.module
++++ b/ahah_helper.module
+@@ -132,6 +132,13 @@ function ahah_helper_generic_submit($form, &$form_state) {
+  */
+ function ahah_helper_real_submit($form, &$form_state) {
+   unset($form_state['storage']);
++  
++  // Call FormAPI's standard submit handler for the form.
++  $form_id = $form['form_id']['#value'];
++  $function = $form_id . '_submit';
++  if (function_exists($function)) {
++    $function($form, $form_state);
++  } 
+ }
+ 
+ /**

+ 24 - 35
base/tripal_core/mviews.php

@@ -133,7 +133,7 @@ function tripal_mviews_action ($op,$mview_id){
       }
       tripal_db_set_active($previous_db);  // now use drupal database
    }
-   return '';
+   drupal_goto("admin/tripal/views/mviews");
 }
 /**
 * Update a Materialized View
@@ -179,7 +179,7 @@ function tripal_mview_report ($mview_id) {
    // create a table with each row containig stats for
    // an individual job in the results set.
 
-   $return_url = url("admin/tripal/tripal_mviews/");
+   $return_url = url("admin/tripal/views/mviews/");
 
    $output .= "<p><a href=\"$return_url\">Return to table of materialized views.</a></p>";
    $output .= "<br />";
@@ -240,9 +240,9 @@ function tripal_mview_report ($mview_id) {
 
    // build the URLs using the url function so we can handle installations where
    // clean URLs are or are not used
-   $update_url = url("admin/tripal/tripal_mviews/action/update/$mview->mview_id");
-   $delete_url = url("admin/tripal/tripal_mviews/action/delete/$mview->mview_id");
-   $edit_url = url("admin/tripal/tripal_mviews/edit/$mview->mview_id");
+   $update_url = url("admin/tripal/views/mviews/action/update/$mview->mview_id");
+   $delete_url = url("admin/tripal/views/mviews/action/delete/$mview->mview_id");
+   $edit_url = url("admin/tripal/views/mviews/edit/$mview->mview_id");
 
    $output .= "<tr><th>Actions</th>".
               "<td> <a href='$update_url'>Update</a>, ".
@@ -259,43 +259,32 @@ function tripal_mview_report ($mview_id) {
 * @ingroup tripal_mviews_api
 */
 function tripal_mviews_report () {
-   $mviews = db_query("SELECT * FROM {tripal_mviews} ORDER BY name");
 
-   // create a table with each row containig stats for
-   // an individual job in the results set.
-   $output .= "<table class=\"border-table\">". 
-              "  <tr>".
-              "    <th nowrap></th>".
-              "    <th>Name</th>".
-              "    <th>Last_Update</th>".
-              "    <th nowrap></th>".
-              "  </tr>";
-   
+   $header = array('','MView Name','Last Update','');
+   $rows = array();
+
+   $mviews = db_query("SELECT * FROM {tripal_mviews} ORDER BY name");  
    while($mview = db_fetch_object($mviews)){
       if($mview->last_update > 0){
          $update = format_date($mview->last_update);
       } else {
          $update = 'Not yet populated';
       }
-	  // build the URLs using the url function so we can handle installations where
-	  // clean URLs are or are not used
-	  $view_url = url("admin/tripal/tripal_mview/$mview->mview_id");
-	  $update_url = url("admin/tripal/tripal_mviews/action/update/$mview->mview_id");
-	  $delete_url = url("admin/tripal/tripal_mviews/action/delete/$mview->mview_id");
-	  // create the row for the table
-      $output .= "  <tr>";
-      $output .= "    <td><a href='$view_url'>View</a>&nbsp".
-                 "        <a href='$update_url'>Update</a></td>".
-	             "    <td>$mview->name</td>".
-                 "    <td>$update</td>".
-                 "    <td><a href='$delete_url'>Delete</a></td>".
-                 "  </tr>";
+      $rows[] = array(
+         l('View',"admin/tripal/views/mviews/report/$mview->mview_id") ." | ".
+            l('Update',"admin/tripal/views/mviews/action/update/$mview->mview_id"),
+         $mview->name,
+         $update,
+         l('Delete',"admin/tripal/views/mviews/action/delete/$mview->mview_id"),
+      );
    }
-   $new_url = url("admin/tripal/tripal_mviews/new");
-   $output .= "</table>";
-   $output .= "<br />";
-   $output .= "<p><a href=\"$new_url\">Create a new materialized view.</a></p>";
-   return $output;
+   $rows[] = array(
+      'data' => array( 
+         array('data' => l('Create a new materialized view.',"admin/tripal/views/mviews/new"), 
+               'colspan' => 4),
+         )
+   );
+   return theme('table', $header, $rows);
 }
 /**
 *
@@ -411,7 +400,7 @@ function tripal_mviews_form(&$form_state = NULL,$mview_id = NULL){
      '#executes_submit_callback' => TRUE,
    );
 
-   $form['#redirect'] = 'admin/tripal/tripal_mviews';
+   $form['#redirect'] = 'admin/tripal/views/mviews';
    return $form;
 }
 /**

+ 3 - 0
base/tripal_core/tripal_core.info

@@ -5,3 +5,6 @@ core = 6.x
 project = tripal_core
 package = Tripal
 version = 6.x-0.3.1b
+
+dependencies[] = views
+dependencies[] = ahah_helper

+ 219 - 25
base/tripal_core/tripal_core.install

@@ -49,10 +49,62 @@ function tripal_core_uninstall(){
 * @ingroup tripal_core
 */
 function tripal_core_get_schemas (){  
-  $schema = array();
+   $schema = array();
 
+   // get all the various schema parts and join them together
+   $temp = tripal_core_jobs_schema();
+   foreach ($temp as $table => $arr){ 
+      $schema[$table] = $arr; 
+   }
+   $temp = tripal_core_mviews_schema();
+   foreach ($temp as $table => $arr){ 
+      $schema[$table] = $arr; 
+   }
+   $temp = tripal_core_views_schema();
+   foreach ($temp as $table => $arr){ 
+      $schema[$table] = $arr; 
+   } 
 
-  $schema['tripal_jobs'] = array(
+	return $schema;
+}
+/************************************************************************
+* 
+*
+* @ingroup tripal_core
+*/
+function tripal_core_mviews_schema(){
+   $schema = array();
+   $schema['tripal_mviews'] = array(
+      'fields' => array(
+         'mview_id'      => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
+         'name'          => array('type' => 'varchar','length' => 255, 'not null' => TRUE),
+         'modulename'    => array('type' => 'varchar','length' => 50, 'not null' => TRUE, 'description' => 'The module name that provides the callback for this job'),
+         'mv_table'      => array('type' => 'varchar','length' => 128, 'not null' => TRUE),
+         'mv_specs'      => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE),
+         'indexed'       => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE),
+         'query'         => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE),
+         'special_index' => array('type' => 'text', 'size' => 'normal', 'not null' => FALSE),
+         'last_update'   => array('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer time'),
+      ),
+      'indexes' => array(
+         'mview_id' => array('mview_id')
+      ),
+      'unique keys' => array(
+         'mv_table' => array('mv_table'),
+         'mv_name' => array('name'),
+      ),
+      'primary key' => array('mview_id'),
+  );
+  return $schema;
+}
+/************************************************************************
+* 
+*
+* @ingroup tripal_core
+*/
+function tripal_core_jobs_schema(){
+   $schema = array();
+   $schema['tripal_jobs'] = array(
       'fields' => array(
          'job_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
          'uid' => array ('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'description' => 'The Drupal userid of the submitee'),
@@ -76,30 +128,172 @@ function tripal_core_get_schemas (){
          'job_name' => array('job_name')
       ),
       'primary key' => array('job_id'),
-  );
+   );
+   return $schema;
+}
+/************************************************************************
+* 
+*
+* @ingroup tripal_core
+*/
+function tripal_core_views_schema(){
+   $schema = array();
+	$schema['tripal_views'] = array(
+		'description' => 'contains the setupes, their materialized view id and base table name that was used.',
+		'fields' => array(
+			'setup_id' => array(
+				'description' => 'the id of the setup',
+				'type' => 'serial',
+				'unsigned' => TRUE,
+				'not null' => TRUE,
+			),
+			'mview_id' => array(
+				'description' => 'the materialized view used for this setup',
+				'type' => 'int',
+				'unsigned' => TRUE,
+			),
+			'table_name' => array(
+				'description' => 'the base table name to be used when using this setup. Use this field when not using a materialized view',
+				'type' => 'varchar',
+				'length' => 255,
+				'not null' => TRUE,
+				'default' => '',
+			),
+			'name' => array(
+				'description' => 'Human readable name of this setup',
+				'type' => 'varchar',
+				'length' => 255,
+				'not null' => TRUE,
+				'default' => '',
+			),
+			'comment' => array(
+				'description' => 'add notes about this views setup',
+				'type' => 'text',
+				'size' => 'normal',
+				'not null' => FALSE,
+				'default' => '',
+			),
+		),
+		'unique_keys' => array(
+			'setup_id' => array('setup_id'),
+		),
+		'primary key' => array('setup_id'),
+	);
 
-  $schema['tripal_mviews'] = array(
-      'fields' => array(
-         'mview_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
-         'name' => array('type' => 'varchar','length' => 255, 'not null' => TRUE),
-         'modulename' => array('type' => 'varchar','length' => 50, 'not null' => TRUE, 'description' => 'The module name that provides the callback for this job'),
-         'mv_table' => array('type' => 'varchar','length' => 128, 'not null' => TRUE),
-         'mv_specs' => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE),
-         'indexed' => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE),
-         'query' => array('type' => 'text', 'size' => 'normal', 'not null' => TRUE),
-         'special_index' => array('type' => 'text', 'size' => 'normal', 'not null' => FALSE),
-         'last_update' => array ('type' => 'int', 'not null' => FALSE, 'description' => 'UNIX integer time'),
-      ),
-      'indexes' => array(
-         'mview_id' => array('mview_id')
-      ),
-      'unique keys' => array(
-         'mv_table' => array('mv_table'),
-         'mv_name' => array('name'),
-      ),
-      'primary key' => array('mview_id'),
-  );
+	$schema['tripal_views_join'] = array(
+		'description' => 'coordinate the joining of tables',
+		'fields' => array(
+		  'view_join_id' => array(
+				'description' => 'the id of the join',
+				'type' => 'serial',
+				'unsigned' => TRUE,
+				'not null' => TRUE,
+		  ),
+			'setup_id' => array(
+				'description' => 'setup id from tripal_views table',
+				'type' => 'int',
+				'unsigned' => TRUE,
+				'not null'=> TRUE,
+			),
+			'base_table' => array(
+			   'description' => 'the name of the base table',
+				'type' => 'varchar',
+				'length' => '255',
+				'not null' => TRUE,
+				'default' => '',
+	      ),
+			'base_field' => array(
+				'description' => 'the name of the base table column that will be joined',
+				'type' => 'varchar',
+				'length' => '255',
+				'not null' => TRUE,
+				'default' => '',
+			),
+			'left_table' => array(
+				'description' => 'the table on which to perform a left join',
+				'type' => 'varchar',
+				'length' => '255',
+				'not null' => TRUE,
+				'default' => '',
+			),
+			'left_field' => array(
+				'description' => 'the column on which to perform a left join',
+				'type' => 'varchar',
+				'length' => '255',
+				'not null' => TRUE,
+				'default' => '',
+	      ),
+		),
+		'unique_keys' => array(
+			'setup_id' => array('view_join_id'),
+		),
+		'primary key' => array('view_join_id'),
+	);
 
-  return $schema;
+	$schema['tripal_views_handlers'] = array(
+		'description' => 'in formation for views: column and views handler name',
+		'fields' => array(
+			'handler_id' => array(
+				'description' => 'the id of the handler',
+				'type' => 'serial',
+			   'unsigned' => TRUE,
+			   'not null' => TRUE,
+	      ),
+			'setup_id' => array(
+				'description' => 'setup id from the tripal_views table',
+				'type' => 'int',
+				'unsigned' => TRUE,
+				'not null'=> TRUE,
+			),
+			'column_name' => array(
+				'description' => '',
+				'type' => 'varchar',
+				'length' => '255',
+				'not null' => TRUE,
+				'default' => '',
+			),
+			'handler_type' => array(
+				'description' => 'identifies the type of hander (e.g. field, filter, sort, argument, relationship, etc.)',
+				'type' => 'varchar',
+				'length' => '50',
+				'not null' => TRUE,
+				'default' => '',
+			),
+			'handler_name' => array(
+				'description' => 'the name of the handler',
+				'type' => 'varchar',
+				'length' => '255',
+				'not null' => TRUE,
+				'default' => '',
+			),
+			'arguments' => array(
+				'description' => 'arguments that may get passed to the handler',
+				'type' => 'text',
+				'size' => 'normal',
+				'not null' => FALSE,
+				'default' => '',
+			),
+		),
+		'unique_keys' => array(
+		   'setup_id' => array('handler_id'),
+	   ),
+		'primary key' => array('handler_id'),
+	);
+
+   return $schema;
 }
+/************************************************************************
+* 
+*
+* @ingroup tripal_core
+*/
+function tripal_core_update_6000(){
+   $schema = tripal_core_views_schema();
+   $ret = array();
+   foreach ($schema as $name => $table) {
+      db_create_table($ret, $name, $table);
+   }   
+   return $ret;
+}
+
 ?>

+ 106 - 47
base/tripal_core/tripal_core.module

@@ -4,8 +4,10 @@ require_once "jobs.php";
 require_once "mviews.php";
 require_once "cvterms.php";
 require_once "chado_install.php";
+require_once "tripal_views_integration.inc";
 
 require_once "tripal_core.api.inc";
+require_once "tripal_core.views.inc";
 
 /**
  * @defgroup tripal_modules Tripal Modules
@@ -29,7 +31,7 @@ function tripal_core_init(){
    // variable is always set.  In the case where a view needs to query the
    // chado schema when it is local to the Drupal database.  Otherwise the
    // search_path isn't set.  When tripal_db_set_active is called it
-   // automatically sets the serach path if chado is local to the 
+   // automatically sets the serach path if chado is local to the
    // Drupal database
    $previous = tripal_db_set_active('chado');
    tripal_db_set_active($previous);
@@ -41,11 +43,11 @@ function tripal_core_init(){
       if(!db_fetch_object(db_query("SELECT * FROM {cv} WHERE name = 'tripal'"))){
          $results = db_query("INSERT INTO {cv} (name,definition) ".
     	                     "VALUES ('tripal','Terms used by Tripal for modules to manage data such as that stored in property tables like featureprop, analysisprop, etc')");
-      } 
+      }
       if(!db_fetch_object(db_query("SELECT * FROM {db} WHERE name = 'tripal'"))){
-         $results = db_query("INSERT INTO {db} (name,description) ". 
+         $results = db_query("INSERT INTO {db} (name,description) ".
 	                        "VALUES ('tripal','Used as a database placeholder for tripal defined objects such as tripal cvterms')");
-      }  
+      }
       tripal_db_set_active($previous_db);  // now use drupal database
    }
 
@@ -54,8 +56,8 @@ function tripal_core_init(){
    $theme_dir = drupal_get_path('theme', 'tripal');
    $clean_urls  = variable_get('clean_url', 0);
    drupal_add_js("
-      var baseurl = '$base_url'; 
-      var themedir = '$theme_dir'; 
+      var baseurl = '$base_url';
+      var themedir = '$theme_dir';
       var isClean = $clean_urls;",'inline');
 
    // make sure the date time settings are the way Tripal will insert them
@@ -85,7 +87,23 @@ function tripal_core_menu() {
       'file' => 'system.admin.inc',
       'file path' => drupal_get_path('module', 'system'),
    );
+   $items['tripal_toggle_box_menu/%/%/%'] = array(
+     'title' => t('Toggle Box'),
+     'page callback' => 'tripal_toggle_box_menu',
+     'page arguments' => array(1,2,3),
+     'access arguments' => array('access administration pages'),
+     'type' => MENU_CALLBACK | MENU_LINKS_TO_PARENT
+   );
+   $items['admin/tripal/chado_1_11_install'] = array(
+     'title' => 'Install Chado v1.11',
+     'description' => 'Installs Chado version 1.11 inside the current Drupal database',
+     'page callback' => 'drupal_get_form',
+     'page arguments' => array('tripal_core_chado_v1_11_load_form'),
+     'access arguments' => array('access administration pages'),
+     'type' => MENU_NORMAL_ITEM,
+   );
 
+   // Jobs Management
    $items['admin/tripal/tripal_jobs'] = array(
      'title' => 'Jobs',
      'description' => 'Jobs managed by Tripal',
@@ -117,66 +135,102 @@ function tripal_core_menu() {
      'access arguments' => array('access administration pages'),
      'type' => MENU_CALLBACK,
    );
-   $items['admin/tripal/tripal_mview/%'] = array(
-     'title' => 'Materialized View',
+ 
+
+   // Views Integration
+   $items['admin/tripal/views'] = array(
+     'title' => t('Views'),
+     'description' => 'Management of Materialized Views & Integration with Drupal Views',
+     'page callback' => 'tripal_core_views_description_page',
+     'access arguments' => array('administer site configuration'),
+     'type' => MENU_NORMAL_ITEM,
+   );
+   $items['admin/tripal/views/mviews'] = array(
+     'title' => 'MViews',
      'description' => 'Materialized views are used to improve speed of large or complex queries.',
-     'page callback' => 'tripal_mview_report',
-     'page arguments' => array(3),
+     'page callback' => 'tripal_mviews_report',
      'access arguments' => array('access administration pages'),
      'type' => MENU_NORMAL_ITEM,
    );
-   $items['admin/tripal/tripal_mviews'] = array(
-     'title' => 'Materialized Views',
+   $items['admin/tripal/views/mviews/report/%'] = array(
+     'title' => 'Materialized View',
      'description' => 'Materialized views are used to improve speed of large or complex queries.',
-     'page callback' => 'tripal_mviews_report',
+     'page callback' => 'tripal_mview_report',
+     'page arguments' => array(5),
      'access arguments' => array('access administration pages'),
      'type' => MENU_NORMAL_ITEM,
    );
-   $items['admin/tripal/tripal_mviews/new'] = array(
-     'title' => 'Create View',
+   $items['admin/tripal/views/mviews/new'] = array(
+     'title' => 'Create MView',
      'description' => 'Materialized views are used to improve speed of large or complex queries.',
      'page callback' => 'drupal_get_form',
      'page arguments' => array('tripal_mviews_form'),
      'access arguments' => array('access administration pages'),
-     'type' => MENU_NORMAL_ITEM,
+     'type' => MENU_CALLBACK,
    );
-   $items['admin/tripal/tripal_mviews/edit/%'] = array(
-     'title' => 'Edit View',
+   $items['admin/tripal/views/mviews/edit/%'] = array(
+     'title' => 'Edit MView',
      'page callback' => 'drupal_get_form',
-     'page arguments' => array('tripal_mviews_form',4),
+     'page arguments' => array('tripal_mviews_form',5),
      'access arguments' => array('access administration pages'),
      'type' => MENU_NORMAL_ITEM,
    );
-   $items['admin/tripal/tripal_mviews/action/%/%'] = array(
-     'title' => 'Create View',
+   $items['admin/tripal/views/mviews/action/%/%'] = array(
+     'title' => 'Create MView',
      'description' => 'Materialized views are used to improve speed of large or complex queries.',
      'page callback' => 'tripal_mviews_action',
-     'page arguments' => array(4,5),
+     'page arguments' => array(5,6),
      'access arguments' => array('access administration pages'),
      'type' => MENU_CALLBACK,
    );
+ 	$items['admin/tripal/views/integration'] = array(
+     'title' => t('Views Integration'),
+     'description' => t('Allows you to select existing materialized views and provide details for integration with Drupal Views.'),
+     'page callback' => 'tripal_core_views_integration_setup_list',
+     'access arguments' => array('manage tripal_views_integration'),
+     'type' => MENU_NORMAL_ITEM,
+ 	);
 
-   $items['tripal_toggle_box_menu/%/%/%'] = array(
-     'title' => t('Libraries'),
-     'page callback' => 'tripal_toggle_box_menu',
-     'page arguments' => array(1,2,3),
-     'access arguments' => array('access administration pages'),
-     'type' => MENU_CALLBACK | MENU_LINKS_TO_PARENT 
-   );
-   $items['admin/tripal/chado_1_11_install'] = array(
-     'title' => 'Install Chado v1.11',
-     'description' => 'Installs Chado version 1.11 inside the current Drupal database',
+
+	$items['admin/tripal/views/integration/new'] = array(
+     'title' => 'Integrate Views',
      'page callback' => 'drupal_get_form',
-     'page arguments' => array('tripal_core_chado_v1_11_load_form'),
-     'access arguments' => array('access administration pages'),
-     'type' => MENU_NORMAL_ITEM,
-   );
+     'page arguments' => array('tripal_core_views_integration_form'),
+     'access arguments' => array('manage tripal_views_integration'), //TODO: figure out the proper permissions arguments
+     'type' => MENU_CALLBACK,
+	);
+	
+	$items['admin/tripal/views/integration/edit/%'] = array(
+     'title' => 'Edit Views Integration',
+     'page callback' => 'drupal_get_form',
+     'page arguments' => array('tripal_core_views_integration_form',5),
+     'access arguments' => array('manage tripal_views_integration'), //TODO: figure out the proper permissions arguments
+     'type' => MENU_CALLBACK,
+	);
 
+	$items['admin/tripal/views/integration/delete/%'] = array(
+     'title' => 'Delete Views Integration',
+     'page callback' => 'tripal_core_views_integration_delete',
+     'page arguments' => array(5),
+     'access arguments' => array('manage tripal_views_integration'), //TODO: figure out the proper permissions arguments
+     'type' => MENU_CALLBACK,
+	);
   return $items;
 }
 
 
-
+/**
+ *  Set the permission types that the chado module uses.  Essentially we
+ *  want permissionis that protect creation, editing and deleting of chado
+ *  data objects
+ *
+ * @ingroup tripal_core
+ */
+function tripal_core_perm(){
+   return array(
+      'manage tripal_views_integration',
+   );
+}
 /**
  *
  *
@@ -184,7 +238,7 @@ function tripal_core_menu() {
  *   The name of the database to switch to as indicated in settings.php
  *   Should be either default or chado
  *
- * @return 
+ * @return
  *   The name of the previously set database
  *
  * @ingroup tripal_chado_api
@@ -192,12 +246,12 @@ function tripal_core_menu() {
 function tripal_core_is_chado_installed(){
    global $db_url, $db_type;
 
-   // first check if chado is in the db_url of the 
+   // first check if chado is in the db_url of the
    // settings.php file
-   if(is_array($db_url)){ 
+   if(is_array($db_url)){
       if(isset($db_url['chado'])){
          return true;
-      } 
+      }
    }
    // check to make sure the chado schema exists
    $sql = "select nspname from pg_catalog.pg_namespace where nspname = 'chado'";
@@ -215,7 +269,7 @@ function tripal_core_is_chado_installed(){
  *  views integration code is
  *
  * @ingroup tripal_core
- */ 
+ */
 function tripal_core_views_api() {
    return array(
       'api' => 2.0,
@@ -228,11 +282,15 @@ function tripal_core_views_api() {
  * @ingroup tripal_core
  */
 function tripal_core_theme () {
-   return array(      
+   return array(
       'tripal_core_job_view' => array (
          'arguments' => array('job_id'=> null),
          'template' => 'tripal_core_job_view',
       ),
+	  'tripal_core_views_integration_form' => array(
+         'arguments' => array('form' => NULL),
+         'template'  => 'tripal_views_integration_fields_form',
+	   ),
    );
 }
 /**
@@ -244,17 +302,18 @@ function tripal_core_job_describe_args($callback,$args){
    if($callback == 'tripal_update_mview'){
       // get this mview details
       $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d ";
-      $mview = db_fetch_object(db_query($sql,$args[0]));     
+      $mview = db_fetch_object(db_query($sql,$args[0]));
       $new_args['View Name'] = $mview->name;
    }
    return $new_args;
 }
 
 // this is just a wrapper for backwards compatibility with a naming mistake.
-// it can go away in the future as it only is useful for jobs created by v0.3b 
-function tripal_core_load_gff3($gff_file, $organism_id,$analysis_id,$add_only =0, 
+// it can go away in the future as it only is useful for jobs created by v0.3b
+function tripal_core_load_gff3($gff_file, $organism_id,$analysis_id,$add_only =0,
    $update = 0, $refresh = 0, $remove = 0, $job = NULL)
 {
-   tripal_feature_load_gff3($gff_file, $organism_id,$analysis_id,$add_only, 
+   tripal_feature_load_gff3($gff_file, $organism_id,$analysis_id,$add_only,
       $update, $refresh, $remove, $job);
 }
+

+ 163 - 1
base/tripal_core/tripal_core.views.inc

@@ -357,4 +357,166 @@ function tripal_core_add_node_ids_to_view (&$view) {
 	} //end of case for stock NID
 		
 	return $view;
-}
+}
+/**
+ *
+ * @ingroup tripal_core
+ */
+
+function tripal_core_views_data(){   
+
+    $tvi_query = db_query('SELECT * FROM {tripal_views}');
+
+    while($tvi_row = db_fetch_object($tvi_query)){
+
+      // ids we'll use for queries
+      $setup_id = $tvi_row->setup_id;
+      $mview_id = $tvi_row->mview_id;
+
+      // holds the base table name and fields
+      $base_table = '';
+      $base_fields = array();
+      $type_prefix = '';
+
+      // populate the base table name and fields.  If an $mview_id is given
+      // the get the materialized view info, otherwise get the Chado table info
+      if($mview_id){
+         $type_prefix = 'MView';
+         // get the base table name from the materialized view
+         $sql = "SELECT name, mv_specs FROM {tripal_mviews} WHERE mview_id = %d";
+         $mview_table = db_fetch_object(db_query($sql,$mview_id));
+         $base_table = $mview_table->name;
+
+         // get the columns in this materialized view.  They are separated by commas
+         // where the first word is the column name and the rest is the type
+         $columns = explode(",",$mview_table->mv_specs);
+         foreach ($columns as $column){
+            $column = trim($column);  // trim trailing and leading spaces
+            preg_match("/^(.*?)\ (.*?)$/",$column,$matches);
+            $column_name = $matches[1];
+            $column_type = $matches[2];
+            $base_fields[] = $column_name;
+         }
+      }
+      else {
+         $type_prefix = 'Chado Table';
+         // TODO: get the chado table info and populate these variables
+         //  1) $base_table
+         //  2) $base_fields (an array of just the table field names)
+      }
+
+      // Setup the base table info in the data array
+      $data[$base_table]['table']['group'] = t($tvi_row->name);
+      $data[$base_table]['table']['base'] = array(
+        'group' => "$type_prefix: $tvi_row->name",
+        'title' => "$type_prefix: $tvi_row->name",
+        'help'  => $tvi_row->comment,
+      );
+
+      // first add the fields
+      foreach ($base_fields as $base_field){
+        $data[$base_table][$base_field] = array(
+           'title' => $base_field,
+           'help' => t("The $base_field from the $base_table table (added by Tripal Views Integration)"),
+           'field' => array(
+              'click sortable' => TRUE,
+           ),
+        );
+
+        // now add the handlers
+        $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id = %d AND column_name = '%s'";
+        $handlers = db_query($sql,$setup_id,$base_field);
+        while($handler = db_fetch_object($handlers)){
+           $data[$base_table][$base_field][$handler->handler_type]['handler'] = $handler->handler_name;
+        };
+    }
+
+     // now add the joins
+     $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
+     $joins = db_query($sql,$setup_id);
+     while($join = db_fetch_object($joins)){               
+        $left_table = $join->left_table;
+        $left_field = $join->left_field;
+        $base_field = $join->base_field;  
+      
+        // add join entry
+        $data[$base_table]['table']['join'][$left_table] = array(
+          'left_field' => $left_field,
+          'field' => $base_field,
+        );
+
+        // check to see if the join table is one that correlates with Drupal nodes
+        // if so, there will be a chado_<table_name> table in the Drupal database
+        // if there is, then we need to add the linking join information
+        $sql = "SELECT tablename FROM pg_tables WHERE tablename = 'chado_$left_table'";
+        if(db_fetch_object(db_query($sql))){
+
+           // join the mview to the linker table
+           $data[$base_table]['table']['join']["chado_$left_table"] = array(
+             'left_field' => $left_field,
+             'field' => $base_field,
+           );
+        }
+      }
+    }
+    return $data;
+}
+/**
+ *
+ * @ingroup tripal_core
+ */
+function tripal_core_views_data_alter(&$data) {
+    $tvi_query = db_query('SELECT * FROM {tripal_views}');
+
+    // iterate through the views that we manage
+    while($tvi_row = db_fetch_object($tvi_query)){
+
+      //ids we'll use for queries
+      $mview_id = $tvi_row->mview_id;
+      $setup_id = $tvi_row->setup_id;
+
+      // iterate through the columns and alter the existing data array for
+      // joins to other tables
+      $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
+      $joins = db_query($sql,$setup_id);
+      while($join = db_fetch_object($joins)){                       
+        $left_table = $join->left_table;
+        $left_field = $join->left_field;
+        $base_field = $join->base_field;  
+        $base_table = $join->base_table;    
+
+        // add the recipricol join entries for each column
+        if(array_key_exists($left_table,$data)){
+           $data[$left_table]['table']['join'][$base_table] = array(
+             'left_field' => $base_field,
+             'field' => $left_field,
+           );
+        }
+
+        // check to see if this table is one that correlates with Drupal nodes
+        // if so, there will be a chado_<table_name> table in the Drupal database
+        // if there is, then we need to add the linking join information.  We did
+        // this step in the hook_views_data function above, but now we need 
+        // to add the reciprical joins
+        $sql = "SELECT tablename FROM pg_tables WHERE tablename = '%s'";
+        if(db_fetch_object(db_query($sql,"chado_$left_table"))){
+
+           // join the linker table to the mview
+           if(array_key_exists("chado_$left_table",$data)){
+              $data["chado_$left_table"]['table']['join'][$base_table] = array(
+                'left_field' => $base_field,
+                'field' => $left_field,
+              );
+
+              // Join the node table to the view by way of the chado linker table
+              $data['node']['table']['join'][$base_table] = array(
+              	'left_table' => "chado_$left_table",
+              	'left_field' => 'nid',
+              	'field' => 'nid',
+              );           
+           }
+        }
+      }
+    }
+    return $data;
+}

+ 729 - 0
base/tripal_core/tripal_views_integration.inc

@@ -0,0 +1,729 @@
+<?php
+
+/**
+ * Purpose: Provide Guidance to new Tripal Admin
+ *
+ * @return
+ *   HTML Formatted text
+ *
+ * @ingroup tripal_views_integration
+ */
+function tripal_core_views_description_page() {
+
+  $text .= '<h3>Tripal Views Quick Links:</h3>';
+  $text .= "<ul>
+             <li><a href=\"".url("admin/tripal/views/mviews") . "\">List of Materialized Views (MViews)</a></li>
+             <li><a href=\"".url("admin/tripal/views/mviews/new") . "\">Create a new MViews</a></li>
+             <li><a href=\"".url("admin/tripal/views/integration/mviews") . "\">List of integrated MViews</a></li>
+             <li><a href=\"".url("admin/tripal/views/integration/mviews/new"). "\">Integrate a MView</a></li>
+             <li><a href=\"".url("admin/tripal/views/integration/chado"). "\">List of integrated Chado tables</a></li>
+             <li><a href=\"".url("admin/tripal/views/integration/chado/new"). "\">Integrate a Chado tables</a></li>
+           </ul>";
+
+  $text .= '<h3>Views Integartion Description:</h3>';
+  $text .= '<p>Tripal Views provides an interface for integrating <a href="http://drupal.org/project/views">Drupal Views</a>
+            with Tripal materialized views.  This will allow site administrators to create custom queries for the materialized views
+            and in turn provide custom content pages, custom blocks and custom search forms. The forms allow a site administrator
+            to select a materialized view and associate other Chado tables on which the view can join.  Usage of this module requires
+            a good understanding of foreign-key relationships in Chado.
+            </p>';
+
+  $text .= '<h3>Setup Instructions:</h3>';
+  $text .= '<p>After installation of the Tripal core module.  The following tasks should be performed
+            <ol>
+              <li><b>Set Permissions</b>: To allow access to site administrators for this module, simply
+               <a href="'.url('admin/user/permissions').'">assign permissions</a> to the appropriate user roles for the
+               permission type "manage tripal_views_integration". </li>
+            </ol>
+            </p>';
+  $text .= '<h3>Usage Instructions:</h3>';
+  $text .= "<p>To use Tripal Views integration follow these steps:
+            <ol>
+               <li><b>Identify or create a materialized view:</b> Using the <a href=\"".url("admin/tripal/views/mviews") . "\">
+                 Tripal materialized View</a> interface, identify the view you would like to integrate or create a new one.</li>
+               <li><b>Setup the Views Integration</b>: Navigate to the <a href=\"".url("admin/tripal/views/integration/mviews/new") . "\">
+                 Tripal views integration setup page</a> to integrate the selected materialized view.  Provide a  user friendly name
+                 and description to help you remember the purpose for integrating the view.  Next, select the view you want to integrate
+                 from the provided select box.  If your materialized view has fields that can join with other Chado tables, you may
+                 provide those relationships in the provided form.  Finally, if your fields require a special handler for display, you
+                 may select it from the drop down provided</li>
+               <li><b>Create custom pages/block/search form</b>:  After saving setup information from step 2 above, you will be redirected to the
+                 Drupal Views interface</a> where you can create a custom page, block or search form.</li>
+               <li><b>Review your integrated views</b>:  A page providing a
+                 <a href=\"".url("admin/tripal/views/integration/mviews/list") . "\">list of all integrated views</a> is provided. You may
+                 view this page to see all integrated views, but also to remove any unwanted integrations.</li>
+            </ol>
+         
+            </p>";
+  return $text;
+}
+/**
+ *
+ * @ingroup tripal_views_integration
+ */
+function tripal_core_views_integration_setup_list(){
+
+   $header = array('', 'Drupal Views Type Name', 'Table Name', 'Is Mview', 'Comment','');
+   $rows = array();
+
+   // get the list of materialized views
+   $tviews = db_query('SELECT * FROM {tripal_views}');
+   while($tview = db_fetch_object($tviews)){
+      if($tview->mview_id){
+         // get the materialized view
+         $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = %d";
+         $mview = db_fetch_object(db_query($sql,$tview->mview_id));
+         $rows[] = array(
+            l('Edit',"admin/tripal/views/integration/edit/".$tview->setup_id) ,
+            $tview->name, 
+            $mview->mv_table, 
+            'Yes', 
+            $tview->comment,
+            l('Delete',"admin/tripal/views/integration/delete/".$tview->setup_id),
+         );
+      } else {
+         // TODO: customize for Chado tables
+      }
+   }
+   $rows[] = array(
+      'data' => array( 
+         array('data' => l('Add a new entry',"admin/tripal/views/integration/new") . " | " .
+                         l("Create View",'admin/build/views/add'), 
+               'colspan' => 6),
+         )
+   );
+   return theme('table', $header, $rows);
+}
+
+/**
+ *
+ * @ingroup tripal_views_integration
+ */
+function tripal_core_views_integration_delete($setup_id){
+  db_query("DELETE FROM {tripal_views} WHERE setup_id = %d",$setup_id);
+  db_query("DELETE FROM {tripal_views_handlers} WHERE setup_id = %d",$setup_id);
+  db_query("DELETE FROM {tripal_views_join} WHERE setup_id = %d",$setup_id);
+  drupal_set_message("Record Deleted");
+  drupal_goto('admin/tripal/views/integration');
+}
+/**
+ *
+ * @ingroup tripal_views_integration
+ */
+function tripal_core_views_integration_form(&$form_state, $setup_id = NULL){
+  
+   $form = array();
+   $data = array();
+   $form['#cache'] = TRUE;
+
+   // ahah_helper requires us to register the form with it's module
+   ahah_helper_register($form, $form_state);
+
+   // if a setup_id is provided then we want to get the form defaults
+   $setup_obj = array();
+   if(isset($setup_id)){
+      // get the deafult setup values
+      $sql = "SELECT * FROM {tripal_views} WHERE setup_id = %d";
+      $setup_obj = db_fetch_object(db_query($sql,$setup_id));
+      $mview_id = $setup_obj->mview_id;
+      $table_name = $setup_obj->table_name;
+      $form_state['storage']['mview_id'] = $mview_id;
+
+      // get the default join settings and handlers
+      $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
+      $query = db_query($sql,$setup_id);
+      $default_joins = array();
+      while ($join = db_fetch_object($query)){
+         $default_joins[$join->base_field]['left_table'] = $join->left_table;
+         $default_joins[$join->base_field]['left_field'] = $join->left_field;
+      }
+      // get the default handlers
+      $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id = %d";
+      $query = db_query($sql,$setup_id);
+      $default_handlers = array();
+      while ($handler = db_fetch_object($query)){
+         $default_handlers[$handler->column_name][$handler->handler_type]['handler_name'] = $handler->handler_name;
+         $default_handlers[$handler->column_name][$handler->handler_type]['arguments'] = $handler->arguments;
+      }
+      // add in the setup_id for the form so we know this is an update not an insert
+      $form['setup_id'] = array(
+         '#type' => 'hidden',
+         '#value' => $setup_id,
+      );    
+   }
+
+  // add a fieldset for the MView & Chado table selectors
+  $form['base_table_type'] = array(
+     '#type' => 'fieldset',
+     '#title' => 'Base Table',
+     '#description' => 'Please select either a materialized view or a Chado table for integration with '.
+                       'Drupal Views.  In Drupal Views terminology, the selected table becomes the "base table". '.
+                       'After you select a table from either list, the fields from that table will appear below '.
+                       'and you can specify other tables to join with and handlers.',
+   );
+
+
+  // build the form element that lists the materialized views
+  $query = db_query("SELECT mview_id,name FROM {tripal_mviews} ORDER BY name");
+  $mview_tables = array();
+  $mview_tables['0'] = 'Select';
+  while ($mview = db_fetch_object($query)){
+    $mview_tables[$mview->mview_id] = $mview->name;
+  }
+  $form['base_table_type']['mview_id'] = array(
+    '#title' => t('Materialized View'),
+    '#type' => 'select',
+    '#options' => $mview_tables,
+    '#description' => 'Which materialized view to use.',
+    '#default_value' => $setup_obj->mview_id,
+    '#ahah' => array(
+       'path' => ahah_helper_path(array('view_setup_table')),
+       'wrapper' => 'table-rows-div',
+       'effect' => 'fade',
+       'event' => 'change',
+       'method' => 'replace',
+    ),
+  );
+
+  // build the form element for the Chado tables
+  $chado_tables = tripal_core_get_chado_tables();
+  $chado_tables = array_merge(array('Select',), $chado_tables);
+  $form['base_table_type']['table_name'] = array(
+    '#title' => t('Chado Table'),
+    '#type' => 'select',
+    '#options' => $chado_tables,
+    '#description' => 'Which Chado table to use.',
+    '#default_value' => $setup_obj->table_name,
+    '#ahah' => array(
+       'path' => ahah_helper_path(array('view_setup_table')),
+       'wrapper' => 'table-rows-div',
+       'effect' => 'fade',
+       'event' => 'change',
+       'method' => 'replace',
+    ),
+  );
+
+  $form['views_type'] = array(
+     '#type' => 'fieldset',
+     '#title' => 'View Type',
+     '#description' => 'Here you can provide the "type" of View you want to create.',
+   );
+  
+  // field for the name of the
+  $form['views_type']['row_name'] = array(
+    '#title' => t('View Type Name'),
+    '#type' => 'textfield',
+    '#default_value' => $setup_obj->name,
+    '#size' => 60,
+    '#maxlength' => 128,
+    '#description' => 'Provide the view type name.  This is the name that will appear in '.
+                      'the Drupal Views interface when adding a new view.  The view type name '.
+                      'must be unique.  You may use the a materialized view or Chado table '.
+                      'multiple times as the base table for different type names.  This allows '.
+                      'for differetn handlers to be '.
+                      'applied to the same table in different ways.',
+    '#required' => TRUE,   
+  );
+  
+  if(isset($setup_id)){
+    $form['row_name']['#attributes'] = array('readonly' => 'readonly');
+  }
+
+  $form['views_type']['row_description'] = array(
+    '#title' => t('Comment'),
+    '#type' => 'textarea',
+    '#description' => '(Optional). Provide any details regarding this setup you would like. This '.
+                      'description will appear when selecting a type for a new Drupal View',
+    '#required' => FALSE,
+  );
+
+  // we need a div block where the table fields will get put when the
+  // AHAH callback is made
+  $form['view_setup_table'] = array(
+     '#type' => 'item',
+       '#prefix' => '<div id="table-rows-div">',
+       '#suffix' => '</div>',
+  );
+
+
+  // add the fieldset for the table fields, but only if the $mview_id or $table_name
+  // is set. The only times these values are set is if we're editing an existing
+  // record or if the AHAH callback is being made.
+  if ($form_state['storage']['mview_id'] or $form_state['storage']['table_name']){
+    $mview_id = $form_state['storage']['mview_id'];
+    $table_name = $form_state['storage']['table_name'];
+    $form['view_setup_table'] = array(
+     '#type' => 'fieldset',
+     '#title' => 'Join Selection',
+     '#prefix' => '<div id="fieldset-table-rows-wrapper">',
+     '#suffix' => '</div>',
+    );
+
+    // get the columns in this materialized view.  They are separated by commas
+    // where the first word is the column name and the rest is the type
+    if($mview_id){
+       $sql = "SELECT mv_specs FROM {tripal_mviews} WHERE mview_id = %d";
+       $mview = db_fetch_object(db_query($sql,$mview_id));
+       $columns = explode(",",$mview->mv_specs);
+    } else {
+       // TODO: get chado table columns and add them to the $columns array
+    }
+
+    $i=1;
+    $form['view_setup_table']["instructions"] = array(
+         '#type' => 'markup',
+         '#value' => "Select an optional table to which the fields of the ".
+                     "materialized view can join.  If a field does not need to ".
+                     "join you may leave the selection blank.",
+    );
+    $data['field_types'] = array();
+
+    // get the list of chado tables to join on
+    $chado_join_tables = tripal_core_get_chado_tables();
+    $chado_join_tables = array_merge(array('Select a Join Table',), $chado_join_tables);
+
+    // get list of all handlers
+    $all_handlers = tripal_core_views_integration_discover_handlers();
+    $handlers_fields = array();
+    $handlers_filters = array();
+    $handlers_sort = array();
+    $handlers_arguments = array();
+    $handlers_join = array();
+    $handlers_rel = array();
+    $handlers_fields[0] = "Select a field handler"; 
+    $handlers_filters[0] = "Select a filter handler";
+    $handlers_sort[0] = "Select a sort handler";
+    $handlers_argument[0] = "Select an argument handler";
+    $handlers_join[0] = "Select a join handler";
+    $handlers_rel[0] = "Select a relationship handler";
+    foreach($all_handlers as $handler){
+       if(preg_match("/views_handler_field/",$handler)){
+          $handlers_fields[$handler] = $handler;
+       }
+       if(preg_match("/views_handler_filter/",$handler)){
+          $handlers_filters[$handler] = $handler;
+       }
+       if(preg_match("/views_handler_sort/",$handler)){
+          $handlers_sort[$handler] = $handler;
+       }
+       if(preg_match("/views_handler_argument/",$handler)){
+          $handlers_argument[$handler] = $handler;
+       }
+       if(preg_match("/views_handler_join/",$handler)){
+          $handlers_join[$handler] = $handler;
+       }
+       if(preg_match("/views_handler_relationship/",$handler)){
+          $handlers_rel[$handler] = $handler;
+       }
+    }
+
+    // generate a unique $table_id for keeping track of the table
+    if($mview_id){
+       $table_id = $mview_id;
+    } else {
+       $table_id = $table_name;
+    }
+
+    // now iterate through the columns of the materialized view or 
+    // chado table and generate the join and handler fields
+    foreach ($columns as $column){
+      $column = trim($column);  // trim trailing and leading spaces
+      preg_match("/^(.*?)\ (.*?)$/",$column,$matches);
+      $column_name = $matches[1];
+      $column_type = $matches[2];
+
+      $form['view_setup_table']["fields_start_$table_id-$i"] = array(
+           '#type' => 'markup',
+           '#value' => "<div class=\"fields-new-row\">",
+      );
+
+      $form['view_setup_table']["fields_name_$table_id-$i"] = array(
+        '#type' => 'markup',
+        '#attributes' => array('class' => 'fields-column-name'),
+        '#value' => "<div class=\"column-id\">".
+                    "<span class=\"column-name\">$column_name</span>".
+                    "<br><span class=\"column-type\">$column_type</span>".
+                    "</div>".
+                    "<div class=\"column-form-fields\"><div class=\"column-one\">",
+      );
+      $data['field_types'][$column_name] = $column_type;
+
+      // set the default values for the join table and columns
+      $default_join_table = 0;
+      $default_join_field = 0;
+      if(isset($setup_id) && !isset($form_state['storage']["fields_join_$table_id-$i"])){
+      	$default_join_table = $default_joins[$column_name]['left_table'];
+      	$default_join_field = $default_joins[$column_name]['left_field'];
+      	$form_state['storage']["fields_join_$table_id-$i"] = $default_join_table;
+      	$form_state['storage']["fields_join_column_$table_id-$i"] = $default_join_field;
+      }
+      else{
+      	$default_join_table = $form_state['storage']["fields_join_$table_id-$i"];
+      	$default_join_field = $form_state['storage']["fields_join_column_$table_id-$i"];
+      }
+
+      $form['view_setup_table']["fields_join_$table_id-$i"] = array(
+        '#type' => 'select',
+        '#prefix' => "<div class=\"fields-column-join\">",
+        '#suffix' => "</div>",
+        '#options' => $chado_join_tables,
+        '#required' => FALSE,
+        '#default_value' => $default_join_table,
+        '#ahah' => array(
+           'path' => ahah_helper_path(array("view_setup_table","fields_join_column_$table_id-$i")),
+           'wrapper' => "fields-column-join-column-$table_id-$i",
+           'effect' => 'fade',
+           'event' => 'change',
+           'method' => 'replace',
+         ),
+      );
+      
+      $columns = array();
+      if($default_join_table){
+        $table_desc = module_invoke_all('chado_'.$default_join_table.'_schema');
+        foreach ($table_desc['fields'] as $column => $def){
+           $columns[$column] = $column;
+        }
+      } else {
+        $columns = array('Select Join Column');
+      }
+      $form['view_setup_table']["fields_join_column_$table_id-$i"] = array(
+        '#type' => 'select',
+        '#prefix' => "  <div id=\"fields-column-join-column-$table_id-$i\" class=\"fields-column-join-column\">",
+        '#suffix' => "</div></div>",
+        '#options' => $columns,
+        '#required' => FALSE,
+        '#default_value' => $default_join_field
+      );
+
+      // create the handler fields
+      $default_field_handler = 0;
+      if(isset($setup_id) && !isset($form_state['storage']["fields_field_handler_$table_id-$i"])){
+         $default_field_handler = $default_handlers[$column_name]['field']['handler_name'];
+         $form_state['storage']["fields_field_handler_$table_id-$i"] = $default_field_handler;
+      }
+      else {
+      	$default_field_handler = $form_state['storage']["fields_field_handler_$table_id-$i"];
+      }
+
+      $form['view_setup_table']["fields_field_handler_$table_id-$i"] = array(
+         '#type' => 'select',
+         '#prefix' => "<div class=\"column-two\">".
+                        "<div class=\"fields-field-handler\">",
+         '#suffix' => "</div>",
+         '#options' => $handlers_fields,
+         '#required' => FALSE,
+         '#default_value' => $default_field_handler,
+      );
+
+      $default_filter_handler = 0;
+      if(isset($setup_id) && !isset($form_state['storage']["fields_filter_handler_$table_id-$i"])){
+         $default_filter_handler = $default_handlers[$column_name]['filter']['handler_name'];
+         $form_state['storage']["fields_filter_handler_$table_id-$i"]= $default_filter_handler;
+      }
+      else {
+         $default_filter_handler = $form_state['storage']["fields_filter_handler_$table_id-$i"];
+      }
+      $form['view_setup_table']["fields_filter_handler_$table_id-$i"] = array(
+        '#type' => 'select',
+        '#prefix' => "<div class=\"fields-filter-handler\">",
+        '#suffix' => "</div>",
+        '#options' => $handlers_filters,
+        '#required' => FALSE,
+         '#default_value' => $default_filter_handler,
+      );
+
+      $default_sort_handler = 0;
+      if(isset($setup_id) && !isset($form_state['storage']["fields_sort_handler_$table_id-$i"])){
+         $default_sort_handler = $default_handlers[$column_name]['sort']['handler_name'];
+         $form_state['storage']["fields_sort_handler_$table_id-$i"] = $default_sort_handler;
+      }
+      else {
+         $default_sort_handler = $form_state['storage']["fields_sort_handler_$table_id-$i"];
+      }
+      $form['view_setup_table']["fields_sort_handler_$table_id-$i"] = array(
+        '#type' => 'select',
+        '#prefix' => "<div class=\"fields-sort-handler\">",
+        '#suffix' => "</div>",
+        '#options' => $handlers_sort,
+        '#required' => FALSE,
+         '#default_value' => $default_sort_handler,
+      );
+
+      $default_argument_handler = 0;
+      if(isset($setup_id) && !isset($form_state['storage']["fields_argument_handler_$table_id-$i"])){
+         $default_argument_handler = $default_handlers[$column_name]['argument']['handler_name'];
+         $form_state['storage']["fields_argument_handler_$table_id-$i"]=$default_argument_handler ;
+      }
+      else {
+         $default_argument_handler = $form_state['storage']["fields_argument_handler_$table_id-$i"];
+      }
+      $form['view_setup_table']["fields_argument_handler_$table_id-$i"] = array(
+        '#type' => 'select',
+        '#prefix' => "<div class=\"fields-argument-handler\">",
+        '#suffix' => "</div>",
+        '#options' => $handlers_argument,
+        '#required' => FALSE,
+         '#default_value' => $default_argument_handler,
+      );
+
+      $default_relationship_handler = 0;
+      if(isset($setup_id) && !isset($form_state['storage']["fields_relationship_handler_$table_id-$i"])){
+         $default_relationship_handler = $default_handlers[$column_name]['relationship']['handler_name'];
+         $form_state['storage']["fields_relationship_handler_$table_id-$i"]=$default_relationship_handler;
+      }
+      else {
+         $default_relationship_handler = $form_state['storage']["fields_relationship_handler_$table_id-$i"];
+      }
+      $form['view_setup_table']["fields_relationship_handler_$table_id-$i"] = array(
+        '#type' => 'select',
+        '#prefix' => "<div class=\"fields-relationship-handler\">",
+        '#suffix' => "</div>",
+        '#options' => $handlers_rel,
+        '#required' => FALSE,
+         '#default_value' => $default_relationship_handler,
+      );
+
+      $default_join_handler = 0;
+      if(isset($setup_id) && !isset($form_state['storage']["fields_join_handler_$table_id-$i"])){
+         $default_join_handler = $default_handlers[$column_name]['join']['handler_name'];
+         $form_state['storage']["fields_join_handler_$table_id-$i"]=$default_join_handler;
+      }
+      else {
+         $default_join_handler = $form_state['storage']["fields_join_handler_$table_id-$i"];
+      }
+      $form['view_setup_table']["fields_join_handler_$table_id-$i"] = array(
+        '#type' => 'select',
+        '#prefix' => "<div class=\"fields-join-handler\">",
+        '#suffix' => "</div></div>",
+        '#options' => $handlers_join,
+        '#required' => FALSE,
+         '#default_value' => $default_join_handler,
+      );
+      
+      $form['view_setup_table']["fields_end_$i"] = array(
+        '#type' => 'markup',
+        '#value' => "</div></div>",
+      );
+      $i++;
+   }
+   $form['view_setup_table']['save'] = array(
+      '#type'  => 'submit',
+      '#value' => t('Save'),
+   );
+
+    $data['row_count'] = $i - 1;
+  }
+
+  //use this to put values into $form_state['values']
+  $form['data'] = array();   
+
+  //need to find out if storing $form['data'][$key]['#value'] = $value <- is an issue
+  //since it will give me errors if i try to stare an array instead of $value
+  //and yet $value can be an array ie "field_types"
+  foreach ($data as $key => $value) {
+    $form['data'][$key] = array(
+    	'#type' => 'hidden',
+    	'#value' => $value,
+    );
+  }
+
+  $form['#redirect'] = 'admin/tripal/views/integration';   
+
+  return $form;
+}
+
+
+/**
+ *
+ * @ingroup tripal_views_integration
+ */
+function tripal_core_views_integration_form_validate($form, &$form_state){
+  $name_array = explode(" ", $form_state['values']['row_name']);
+  $mview_id = $form_state['values']['mview_id'];
+  $table_name = $form_state['values']['table_name'];
+
+//  if(count($name_array) > 1){
+//    form_set_error($form_state['values']['row_name'], 'The View type name must be a single word only.');
+//  }
+  if($mview_id and $table_name){
+    form_set_error($form_state['values']['mview_id'], 'Please select either a materialized view or a Chado table but not both');
+  }
+  if(!$mview_id and !$table_name){
+    form_set_error($form_state['values']['mview_id'], 'Please select either a materialized view or a Chado table');
+  }
+  // TODO: do we need to require that a handler be set for each field and each type of handler?
+}
+/**
+ *
+ * @ingroup tripal_views_integration
+ */
+function tripal_core_views_integration_form_submit($form, &$form_state){
+   $name = $form_state['values']['row_name'];
+   $mview_id = $form_state['values']['mview_id'];
+   $table_name = $form_state['values']['table_name'];
+   $setup_id = $form_state['values']['setup_id'];
+
+   if($mview_id){
+      $table_id = $mview_id;
+   } else {
+      $table_id = $table_name;
+   }
+
+   // If this is for a materialized view then we want to add/update that record
+   $tripal_views_record = array();
+   if($mview_id){
+      // get details about this mview
+      $sql = "SELECT * FROM {tripal_mviews} WHERE mview_id = $mview_id";
+      $mview = db_fetch_object(db_query($sql));      
+
+      // build the record for insert/update
+      $tripal_views_record = array(
+       'mview_id' => $mview_id,
+       'name' => $name,
+       'comment' => $form_state['values']['row_description'],
+      );
+      if(!$setup_id){  // this is an insert
+         if(!drupal_write_record('tripal_views', $tripal_views_record)){
+            drupal_set_message("Failed to add record.");
+            return;
+         }
+      } else {  // this is an update
+         $tripal_views_record['setup_id'] = $setup_id;
+         if(!drupal_write_record('tripal_views', $tripal_views_record,array('setup_id'))){
+            drupal_set_message("Failed to update record.");
+            return;
+         }
+      }
+   } 
+   // if a chado table then...
+   if($table_name){
+      // TODO: add code to update tables for Chado table
+   }
+
+   
+   // if this is an update then clean out the existing joins and handlers so we can add new ones
+   if($setup_id){  
+      db_query("DELETE FROM {tripal_views_join} WHERE setup_id = %d",$setup_id);
+      db_query("DELETE FROM {tripal_views_handlers} WHERE setup_id = %d",$setup_id);
+   }
+
+   // iterate through the columns of the form and add
+   // the joins if provided, and the handlers
+   $i = 1;
+   foreach ($form_state['values']['field_types'] as $key => $value){
+
+      // first add the join if it exists
+      $left_table = $form_state['values']["fields_join_$table_id-$i"];
+      $left_column = $form_state['values']["fields_join_column_$table_id-$i"];
+
+      if($left_column){
+         $view_join_record = array(
+           'setup_id' => $tripal_views_record['setup_id'],
+           'base_table' => $mview->mv_table,
+           'base_field' => $key,
+           'left_table' => $left_table,
+           'left_field' => $left_column,
+         );
+         
+         // write the new joins to the database
+         drupal_write_record('tripal_views_join', $view_join_record);
+      }
+
+      // add the hanlders
+      $handlers = array('filter','field','sort','argument','join','relationship');
+     
+      foreach($handlers as $handler){
+         $handler_name = $form_state['values']["fields_".$handler."_handler_$table_id-$i"];
+         if($handler_name){
+            $handler_record = array(
+            'setup_id' => $tripal_views_record['setup_id'],
+            'column_name' => $key, 
+            'handler_type' => $handler,
+            'handler_name' => $handler_name,
+            );
+            drupal_write_record('tripal_views_handlers', $handler_record);
+         }
+      }
+      $i++;
+   }
+   if($setup_id){
+      drupal_set_message('Record Updated');
+   } else {
+      drupal_set_message('Record Added');
+   }
+   // now clear all the caches so that Drupal views picks up our chages
+   views_invalidate_cache();
+}
+
+/**
+ *
+ * @ingroup tripal_views_integration
+ */
+function tripal_core_views_integration_discover_handlers() {
+
+   $handlers = array();
+
+   // Get handlers from all modules.
+   foreach (module_implements('views_handlers') as $module) {
+     $function = $module . '_views_handlers';
+     $result = $function();
+     if (!is_array($result)) {
+       continue;
+     }
+     foreach ($result['handlers'] as $handler => $parent){
+        $handlers[] = $handler;
+     }
+   }
+
+   // these handlers are hard coded because I could not
+   // get the views_views_handlers() function to be called
+   // in the code above.  However, we will be creating
+   // Chado wrappers for many of these and once that work
+   // is done these will no longer be needed.
+
+   // argument handlers
+   $handlers[] = 'views_handler_argument';
+   $handlers[] = 'views_handler_argument_numeric';
+   $handlers[] = 'views_handler_argument_formula';
+   $handlers[] = 'views_handler_argument_date';
+   $handlers[] = 'views_handler_argument_string';
+   $handlers[] = 'views_handler_argument_many_to_one';
+   $handlers[] = 'views_handler_argument_null';
+
+   // field handlers
+   $handlers[] = 'views_handler_field';
+   $handlers[] = 'views_handler_field_date';
+   $handlers[] = 'views_handler_field_boolean';
+   $handlers[] = 'views_handler_field_markup';
+   $handlers[] = 'views_handler_field_xss';
+   $handlers[] = 'views_handler_field_url';
+   $handlers[] = 'views_handler_field_file_size';
+   $handlers[] = 'views_handler_field_prerender_list';
+   $handlers[] = 'views_handler_field_numeric';
+   $handlers[] = 'views_handler_field_custom';
+   $handlers[] = 'views_handler_field_counter';
+
+   // filter handlers
+   $handlers[] = 'views_handler_filter';
+   $handlers[] = 'views_handler_filter_equality';
+   $handlers[] = 'views_handler_filter_string';
+   $handlers[] = 'views_handler_filter_boolean_operator';
+   $handlers[] = 'views_handler_filter_boolean_operator_string';
+   $handlers[] = 'views_handler_filter_in_operator';
+   $handlers[] = 'views_handler_filter_numeric';
+   $handlers[] = 'views_handler_filter_float';
+   $handlers[] = 'views_handler_filter_date';
+   $handlers[] = 'views_handler_filter_many_to_one';
+
+   // relationship handlers
+   $handlers[] = 'views_handler_relationship';
+
+   // sort handlers
+   $handlers[] = 'views_handler_sort';
+   $handlers[] = 'views_handler_sort_formula';
+   $handlers[] = 'views_handler_sort_date';
+   $handlers[] = 'views_handler_sort_menu_hierarchy';
+   $handlers[] = 'views_handler_sort_random';
+   return $handlers;
+ }

+ 66 - 0
base/tripal_core/tripal_views_integration_fields_form.tpl.php

@@ -0,0 +1,66 @@
+<style type="text/css">
+
+#tripal-core-views-integration-form  .fields-new-row, .field-headers {
+   dislay: block;
+   margin: 0px;
+   border-bottom-style: solid;
+   border-bottom-width: 1px;
+}
+#tripal-core-views-integration-form .form-item {
+   margin: 0px 0px 5px 0px;
+}
+#tripal-core-views-integration-form .column-id, .column-form-fields, .column-one, .column-two {
+   display: inline-block;
+   margin: 0px;
+   vertical-align: top;
+   //border: 1px solid #000;
+}
+#tripal-core-views-integration-form  .field-headers {
+   font-weight: bold;
+}
+#tripal-core-views-integration-form  .field-headers div {
+   display: inline-block;
+   margin: 0px;
+   vertical-align: top;
+}
+#tripal-core-views-integration-form .column-name {
+   font-weight: bold;
+}
+#tripal-core-views-integration-form .column-type {
+   font-style: italic;
+}
+#tripal-core-views-integration-form .column-id {
+   width: 20%;
+   height: 50px;
+}
+#tripal-core-views-integration-form  .fields-new-row {
+   padding-bottom: 10px;
+   margin-bottom: 5px;
+   padding-top: 10px;
+}
+#tripal-core-views-integration-form .column-form-fields {
+   //border: 3px solid #f00;
+}
+#tripal-core-views-integration-form .column-one {
+   margin-left: 15px;
+}
+#tripal-core-views-integration-form .column-two {
+   margin-left: 15px;
+}
+#tripal-core-views-integration-form .fields-column-join {
+
+}
+#tripal-core-views-integration-form .fields-column-join-column {
+
+}
+#tripal-core-views-integration-form .fields-filter-handler {
+
+}
+#tripal-core-views-integration-form .fields-field-handler {
+
+}
+
+</style>
+
+<?php print drupal_render($form); ?>
+

+ 9 - 9
base/tripal_cv/obo_loader.php

@@ -216,7 +216,7 @@ function tripal_cv_obo_process_term($term,$defaultcv,$obo,$is_relationship=0,&$n
 
    // now handle other properites
    if(isset($term['is_anonymous'])){
-     print "WARNING: unhandled tag: is_anonymous\n";
+     //print "WARNING: unhandled tag: is_anonymous\n";
    }
    if(isset($term['alt_id'])){
       foreach($term['alt_id'] as $alt_id){
@@ -226,7 +226,7 @@ function tripal_cv_obo_process_term($term,$defaultcv,$obo,$is_relationship=0,&$n
       }
    }
    if(isset($term['subset'])){
-     print "WARNING: unhandled tag: subset\n";
+     //print "WARNING: unhandled tag: subset\n";
    }
    // add synonyms for this cvterm
    if(isset($term['synonym'])){
@@ -304,13 +304,13 @@ function tripal_cv_obo_process_term($term,$defaultcv,$obo,$is_relationship=0,&$n
       }
    } 
    if(isset($term['intersection_of'])){
-     print "WARNING: unhandled tag: intersection_of\n";
+     //print "WARNING: unhandled tag: intersection_of\n";
    }
    if(isset($term['union_of'])){
-     print "WARNING: unhandled tag: union_on\n";
+     //print "WARNING: unhandled tag: union_on\n";
    }
    if(isset($term['disjoint_from'])){
-     print "WARNING: unhandled tag: disjoint_from\n";
+     //print "WARNING: unhandled tag: disjoint_from\n";
    }
    if(isset($term['relationship'])){
       foreach($term['relationship'] as $value){
@@ -322,16 +322,16 @@ function tripal_cv_obo_process_term($term,$defaultcv,$obo,$is_relationship=0,&$n
       }
    }
    if(isset($term['replaced_by'])){
-     print "WARNING: unhandled tag: replaced_by\n";
+     //print "WARNING: unhandled tag: replaced_by\n";
    }
    if(isset($term['consider'])){
-     print "WARNING: unhandled tag: consider\n";
+     //print "WARNING: unhandled tag: consider\n";
    }
    if(isset($term['use_term'])){
-     print "WARNING: unhandled tag: user_term\n";
+     //print "WARNING: unhandled tag: user_term\n";
    }
    if(isset($term['builtin'])){
-     print "WARNING: unhandled tag: builtin\n";
+     //print "WARNING: unhandled tag: builtin\n";
    }
    return 1;
 }

+ 3 - 3
base/tripal_cv/tripal_cv.module

@@ -607,7 +607,7 @@ function tripal_cv_add_cvterm_form (&$form_state) {
 		array()
 	);
 	$cvs = array();
-  $cvs[] = '';
+   $cvs[] = '';
 	foreach ($results as $cv) {
 		$cvs[$cv->cv_id] = $cv->name;
 	}
@@ -628,7 +628,7 @@ function tripal_cv_add_cvterm_form (&$form_state) {
 
 	$form['add_cvterm'] = array(
 		'#type'					 => 'item',
-		'#value'				 => t('Please select a vocabulary above to add a term to it'),
+		'#value'				    => t('Please select a vocabulary above to add a term to it'),
 		'#prefix'				 => '<div id="cvterm-add-div">',
 		'#suffix'				 => '</div>'		
 	);
@@ -923,7 +923,7 @@ function tripal_cv_obo_form(&$form_state = NULL){
      '#executes_submit_callback' => TRUE,
    );
 
-   $form['#redirect'] = 'admin/tripal/tripal_cv/obo';
+   $form['#redirect'] = 'admin/tripal/tripal_cv/obo_loader';
 
 
    return $form;

+ 4 - 4
extensions/tripal_search_unigene/tripal_search_unigene.module

@@ -4,15 +4,15 @@
 
 /*************************************************************************
  * tripal_search_unigene_init
- */ 
+ */
 function tripal_search_unigene_init(){
-	drupal_add_css(drupal_get_path('theme', 'tripal_search_unigene').'/theme/css/tripal_search_unigene.css');
-	drupal_add_js(drupal_get_path('theme', 'tripal_search_unigene').'/theme/js/tripal_search_unigene.js');
+	drupal_add_css(drupal_get_path('module', 'tripal_search_unigene').'/theme/css/tripal_search_unigene.css');
+	drupal_add_js(drupal_get_path('module', 'tripal_search_unigene').'/theme/js/tripal_search_unigene.js');
 }
 
 /*************************************************************************
  * tripal_search_unigene_views_api
- */ 
+ */
 function tripal_search_unigene_views_api() {
    return array(
       'api' => 2.0,

Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
views_exports/feature_for_search.view_export.txt


Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff