Browse Source

Updated remaining field handlers with same code as chado_handler_field -using chado_wrapper_functions.inc

Lacey Sanderson 13 years ago
parent
commit
e28f4fc186

+ 23 - 48
base/tripal_core/views/handlers/chado_views_handler_field_boolean.inc

@@ -2,6 +2,11 @@
 
 class chado_views_handler_field_boolean extends views_handler_field_boolean {
 
+  function init (&$view, $options) {
+    include_once('chado_wrapper_functions.inc');
+    parent::init($view,$options);
+  }
+  
   /**
    * Defines the defaults for the options form
    */
@@ -19,6 +24,7 @@ class chado_views_handler_field_boolean extends views_handler_field_boolean {
    */
   function options_form(&$form, &$form_state) {
     parent::options_form($form, $form_state);
+    
     $form['type'] = array(
       '#type' => 'radios',
       '#title' => t('Display type'),
@@ -45,13 +51,20 @@ class chado_views_handler_field_boolean extends views_handler_field_boolean {
    */
   function query () {
     parent::query();
+    $this->aggregated = chado_wrapper_is_aggregated_by_join($this);
+  }
+  
+  /**
+   * Splits the aggregated values up for use in rendering
+   */
+  function pre_render (&$values) {
+    
+    // further check the results to see if this field is a postgresql array
+    $this->aggregated = chado_wrapper_is_aggregated_by_result($this, $values);
+    
+    // Split Aggregated Results
+    chado_wrapper_split_array_agg_results($this, $values);
     
-    $table = $this->query->get_table_info($this->table);
-    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
-      $this->aggregated = TRUE;
-    } else {
-      $this->aggregated = FALSE;
-    }
   }
   
   /**
@@ -64,49 +77,11 @@ class chado_views_handler_field_boolean extends views_handler_field_boolean {
    *   The values retrieved from the database.
    */
   function render($values) {
-    
-    // If it's aggregated (an array), then render each part 
-    // using the parent render functionality
-    if ($this->aggregated) {
-      $items = array();
-      
-      $parts = $this->split_array_agg_results($values->{$this->field_alias});
-      foreach ($parts as $p) {
-        $v[ $this->field_alias ] = $p;
-        $val = (object) $v;
-        $items[] = parent::render($val);
-        unset($v, $val);
-      }
-      
-      if ($this->options['type'] == 'separator') {
-        return implode(check_plain($this->options['separator']), $items);
-      }
-      else {
-        return theme('item_list', $items, NULL, $this->options['type']);
-      }
-    
-    // Otherwise it is not aggragated
-    // Just render like the default handler would
-    } else {
-      return parent::render($values);
-    }
-    
+    return chado_wrapper_render_items($this, $values);
   }
   
-  /**
-   * Splits an SQL array of results in a single field
-   * into a php array
-   *
-   * @param $field
-   *   An SQL array (ie: {"",^(.*)$,646,tripal_analysis_blast} )
-   * @return
-   *   A PHP version of the SQL array (ie: array('','^(.*)$','646','tripal_analysis_blast') )
-   */
-  function split_array_agg_results($field) {
-    if(preg_match('/^{(.*)}$/',$field, $matches)) {
-      return str_getcsv($matches[1]);
-    } else {
-      return array();
-    }
+  function parent_render($val) {
+    return parent::render($val);
   }
+  
 }

+ 23 - 48
base/tripal_core/views/handlers/chado_views_handler_field_counter.inc

@@ -2,6 +2,11 @@
 
 class chado_views_handler_field_counter extends views_handler_field_counter {
 
+  function init (&$view, $options) {
+    include_once('chado_wrapper_functions.inc');
+    parent::init($view,$options);
+  }
+  
   /**
    * Defines the defaults for the options form
    */
@@ -19,6 +24,7 @@ class chado_views_handler_field_counter extends views_handler_field_counter {
    */
   function options_form(&$form, &$form_state) {
     parent::options_form($form, $form_state);
+    
     $form['type'] = array(
       '#type' => 'radios',
       '#title' => t('Display type'),
@@ -45,13 +51,20 @@ class chado_views_handler_field_counter extends views_handler_field_counter {
    */
   function query () {
     parent::query();
+    $this->aggregated = chado_wrapper_is_aggregated_by_join($this);
+  }
+  
+  /**
+   * Splits the aggregated values up for use in rendering
+   */
+  function pre_render (&$values) {
+    
+    // further check the results to see if this field is a postgresql array
+    $this->aggregated = chado_wrapper_is_aggregated_by_result($this, $values);
+    
+    // Split Aggregated Results
+    chado_wrapper_split_array_agg_results($this, $values);
     
-    $table = $this->query->get_table_info($this->table);
-    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
-      $this->aggregated = TRUE;
-    } else {
-      $this->aggregated = FALSE;
-    }
   }
   
   /**
@@ -64,49 +77,11 @@ class chado_views_handler_field_counter extends views_handler_field_counter {
    *   The values retrieved from the database.
    */
   function render($values) {
-    
-    // If it's aggregated (an array), then render each part 
-    // using the parent render functionality
-    if ($this->aggregated) {
-      $items = array();
-      
-      $parts = $this->split_array_agg_results($values->{$this->field_alias});
-      foreach ($parts as $p) {
-        $v[ $this->field_alias ] = $p;
-        $val = (object) $v;
-        $items[] = parent::render($val);
-        unset($v, $val);
-      }
-      
-      if ($this->options['type'] == 'separator') {
-        return implode(check_plain($this->options['separator']), $items);
-      }
-      else {
-        return theme('item_list', $items, NULL, $this->options['type']);
-      }
-    
-    // Otherwise it is not aggragated
-    // Just render like the default handler would
-    } else {
-      return parent::render($values);
-    }
-    
+    return chado_wrapper_render_items($this, $values);
   }
   
-  /**
-   * Splits an SQL array of results in a single field
-   * into a php array
-   *
-   * @param $field
-   *   An SQL array (ie: {"",^(.*)$,646,tripal_analysis_blast} )
-   * @return
-   *   A PHP version of the SQL array (ie: array('','^(.*)$','646','tripal_analysis_blast') )
-   */
-  function split_array_agg_results($field) {
-    if(preg_match('/^{(.*)}$/',$field, $matches)) {
-      return str_getcsv($matches[1]);
-    } else {
-      return array();
-    }
+  function parent_render($val) {
+    return parent::render($val);
   }
+  
 }

+ 23 - 48
base/tripal_core/views/handlers/chado_views_handler_field_custom.inc

@@ -2,6 +2,11 @@
 
 class chado_views_handler_field_custom extends views_handler_field_custom {
 
+  function init (&$view, $options) {
+    include_once('chado_wrapper_functions.inc');
+    parent::init($view,$options);
+  }
+  
   /**
    * Defines the defaults for the options form
    */
@@ -19,6 +24,7 @@ class chado_views_handler_field_custom extends views_handler_field_custom {
    */
   function options_form(&$form, &$form_state) {
     parent::options_form($form, $form_state);
+    
     $form['type'] = array(
       '#type' => 'radios',
       '#title' => t('Display type'),
@@ -45,13 +51,20 @@ class chado_views_handler_field_custom extends views_handler_field_custom {
    */
   function query () {
     parent::query();
+    $this->aggregated = chado_wrapper_is_aggregated_by_join($this);
+  }
+  
+  /**
+   * Splits the aggregated values up for use in rendering
+   */
+  function pre_render (&$values) {
+    
+    // further check the results to see if this field is a postgresql array
+    $this->aggregated = chado_wrapper_is_aggregated_by_result($this, $values);
+    
+    // Split Aggregated Results
+    chado_wrapper_split_array_agg_results($this, $values);
     
-    $table = $this->query->get_table_info($this->table);
-    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
-      $this->aggregated = TRUE;
-    } else {
-      $this->aggregated = FALSE;
-    }
   }
   
   /**
@@ -64,49 +77,11 @@ class chado_views_handler_field_custom extends views_handler_field_custom {
    *   The values retrieved from the database.
    */
   function render($values) {
-    
-    // If it's aggregated (an array), then render each part 
-    // using the parent render functionality
-    if ($this->aggregated) {
-      $items = array();
-      
-      $parts = $this->split_array_agg_results($values->{$this->field_alias});
-      foreach ($parts as $p) {
-        $v[ $this->field_alias ] = $p;
-        $val = (object) $v;
-        $items[] = parent::render($val);
-        unset($v, $val);
-      }
-      
-      if ($this->options['type'] == 'separator') {
-        return implode(check_plain($this->options['separator']), $items);
-      }
-      else {
-        return theme('item_list', $items, NULL, $this->options['type']);
-      }
-    
-    // Otherwise it is not aggragated
-    // Just render like the default handler would
-    } else {
-      return parent::render($values);
-    }
-    
+    return chado_wrapper_render_items($this, $values);
   }
   
-  /**
-   * Splits an SQL array of results in a single field
-   * into a php array
-   *
-   * @param $field
-   *   An SQL array (ie: {"",^(.*)$,646,tripal_analysis_blast} )
-   * @return
-   *   A PHP version of the SQL array (ie: array('','^(.*)$','646','tripal_analysis_blast') )
-   */
-  function split_array_agg_results($field) {
-    if(preg_match('/^{(.*)}$/',$field, $matches)) {
-      return str_getcsv($matches[1]);
-    } else {
-      return array();
-    }
+  function parent_render($val) {
+    return parent::render($val);
   }
+  
 }

+ 23 - 48
base/tripal_core/views/handlers/chado_views_handler_field_date.inc

@@ -2,6 +2,11 @@
 
 class chado_views_handler_field_date extends views_handler_field_date {
 
+  function init (&$view, $options) {
+    include_once('chado_wrapper_functions.inc');
+    parent::init($view,$options);
+  }
+  
   /**
    * Defines the defaults for the options form
    */
@@ -19,6 +24,7 @@ class chado_views_handler_field_date extends views_handler_field_date {
    */
   function options_form(&$form, &$form_state) {
     parent::options_form($form, $form_state);
+    
     $form['type'] = array(
       '#type' => 'radios',
       '#title' => t('Display type'),
@@ -45,13 +51,20 @@ class chado_views_handler_field_date extends views_handler_field_date {
    */
   function query () {
     parent::query();
+    $this->aggregated = chado_wrapper_is_aggregated_by_join($this);
+  }
+  
+  /**
+   * Splits the aggregated values up for use in rendering
+   */
+  function pre_render (&$values) {
+    
+    // further check the results to see if this field is a postgresql array
+    $this->aggregated = chado_wrapper_is_aggregated_by_result($this, $values);
+    
+    // Split Aggregated Results
+    chado_wrapper_split_array_agg_results($this, $values);
     
-    $table = $this->query->get_table_info($this->table);
-    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
-      $this->aggregated = TRUE;
-    } else {
-      $this->aggregated = FALSE;
-    }
   }
   
   /**
@@ -64,49 +77,11 @@ class chado_views_handler_field_date extends views_handler_field_date {
    *   The values retrieved from the database.
    */
   function render($values) {
-    
-    // If it's aggregated (an array), then render each part 
-    // using the parent render functionality
-    if ($this->aggregated) {
-      $items = array();
-      
-      $parts = $this->split_array_agg_results($values->{$this->field_alias});
-      foreach ($parts as $p) {
-        $v[ $this->field_alias ] = $p;
-        $val = (object) $v;
-        $items[] = parent::render($val);
-        unset($v, $val);
-      }
-      
-      if ($this->options['type'] == 'separator') {
-        return implode(check_plain($this->options['separator']), $items);
-      }
-      else {
-        return theme('item_list', $items, NULL, $this->options['type']);
-      }
-    
-    // Otherwise it is not aggragated
-    // Just render like the default handler would
-    } else {
-      return parent::render($values);
-    }
-    
+    return chado_wrapper_render_items($this, $values);
   }
   
-  /**
-   * Splits an SQL array of results in a single field
-   * into a php array
-   *
-   * @param $field
-   *   An SQL array (ie: {"",^(.*)$,646,tripal_analysis_blast} )
-   * @return
-   *   A PHP version of the SQL array (ie: array('','^(.*)$','646','tripal_analysis_blast') )
-   */
-  function split_array_agg_results($field) {
-    if(preg_match('/^{(.*)}$/',$field, $matches)) {
-      return str_getcsv($matches[1]);
-    } else {
-      return array();
-    }
+  function parent_render($val) {
+    return parent::render($val);
   }
+  
 }

+ 23 - 48
base/tripal_core/views/handlers/chado_views_handler_field_markup.inc

@@ -2,6 +2,11 @@
 
 class chado_views_handler_field_markup extends views_handler_field_markup {
 
+  function init (&$view, $options) {
+    include_once('chado_wrapper_functions.inc');
+    parent::init($view,$options);
+  }
+  
   /**
    * Defines the defaults for the options form
    */
@@ -19,6 +24,7 @@ class chado_views_handler_field_markup extends views_handler_field_markup {
    */
   function options_form(&$form, &$form_state) {
     parent::options_form($form, $form_state);
+    
     $form['type'] = array(
       '#type' => 'radios',
       '#title' => t('Display type'),
@@ -45,13 +51,20 @@ class chado_views_handler_field_markup extends views_handler_field_markup {
    */
   function query () {
     parent::query();
+    $this->aggregated = chado_wrapper_is_aggregated_by_join($this);
+  }
+  
+  /**
+   * Splits the aggregated values up for use in rendering
+   */
+  function pre_render (&$values) {
+    
+    // further check the results to see if this field is a postgresql array
+    $this->aggregated = chado_wrapper_is_aggregated_by_result($this, $values);
+    
+    // Split Aggregated Results
+    chado_wrapper_split_array_agg_results($this, $values);
     
-    $table = $this->query->get_table_info($this->table);
-    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
-      $this->aggregated = TRUE;
-    } else {
-      $this->aggregated = FALSE;
-    }
   }
   
   /**
@@ -64,49 +77,11 @@ class chado_views_handler_field_markup extends views_handler_field_markup {
    *   The values retrieved from the database.
    */
   function render($values) {
-    
-    // If it's aggregated (an array), then render each part 
-    // using the parent render functionality
-    if ($this->aggregated) {
-      $items = array();
-      
-      $parts = $this->split_array_agg_results($values->{$this->field_alias});
-      foreach ($parts as $p) {
-        $v[ $this->field_alias ] = $p;
-        $val = (object) $v;
-        $items[] = parent::render($val);
-        unset($v, $val);
-      }
-      
-      if ($this->options['type'] == 'separator') {
-        return implode(check_plain($this->options['separator']), $items);
-      }
-      else {
-        return theme('item_list', $items, NULL, $this->options['type']);
-      }
-    
-    // Otherwise it is not aggragated
-    // Just render like the default handler would
-    } else {
-      return parent::render($values);
-    }
-    
+    return chado_wrapper_render_items($this, $values);
   }
   
-  /**
-   * Splits an SQL array of results in a single field
-   * into a php array
-   *
-   * @param $field
-   *   An SQL array (ie: {"",^(.*)$,646,tripal_analysis_blast} )
-   * @return
-   *   A PHP version of the SQL array (ie: array('','^(.*)$','646','tripal_analysis_blast') )
-   */
-  function split_array_agg_results($field) {
-    if(preg_match('/^{(.*)}$/',$field, $matches)) {
-      return str_getcsv($matches[1]);
-    } else {
-      return array();
-    }
+  function parent_render($val) {
+    return parent::render($val);
   }
+  
 }

+ 23 - 48
base/tripal_core/views/handlers/chado_views_handler_field_math.inc

@@ -2,6 +2,11 @@
 
 class chado_views_handler_field_math extends views_handler_field_math {
 
+  function init (&$view, $options) {
+    include_once('chado_wrapper_functions.inc');
+    parent::init($view,$options);
+  }
+  
   /**
    * Defines the defaults for the options form
    */
@@ -19,6 +24,7 @@ class chado_views_handler_field_math extends views_handler_field_math {
    */
   function options_form(&$form, &$form_state) {
     parent::options_form($form, $form_state);
+    
     $form['type'] = array(
       '#type' => 'radios',
       '#title' => t('Display type'),
@@ -45,13 +51,20 @@ class chado_views_handler_field_math extends views_handler_field_math {
    */
   function query () {
     parent::query();
+    $this->aggregated = chado_wrapper_is_aggregated_by_join($this);
+  }
+  
+  /**
+   * Splits the aggregated values up for use in rendering
+   */
+  function pre_render (&$values) {
+    
+    // further check the results to see if this field is a postgresql array
+    $this->aggregated = chado_wrapper_is_aggregated_by_result($this, $values);
+    
+    // Split Aggregated Results
+    chado_wrapper_split_array_agg_results($this, $values);
     
-    $table = $this->query->get_table_info($this->table);
-    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
-      $this->aggregated = TRUE;
-    } else {
-      $this->aggregated = FALSE;
-    }
   }
   
   /**
@@ -64,49 +77,11 @@ class chado_views_handler_field_math extends views_handler_field_math {
    *   The values retrieved from the database.
    */
   function render($values) {
-    
-    // If it's aggregated (an array), then render each part 
-    // using the parent render functionality
-    if ($this->aggregated) {
-      $items = array();
-      
-      $parts = $this->split_array_agg_results($values->{$this->field_alias});
-      foreach ($parts as $p) {
-        $v[ $this->field_alias ] = $p;
-        $val = (object) $v;
-        $items[] = parent::render($val);
-        unset($v, $val);
-      }
-      
-      if ($this->options['type'] == 'separator') {
-        return implode(check_plain($this->options['separator']), $items);
-      }
-      else {
-        return theme('item_list', $items, NULL, $this->options['type']);
-      }
-    
-    // Otherwise it is not aggragated
-    // Just render like the default handler would
-    } else {
-      return parent::render($values);
-    }
-    
+    return chado_wrapper_render_items($this, $values);
   }
   
-  /**
-   * Splits an SQL array of results in a single field
-   * into a php array
-   *
-   * @param $field
-   *   An SQL array (ie: {"",^(.*)$,646,tripal_analysis_blast} )
-   * @return
-   *   A PHP version of the SQL array (ie: array('','^(.*)$','646','tripal_analysis_blast') )
-   */
-  function split_array_agg_results($field) {
-    if(preg_match('/^{(.*)}$/',$field, $matches)) {
-      return str_getcsv($matches[1]);
-    } else {
-      return array();
-    }
+  function parent_render($val) {
+    return parent::render($val);
   }
+  
 }

+ 23 - 48
base/tripal_core/views/handlers/chado_views_handler_field_numeric.inc

@@ -2,6 +2,11 @@
 
 class chado_views_handler_field_numeric extends views_handler_field_numeric {
 
+  function init (&$view, $options) {
+    include_once('chado_wrapper_functions.inc');
+    parent::init($view,$options);
+  }
+  
   /**
    * Defines the defaults for the options form
    */
@@ -19,6 +24,7 @@ class chado_views_handler_field_numeric extends views_handler_field_numeric {
    */
   function options_form(&$form, &$form_state) {
     parent::options_form($form, $form_state);
+    
     $form['type'] = array(
       '#type' => 'radios',
       '#title' => t('Display type'),
@@ -45,13 +51,20 @@ class chado_views_handler_field_numeric extends views_handler_field_numeric {
    */
   function query () {
     parent::query();
+    $this->aggregated = chado_wrapper_is_aggregated_by_join($this);
+  }
+  
+  /**
+   * Splits the aggregated values up for use in rendering
+   */
+  function pre_render (&$values) {
+    
+    // further check the results to see if this field is a postgresql array
+    $this->aggregated = chado_wrapper_is_aggregated_by_result($this, $values);
+    
+    // Split Aggregated Results
+    chado_wrapper_split_array_agg_results($this, $values);
     
-    $table = $this->query->get_table_info($this->table);
-    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
-      $this->aggregated = TRUE;
-    } else {
-      $this->aggregated = FALSE;
-    }
   }
   
   /**
@@ -64,49 +77,11 @@ class chado_views_handler_field_numeric extends views_handler_field_numeric {
    *   The values retrieved from the database.
    */
   function render($values) {
-    
-    // If it's aggregated (an array), then render each part 
-    // using the parent render functionality
-    if ($this->aggregated) {
-      $items = array();
-      
-      $parts = $this->split_array_agg_results($values->{$this->field_alias});
-      foreach ($parts as $p) {
-        $v[ $this->field_alias ] = $p;
-        $val = (object) $v;
-        $items[] = parent::render($val);
-        unset($v, $val);
-      }
-      
-      if ($this->options['type'] == 'separator') {
-        return implode(check_plain($this->options['separator']), $items);
-      }
-      else {
-        return theme('item_list', $items, NULL, $this->options['type']);
-      }
-    
-    // Otherwise it is not aggragated
-    // Just render like the default handler would
-    } else {
-      return parent::render($values);
-    }
-    
+    return chado_wrapper_render_items($this, $values);
   }
   
-  /**
-   * Splits an SQL array of results in a single field
-   * into a php array
-   *
-   * @param $field
-   *   An SQL array (ie: {"",^(.*)$,646,tripal_analysis_blast} )
-   * @return
-   *   A PHP version of the SQL array (ie: array('','^(.*)$','646','tripal_analysis_blast') )
-   */
-  function split_array_agg_results($field) {
-    if(preg_match('/^{(.*)}$/',$field, $matches)) {
-      return str_getcsv($matches[1]);
-    } else {
-      return array();
-    }
+  function parent_render($val) {
+    return parent::render($val);
   }
+  
 }