Преглед изворни кода

Updated 6.x-1482618-API_for_default_views_integration to the newest version of 6.x-1.x

Lacey Sanderson пре 12 година
родитељ
комит
a52b0a5893

+ 14 - 13
tripal_core/api/tripal_core.api.inc

@@ -699,13 +699,13 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
           'regex_columns' => $options['regex_columns'],
           'regex_columns' => $options['regex_columns'],
           'case_insensitive_columns' => $options['case_insensitive_columns']
           'case_insensitive_columns' => $options['case_insensitive_columns']
         );
         );
-        if($options['statement_name']){
+        if ($options['statement_name']) {
            // add the fk relationship info to the prepared statement name so that
            // add the fk relationship info to the prepared statement name so that
            // we can prepare the selects run by the recrusive tripal_core_chado_get_foreign_key
            // we can prepare the selects run by the recrusive tripal_core_chado_get_foreign_key
            // function.
            // function.
            $foreign_options['statement_name'] = $options['statement_name'] . "fk_" . $table . "_" . $field;
            $foreign_options['statement_name'] = $options['statement_name'] . "fk_" . $table . "_" . $field;
         }
         }
-        if($options['prepare']){
+        if ($options['prepare']) {
            $foreign_options['prepare'] = $options['prepare'];
            $foreign_options['prepare'] = $options['prepare'];
         }
         }
         $results = tripal_core_chado_get_foreign_key($table_desc, $field, $value, $foreign_options);
         $results = tripal_core_chado_get_foreign_key($table_desc, $field, $value, $foreign_options);
@@ -867,7 +867,7 @@ function tripal_core_chado_select($table, $columns, $values, $options = NULL) {
   }
   }
 #  print "$psql\n";
 #  print "$psql\n";
 #  print "$sql\n";
 #  print "$sql\n";
-#  print '$results = ' . print_r($results,1);
+#  print '$results = ' . print_r($results, 1);
   return $results;
   return $results;
 }
 }
 
 
@@ -958,7 +958,7 @@ function tripal_core_chado_get_foreign_key($table_desc, $field, $values, $option
           $select_cols = array($right);
           $select_cols = array($right);
           $result = tripal_core_chado_select($table, $select_cols, $values, $options);
           $result = tripal_core_chado_select($table, $select_cols, $values, $options);
           $fields = array();
           $fields = array();
-          if (count($result) > 0) {
+          if ($result and count($result) > 0) {
             foreach ($result as $obj) {
             foreach ($result as $obj) {
               $fields[] = $obj->$right;
               $fields[] = $obj->$right;
             }
             }
@@ -1985,9 +1985,10 @@ function tripal_db_set_active($dbname) {
  *   TRUE if the statement is preapred, FALSE otherwise
  *   TRUE if the statement is preapred, FALSE otherwise
  */
  */
 function tripal_core_is_sql_prepared($statement_name) {
 function tripal_core_is_sql_prepared($statement_name) {
+  // @coder-ignore: acting on postgres tables rather then drupal schema therefore, table prefixing does not apply
   $sql = "SELECT name FROM pg_prepared_statements WHERE name = '%s'";
   $sql = "SELECT name FROM pg_prepared_statements WHERE name = '%s'";
-  $result = db_fetch_object(chado_query($sql,$statement_name));
-  if($result){
+  $result = db_fetch_object(chado_query($sql, $statement_name));
+  if ($result) {
      return TRUE;
      return TRUE;
   }
   }
   return FALSE;
   return FALSE;
@@ -2318,11 +2319,11 @@ function tripal_core_get_chado_tables($include_custom = NULL) {
  *
  *
  * @ingroup tripal_core_api
  * @ingroup tripal_core_api
  */
  */
-function tripal_core_get_chado_version () {
+function tripal_core_get_chado_version() {
 
 
   // check that Chado is installed if not return 'uninstalled as the version'
   // check that Chado is installed if not return 'uninstalled as the version'
   $chado_exists = tripal_core_chado_schema_exists();
   $chado_exists = tripal_core_chado_schema_exists();
-  if(!$chado_exists){
+  if (!$chado_exists) {
      return 'not installed';
      return 'not installed';
   }
   }
 
 
@@ -2331,7 +2332,7 @@ function tripal_core_get_chado_version () {
   $previous_db = tripal_db_set_active('chado');
   $previous_db = tripal_db_set_active('chado');
   $prop_exists = db_table_exists('chadoprop');
   $prop_exists = db_table_exists('chadoprop');
   tripal_db_set_active($previous_db);
   tripal_db_set_active($previous_db);
-  if(!$prop_exists){
+  if (!$prop_exists) {
      return "1.11 or older";
      return "1.11 or older";
   }
   }
   
   
@@ -2349,7 +2350,7 @@ function tripal_core_get_chado_version () {
   
   
   // if we don't have a version in the chadoprop table then it must be 
   // if we don't have a version in the chadoprop table then it must be 
   // v1.11 or older 
   // v1.11 or older 
-  if(!$v->value){
+  if (!$v->value) {
      return "1.11 or older";
      return "1.11 or older";
   }
   }
   return $v->value;
   return $v->value;
@@ -2372,13 +2373,13 @@ function tripal_core_get_chado_table_schema($table) {
    $v = tripal_core_get_chado_version();
    $v = tripal_core_get_chado_version();
    
    
    // Tripal only supports v1.11 or newer
    // Tripal only supports v1.11 or newer
-   if(strcmp($v,'1.11 or older')==0){
+   if (strcmp($v, '1.11 or older')==0) {
       $v = "1.11";
       $v = "1.11";
    }
    }
 
 
    // get the table array from the proper chado schema
    // get the table array from the proper chado schema
-   $v = preg_replace("/\./","_",$v); // reformat version for hook name
-   $table_arr = module_invoke_all("chado_schema_v".$v."_" . $table);
+   $v = preg_replace("/\./", "_", $v); // reformat version for hook name
+   $table_arr = module_invoke_all("chado_schema_v" . $v . "_" . $table);
 
 
    return $table_arr;
    return $table_arr;
 }
 }

+ 1 - 1
tripal_core/tripal_core.install

@@ -73,7 +73,7 @@ function tripal_core_schema() {
   // installation we don't want to make these custom tables available as we don't
   // installation we don't want to make these custom tables available as we don't
   // want them created in the Drupal database.  The custom tables go in the
   // want them created in the Drupal database.  The custom tables go in the
   // Chado database.
   // Chado database.
-  if(db_table_exists('tripal_custom_tables')){
+  if (db_table_exists('tripal_custom_tables')) {
     $sql = 'SELECT * FROM {tripal_custom_tables}';
     $sql = 'SELECT * FROM {tripal_custom_tables}';
     $q = db_query($sql);
     $q = db_query($sql);
     while ($custom = db_fetch_object($q)) {
     while ($custom = db_fetch_object($q)) {

+ 4 - 4
tripal_feature/includes/gff_loader.inc

@@ -161,9 +161,9 @@ function tripal_feature_gff3_load_form_validate($form, &$form_state) {
   // @coder-ignore: there are no functions being called here
   // @coder-ignore: there are no functions being called here
   // @todo: break each line of this conditional into separate variables to make more readable
   // @todo: break each line of this conditional into separate variables to make more readable
   if (($add_only AND ($update OR $refresh OR $remove)) OR
   if (($add_only AND ($update OR $refresh OR $remove)) OR
-    ($update AND ($add_only OR $refresh OR $remove)) OR
-    ($refresh AND ($update OR $add_only OR $remove)) OR
-    ($remove AND ($update OR $refresh OR $add_only))) {
+      ($update AND ($add_only OR $refresh OR $remove)) OR
+      ($refresh AND ($update OR $add_only OR $remove)) OR
+      ($remove AND ($update OR $refresh OR $add_only))) {
       form_set_error('add_only', t("Please select only one checkbox from the import options section"));
       form_set_error('add_only', t("Please select only one checkbox from the import options section"));
   }
   }
 }
 }
@@ -367,7 +367,7 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id, $add_on
       }
       }
 
 
       // break apart each tag
       // break apart each tag
-      $tag = preg_split("/=/", $attr,2);  // split by equals sign
+      $tag = preg_split("/=/", $attr, 2);  // split by equals sign
       // multiple instances of an attribute are separated by commas
       // multiple instances of an attribute are separated by commas
       $tags[$tag[0]] = explode(",", $tag[1]);  // split by comma
       $tags[$tag[0]] = explode(",", $tag[1]);  // split by comma
       if (strcmp($tag[0], 'ID')==0) {
       if (strcmp($tag[0], 'ID')==0) {

+ 0 - 0
tripal_views/tripal_views.api.inc → tripal_views/api/tripal_views.api.inc


+ 0 - 0
tripal_views/tripal_views_form_elements.inc → tripal_views/includes/tripal_views_form_elements.inc


+ 0 - 0
tripal_views/tripal_views_integration.inc → tripal_views/includes/tripal_views_integration.inc


+ 0 - 0
tripal_views/tripal_views_integration_port.inc → tripal_views/includes/tripal_views_integration_port.inc


+ 4 - 3
tripal_views/tripal_views.module

@@ -1,9 +1,10 @@
 <?php
 <?php
 
 
-require_once "tripal_views_integration.inc";
 require_once "tripal_views.views.inc";
 require_once "tripal_views.views.inc";
-require_once "tripal_views_form_elements.inc";
-require_once "tripal_views_integration_port.inc";
+
+require_once "includes/tripal_views_integration.inc";
+require_once "includes/tripal_views_form_elements.inc";
+require_once "includes/tripal_views_integration_port.inc";
 
 
 /**
 /**
  * Implements hook_menu()
  * Implements hook_menu()

+ 14 - 15
tripal_views/tripal_views.views.inc

@@ -2,7 +2,7 @@
 
 
 include('views/handlers/views_handler_join_chado_through_linking.inc');
 include('views/handlers/views_handler_join_chado_through_linking.inc');
 include('views/handlers/views_handler_join_chado_aggregator.inc');
 include('views/handlers/views_handler_join_chado_aggregator.inc');
-include('tripal_views.api.inc');
+include('api/tripal_views.api.inc');
 
 
 
 
 // TEMPORARY
 // TEMPORARY
@@ -62,27 +62,26 @@ function tripal_views_views_handlers() {
     ),
     ),
     'handlers' => array(
     'handlers' => array(
 
 
-      // Custom Tripal Handlers
-      'views_handler_filter_file_upload' => array(
+      // Custom Tripal Filter Handlers
+      'tripal_views_handler_filter_file_upload' => array(
         'parent' => 'views_handler_filter',
         'parent' => 'views_handler_filter',
       ),
       ),
-      'tripal_views_handler_filter_string_selectbox' => array(
-        'parent' => 'views_handler_filter_string',
-      ),
-      'views_handler_filter_no_results' => array(
+      'tripal_views_handler_filter_no_results' => array(
         'parent' => 'views_handler_filter'
         'parent' => 'views_handler_filter'
       ),
       ),
-
-      // Custom Chado Handlers
-      'chado_views_handler_field_aggregate' => array(
-        'parent' => 'chado_views_handler_field',
-      ),
-      'chado_views_handler_filter_select_cvterm' => array(
+      'tripal_views_handler_filter_select_cvterm' => array(
         'parent' => 'views_handler_filter_chado_select_cvterm_name',
         'parent' => 'views_handler_filter_chado_select_cvterm_name',
       ),
       ),
-      'chado_views_handler_filter_select_string' => array(
+      'tripal_views_handler_filter_select_string' => array(
         'parent' => 'chado_views_handler_filter_string',
         'parent' => 'chado_views_handler_filter_string',
-
+      ),
+      
+      // Custom Tripal Field Handlers
+      'tripal_views_handler_field_aggregate' => array(
+        'parent' => 'chado_views_handler_field',
+      ),
+      'tripal_views_handler_field_sequence' => array(
+        'parent' => 'chado_views_handler_field',
       ),
       ),
 
 
       // Join Handlers
       // Join Handlers

+ 1 - 1
tripal_views/views/handlers/chado_views_handler_field_aggregate.inc → tripal_views/views/handlers/tripal_views_handler_field_aggregate.inc

@@ -8,7 +8,7 @@
  * will render an aggregated field as a pre_rendered list and will dynamically detect
  * will render an aggregated field as a pre_rendered list and will dynamically detect
  * whether the field is aggregated or not.
  * whether the field is aggregated or not.
  */
  */
-class chado_views_handler_field_aggregate extends chado_views_handler_field {
+class tripal_views_handler_field_aggregate extends chado_views_handler_field {
 
 
   function init(&$view, $options) {
   function init(&$view, $options) {
     parent::init($view, $options);
     parent::init($view, $options);

+ 1 - 1
tripal_views/views/handlers/views_handler_filter_file_upload.inc → tripal_views/views/handlers/tripal_views_handler_filter_file_upload.inc

@@ -7,7 +7,7 @@
  *
  *
  * @ingroup tripal_views_integration
  * @ingroup tripal_views_integration
  */
  */
-class views_handler_filter_file_upload extends views_handler_filter {
+class tripal_views_handler_filter_file_upload extends views_handler_filter {
 
 
   /**
   /**
    * Defines the value field in both the views filter options form
    * Defines the value field in both the views filter options form

+ 2 - 2
tripal_views/views/handlers/views_handler_filter_no_results.inc → tripal_views/views/handlers/tripal_views_handler_filter_no_results.inc

@@ -6,7 +6,7 @@
  * query is not run). This imitates an advanced search form allowing users to fist
  * query is not run). This imitates an advanced search form allowing users to fist
  * enter other filter values and then retrieve results.
  * enter other filter values and then retrieve results.
  */
  */
-class views_handler_filter_no_results extends views_handler_filter {
+class tripal_views_handler_filter_no_results extends views_handler_filter {
 
 
   /**
   /**
    * Ensure this filter is not exposed
    * Ensure this filter is not exposed
@@ -82,4 +82,4 @@ class views_handler_filter_no_results extends views_handler_filter {
     }
     }
   }
   }
 
 
-}
+}

+ 2 - 2
tripal_views/views/handlers/chado_views_handler_filter_select_cvterm.inc → tripal_views/views/handlers/tripal_views_handler_filter_select_cvterm.inc

@@ -10,7 +10,7 @@
  * @ingroup views_filter_handlers
  * @ingroup views_filter_handlers
  * @ingroup tripal_core
  * @ingroup tripal_core
  */
  */
-class chado_views_handler_filter_select_cvterm extends views_handler_filter_chado_select_cvterm_name {
+class tripal_views_handler_filter_select_cvterm extends views_handler_filter_chado_select_cvterm_name {
 
 
  /**
  /**
   * Executed when the field is added
   * Executed when the field is added
@@ -102,4 +102,4 @@ class chado_views_handler_filter_select_cvterm extends views_handler_filter_chad
     }
     }
 
 
   }
   }
-}
+}

+ 1 - 1
tripal_views/views/handlers/chado_views_handler_filter_select_string.inc → tripal_views/views/handlers/tripal_views_handler_filter_select_string.inc

@@ -8,7 +8,7 @@
  * @ingroup views_filter_handlers
  * @ingroup views_filter_handlers
  * @ingroup tripal_core
  * @ingroup tripal_core
  */
  */
-class chado_views_handler_filter_select_string extends chado_views_handler_filter_string {
+class tripal_views_handler_filter_select_string extends chado_views_handler_filter_string {
 
 
   function options_form(&$form, &$form_state) {
   function options_form(&$form, &$form_state) {
     parent::options_form($form, $form_state);
     parent::options_form($form, $form_state);

+ 0 - 206
tripal_views/views/handlers/tripal_views_handler_filter_string_selectbox.inc

@@ -1,206 +0,0 @@
-<?php
-
-/**
- * @file
- * Purpose: This Handler provides a generic select list for any chado field that is a string
- *  The select list includes all distinct values for that field.
- *
- * @ingroup views_filter_handlers
- * @ingroup tripal_core
- */
-class tripal_views_handler_filter_string_selectbox extends views_handler_filter_string {
-
-  function options_form(&$form, &$form_state) {
-    parent::options_form($form, $form_state);
-
-    $form['values_form_type'] = array(
-      '#type' => 'radios',
-      '#title' => t('Filter Type'),
-      '#options' => array(
-        'textfield' => 'Text Field',
-        'select' => 'Drop-Down Box',
-      ),
-      '#default_value' => ($this->options['values_form_type']) ? $this->options['values_form_type'] : 'select',
-    );
-
-    $form['multiple'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Select Multiple'),
-      '#description' => t('Allows more then one option to be selected.'),
-      '#default_value' => (isset($this->options['multiple'])) ? $this->options['multiple'] : FALSE,
-    );
-
-    $form['optional'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Optional'),
-      '#description' => t('Adds --Any-- to the available options.'),
-      '#default_value' => (isset($this->options['optional'])) ? $this->options['optional'] : TRUE,
-    );
-
-    $form['max_length'] = array(
-      '#type' => 'textfield',
-      '#title' => t('Max Width'),
-      '#description' => t('Specify the maximum width of the select box'),
-      '#default_value' => (isset($this->options['max_length'])) ? $this->options['max_length'] : 40,
-
-    );
-    $form['max_length'] = array(
-      '#type' => 'markup',
-      '#value' => t('<strong><font color="red">Note:</font></strong> If another filter exists for the same table then '.
-                    'the values shown in the drop box will only include those from rows that are not filtered.'),
-
-    );
-
-  }
-
- /**
-  * Defines the value field in both the views filter options form
-  *   and the exposed form
-  */
-  function value_form(&$form, &$form_state) {
-    parent::value_form($form, $form_state);
-
-    if (preg_match('/textfield/', $this->options['values_form_type'])) {
-      $form['value'] = array(
-        '#type' => 'textfield',
-        '#title' => t('%label', array('%label' => $this->options['label'])),
-        '#default_value' => $this->value,
-      );
-
-    }
-    else {
-
-      // build a where clause that will filter the list in the drop box
-      // using fields that are not exposed and that are for the table
-      // from whcih the values in the drop box will be slected and
-      // we only want to use non-exposed fields because these are not
-      // available to the user to edit--their fixed.
-      $where = '';
-      $filters = $this->view->filter;
-      foreach($filters as $filter_name => $details){
-         // we only want to inclue non-exposed filters 
-         if($details->options['exposed'] == FALSE){
-            // we only want to filter on the table we're getting the list from
-            if(strcmp($details->table,$this->table)==0){
-              $where .= "$details->field $details->operator ". $details->value['value'];
-              $where .= ' AND ';
-            }
-         }
-      } 
-      if($where){
-         $where = "WHERE $where";
-         $where = substr($where,0,-5); # remove the final ' AND '
-      }
-
-      // get the values from the table
-      $sql = "SELECT $this->real_field FROM $this->table $where ORDER BY $this->field ASC";
-      $previous_db = tripal_db_set_active('chado');  // use chado database
-      $results = db_query($sql);
-      tripal_db_set_active($previous_db);  // now use drupal database
-
-      // Build the select box options
-      $max_length = $this->options['max_length'];
-      if (!$max_length) {
-        $max_length = 40;
-      }
-      if ($this->options['optional']) {
-        //$options['<select '.$this->table.'>'] = '--None--';
-        $options['All'] = '--Any--';
-      }
-      while ($r = db_fetch_object($results)) {
-        if (drupal_strlen($r->{$this->field}) > $max_length) {
-          $options[$r->{$this->field}] = drupal_substr($r->{$this->field}, 0, $max_length) . '...';
-        }
-        else {
-          $options[$r->{$this->field}] = $r->{$this->field};
-        }
-      }
-
-      //Select List
-      $form['value'] = array(
-          '#type' => 'select',
-          '#title' => t('%label', array('%label' => $this->options['label'])),
-          '#options' => $options,
-          '#default_value' => $this->value,
-      );
-
-      if ($this->options['multiple']) {
-        $form['value']['#multiple'] = TRUE;
-      }
-    }
-  }
-
- /**
-  * Ensures the select list gets rendered when the filter is exposed
-  */
-  function exposed_form(&$form, &$form_state) {
-    if (empty($this->options['exposed'])) {
-      return;
-    }
-
-    $value = $this->options['expose']['identifier'];
-    $this->value_form($form, $form_state);
-    $form[$value] = $form['value'];
-
-    if (isset($form[$value]['#title']) && !empty($form[$value]['#type']) && $form[$value]['#type'] != 'checkbox') {
-      unset($form[$value]['#title']);
-    }
-
-    $this->exposed_translate($form[$value], 'value');
-
-    if (!empty($form['#type']) && ($form['#type'] == 'checkboxes' || ($form['#type'] == 'select' && !empty($form['#multiple'])))) {
-      unset($form[$value]['#default_value']);
-    }
-
-    if (!empty($form['#type']) && $form['#type'] == 'select' && empty($form['#multiple'])) {
-      $form[$value]['#default_value'] = 'All';
-    }
-
-    if ($value != 'value') {
-      unset($form['value']);
-    }
-
-  }
-
- /**
-  *
-  */
-  function query() {
-
-    $this->ensure_my_table();
-    $field = "$this->table_alias.$this->real_field";
-    $upper = $this->case_transform();
-
-    if ($this->options['multiple']) {
-      // Remove any if it's there
-      unset($this->value['All']);
-
-      if (sizeof($this->value)) {
-        $holders = array();
-        foreach ($this->value as $v) {
-          if (preg_match('/^[\d\.]+$/', $v)) {
-            $holders[] = '%d';
-          }
-          else {
-            $holders[] = "'%s'";
-          }
-        }
-        $where = "$field IN (" . implode(", ", $holders) . ")";
-        $this->query->add_where($this->options['group'], $where, $this->value);
-      }
-    }
-    else {
-
-      // Deal with All/Any as value
-      if (preg_match('/All/', $this->value)) {
-        // Don't do anything
-      }
-      else {
-        $info = $this->operators();
-        if (!empty($info[$this->operator]['method'])) {
-          $this->{$info[$this->operator]['method']}($field, $upper);
-        }
-      }
-    }
-  }
-}