Browse Source

Created all chado_wrapper field handlers :) -only string fully tested

Lacey Sanderson 13 năm trước cách đây
mục cha
commit
8e0cd44755

+ 1 - 1
base/tripal_analysis/views/analysis.views.inc

@@ -80,7 +80,7 @@ function retrieve_analysis_views_data() {
     'title' => t('Value'),
     'help' => t(' '),
     'field' => array(
-      'handler' => 'views_handler_field',
+      'handler' => 'chado_views_handler_field',
       'click sortable' => TRUE,
     ),
     'sort' => array(

+ 27 - 2
base/tripal_core/tripal_core.views.inc

@@ -60,6 +60,7 @@ function tripal_core_views_handlers() {
      'path' => drupal_get_path('module', 'tripal_core') . '/views/handlers',
    ),
    'handlers' => array(
+     // Custom Chado Handlers
      'views_handler_field_node_optional' => array(
        'parent' => 'views_handler_field_node',
      ),
@@ -84,8 +85,32 @@ function tripal_core_views_handlers() {
      'views_handler_field_chado_rel_by_type' => array(
       'parent' => 'views_handler_field_prerender_list',
      ),
-     'views_handler_join_chado_one2many' => array(
-      'parent' => 'views_join'
+
+     
+     // Wrappers for Default Views Handlers
+     'chado_views_handler_field' => array(
+      'parent' => 'views_handler_field'
+     ),
+     'chado_views_handler_field_boolean' => array(
+      'parent' => 'views_handler_field_boolean'
+     ),
+     'chado_views_handler_field_counter' => array(
+      'parent' => 'views_handler_field_counter'
+     ),
+     'chado_views_handler_field_custom' => array(
+      'parent' => 'views_handler_field_custom'
+     ),
+     'chado_views_handler_field_date' => array(
+      'parent' => 'views_handler_field_date'
+     ),
+     'chado_views_handler_field_markup' => array(
+      'parent' => 'views_handler_field_markup'
+     ),
+     'chado_views_handler_field_math' => array(
+      'parent' => 'views_handler_field_math'
+     ),
+     'chado_views_handler_field_numeric' => array(
+      'parent' => 'views_handler_field_numeric'
      ),
    ),
  );

+ 112 - 0
base/tripal_core/views/handlers/chado_views_handler_field.inc

@@ -0,0 +1,112 @@
+<?php
+
+class chado_views_handler_field extends views_handler_field {
+
+  /**
+   * Defines the defaults for the options form
+   */
+  function option_definition() {
+    $options = parent::option_definition();
+
+    $options['type'] = array('default' => 'separator');
+    $options['separator'] = array('default' => ', ');
+
+    return $options;
+  }
+  
+  /**
+   * Defines the options form (form available to admin when they add a field to a view)
+   */
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+    $form['type'] = array(
+      '#type' => 'radios',
+      '#title' => t('Display type'),
+      '#options' => array(
+        'ul' => t('Unordered list'),
+        'ol' => t('Ordered list'),
+        'separator' => t('Simple separator'),
+      ),
+      '#default_value' => $this->options['type'],
+    );
+
+    $form['separator'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Separator'),
+      '#default_value' => $this->options['separator'],
+      '#process' => array('views_process_dependency'),
+      '#dependency' => array('radio:options[type]' => array('separator')),
+    );
+  }
+  
+  /**
+   * Determines whether the current field is aggregated or not
+   * Note: The parent::query() takes care of adding the field to the query, etc.
+   */
+  function query () {
+    parent::query();
+    
+    $table = $this->query->get_table_info($this->table);
+    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
+      $this->aggregated = TRUE;
+    } else {
+      $this->aggregated = FALSE;
+    }
+  }
+  
+  /**
+   * Render the field.
+   *
+   * Note: Checks to see if we have an array or simple field. If we have an array, then
+   *   split it up and render each part using the parent render functionality.
+   *
+   * @param $values
+   *   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);
+    }
+    
+  }
+  
+  /**
+   * 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();
+    }
+  }
+}

+ 112 - 0
base/tripal_core/views/handlers/chado_views_handler_field_boolean.inc

@@ -0,0 +1,112 @@
+<?php
+
+class chado_views_handler_field_boolean extends views_handler_field_boolean {
+
+  /**
+   * Defines the defaults for the options form
+   */
+  function option_definition() {
+    $options = parent::option_definition();
+
+    $options['type'] = array('default' => 'separator');
+    $options['separator'] = array('default' => ', ');
+
+    return $options;
+  }
+  
+  /**
+   * Defines the options form (form available to admin when they add a field to a view)
+   */
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+    $form['type'] = array(
+      '#type' => 'radios',
+      '#title' => t('Display type'),
+      '#options' => array(
+        'ul' => t('Unordered list'),
+        'ol' => t('Ordered list'),
+        'separator' => t('Simple separator'),
+      ),
+      '#default_value' => $this->options['type'],
+    );
+
+    $form['separator'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Separator'),
+      '#default_value' => $this->options['separator'],
+      '#process' => array('views_process_dependency'),
+      '#dependency' => array('radio:options[type]' => array('separator')),
+    );
+  }
+  
+  /**
+   * Determines whether the current field is aggregated or not
+   * Note: The parent::query() takes care of adding the field to the query, etc.
+   */
+  function query () {
+    parent::query();
+    
+    $table = $this->query->get_table_info($this->table);
+    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
+      $this->aggregated = TRUE;
+    } else {
+      $this->aggregated = FALSE;
+    }
+  }
+  
+  /**
+   * Render the field.
+   *
+   * Note: Checks to see if we have an array or simple field. If we have an array, then
+   *   split it up and render each part using the parent render functionality.
+   *
+   * @param $values
+   *   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);
+    }
+    
+  }
+  
+  /**
+   * 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();
+    }
+  }
+}

+ 112 - 0
base/tripal_core/views/handlers/chado_views_handler_field_counter.inc

@@ -0,0 +1,112 @@
+<?php
+
+class chado_views_handler_field_counter extends views_handler_field_counter {
+
+  /**
+   * Defines the defaults for the options form
+   */
+  function option_definition() {
+    $options = parent::option_definition();
+
+    $options['type'] = array('default' => 'separator');
+    $options['separator'] = array('default' => ', ');
+
+    return $options;
+  }
+  
+  /**
+   * Defines the options form (form available to admin when they add a field to a view)
+   */
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+    $form['type'] = array(
+      '#type' => 'radios',
+      '#title' => t('Display type'),
+      '#options' => array(
+        'ul' => t('Unordered list'),
+        'ol' => t('Ordered list'),
+        'separator' => t('Simple separator'),
+      ),
+      '#default_value' => $this->options['type'],
+    );
+
+    $form['separator'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Separator'),
+      '#default_value' => $this->options['separator'],
+      '#process' => array('views_process_dependency'),
+      '#dependency' => array('radio:options[type]' => array('separator')),
+    );
+  }
+  
+  /**
+   * Determines whether the current field is aggregated or not
+   * Note: The parent::query() takes care of adding the field to the query, etc.
+   */
+  function query () {
+    parent::query();
+    
+    $table = $this->query->get_table_info($this->table);
+    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
+      $this->aggregated = TRUE;
+    } else {
+      $this->aggregated = FALSE;
+    }
+  }
+  
+  /**
+   * Render the field.
+   *
+   * Note: Checks to see if we have an array or simple field. If we have an array, then
+   *   split it up and render each part using the parent render functionality.
+   *
+   * @param $values
+   *   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);
+    }
+    
+  }
+  
+  /**
+   * 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();
+    }
+  }
+}

+ 112 - 0
base/tripal_core/views/handlers/chado_views_handler_field_custom.inc

@@ -0,0 +1,112 @@
+<?php
+
+class chado_views_handler_field_custom extends views_handler_field_custom {
+
+  /**
+   * Defines the defaults for the options form
+   */
+  function option_definition() {
+    $options = parent::option_definition();
+
+    $options['type'] = array('default' => 'separator');
+    $options['separator'] = array('default' => ', ');
+
+    return $options;
+  }
+  
+  /**
+   * Defines the options form (form available to admin when they add a field to a view)
+   */
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+    $form['type'] = array(
+      '#type' => 'radios',
+      '#title' => t('Display type'),
+      '#options' => array(
+        'ul' => t('Unordered list'),
+        'ol' => t('Ordered list'),
+        'separator' => t('Simple separator'),
+      ),
+      '#default_value' => $this->options['type'],
+    );
+
+    $form['separator'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Separator'),
+      '#default_value' => $this->options['separator'],
+      '#process' => array('views_process_dependency'),
+      '#dependency' => array('radio:options[type]' => array('separator')),
+    );
+  }
+  
+  /**
+   * Determines whether the current field is aggregated or not
+   * Note: The parent::query() takes care of adding the field to the query, etc.
+   */
+  function query () {
+    parent::query();
+    
+    $table = $this->query->get_table_info($this->table);
+    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
+      $this->aggregated = TRUE;
+    } else {
+      $this->aggregated = FALSE;
+    }
+  }
+  
+  /**
+   * Render the field.
+   *
+   * Note: Checks to see if we have an array or simple field. If we have an array, then
+   *   split it up and render each part using the parent render functionality.
+   *
+   * @param $values
+   *   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);
+    }
+    
+  }
+  
+  /**
+   * 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();
+    }
+  }
+}

+ 112 - 0
base/tripal_core/views/handlers/chado_views_handler_field_date.inc

@@ -0,0 +1,112 @@
+<?php
+
+class chado_views_handler_field_date extends views_handler_field_date {
+
+  /**
+   * Defines the defaults for the options form
+   */
+  function option_definition() {
+    $options = parent::option_definition();
+
+    $options['type'] = array('default' => 'separator');
+    $options['separator'] = array('default' => ', ');
+
+    return $options;
+  }
+  
+  /**
+   * Defines the options form (form available to admin when they add a field to a view)
+   */
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+    $form['type'] = array(
+      '#type' => 'radios',
+      '#title' => t('Display type'),
+      '#options' => array(
+        'ul' => t('Unordered list'),
+        'ol' => t('Ordered list'),
+        'separator' => t('Simple separator'),
+      ),
+      '#default_value' => $this->options['type'],
+    );
+
+    $form['separator'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Separator'),
+      '#default_value' => $this->options['separator'],
+      '#process' => array('views_process_dependency'),
+      '#dependency' => array('radio:options[type]' => array('separator')),
+    );
+  }
+  
+  /**
+   * Determines whether the current field is aggregated or not
+   * Note: The parent::query() takes care of adding the field to the query, etc.
+   */
+  function query () {
+    parent::query();
+    
+    $table = $this->query->get_table_info($this->table);
+    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
+      $this->aggregated = TRUE;
+    } else {
+      $this->aggregated = FALSE;
+    }
+  }
+  
+  /**
+   * Render the field.
+   *
+   * Note: Checks to see if we have an array or simple field. If we have an array, then
+   *   split it up and render each part using the parent render functionality.
+   *
+   * @param $values
+   *   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);
+    }
+    
+  }
+  
+  /**
+   * 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();
+    }
+  }
+}

+ 112 - 0
base/tripal_core/views/handlers/chado_views_handler_field_markup.inc

@@ -0,0 +1,112 @@
+<?php
+
+class chado_views_handler_field_markup extends views_handler_field_markup {
+
+  /**
+   * Defines the defaults for the options form
+   */
+  function option_definition() {
+    $options = parent::option_definition();
+
+    $options['type'] = array('default' => 'separator');
+    $options['separator'] = array('default' => ', ');
+
+    return $options;
+  }
+  
+  /**
+   * Defines the options form (form available to admin when they add a field to a view)
+   */
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+    $form['type'] = array(
+      '#type' => 'radios',
+      '#title' => t('Display type'),
+      '#options' => array(
+        'ul' => t('Unordered list'),
+        'ol' => t('Ordered list'),
+        'separator' => t('Simple separator'),
+      ),
+      '#default_value' => $this->options['type'],
+    );
+
+    $form['separator'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Separator'),
+      '#default_value' => $this->options['separator'],
+      '#process' => array('views_process_dependency'),
+      '#dependency' => array('radio:options[type]' => array('separator')),
+    );
+  }
+  
+  /**
+   * Determines whether the current field is aggregated or not
+   * Note: The parent::query() takes care of adding the field to the query, etc.
+   */
+  function query () {
+    parent::query();
+    
+    $table = $this->query->get_table_info($this->table);
+    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
+      $this->aggregated = TRUE;
+    } else {
+      $this->aggregated = FALSE;
+    }
+  }
+  
+  /**
+   * Render the field.
+   *
+   * Note: Checks to see if we have an array or simple field. If we have an array, then
+   *   split it up and render each part using the parent render functionality.
+   *
+   * @param $values
+   *   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);
+    }
+    
+  }
+  
+  /**
+   * 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();
+    }
+  }
+}

+ 112 - 0
base/tripal_core/views/handlers/chado_views_handler_field_math.inc

@@ -0,0 +1,112 @@
+<?php
+
+class chado_views_handler_field_math extends views_handler_field_math {
+
+  /**
+   * Defines the defaults for the options form
+   */
+  function option_definition() {
+    $options = parent::option_definition();
+
+    $options['type'] = array('default' => 'separator');
+    $options['separator'] = array('default' => ', ');
+
+    return $options;
+  }
+  
+  /**
+   * Defines the options form (form available to admin when they add a field to a view)
+   */
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+    $form['type'] = array(
+      '#type' => 'radios',
+      '#title' => t('Display type'),
+      '#options' => array(
+        'ul' => t('Unordered list'),
+        'ol' => t('Ordered list'),
+        'separator' => t('Simple separator'),
+      ),
+      '#default_value' => $this->options['type'],
+    );
+
+    $form['separator'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Separator'),
+      '#default_value' => $this->options['separator'],
+      '#process' => array('views_process_dependency'),
+      '#dependency' => array('radio:options[type]' => array('separator')),
+    );
+  }
+  
+  /**
+   * Determines whether the current field is aggregated or not
+   * Note: The parent::query() takes care of adding the field to the query, etc.
+   */
+  function query () {
+    parent::query();
+    
+    $table = $this->query->get_table_info($this->table);
+    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
+      $this->aggregated = TRUE;
+    } else {
+      $this->aggregated = FALSE;
+    }
+  }
+  
+  /**
+   * Render the field.
+   *
+   * Note: Checks to see if we have an array or simple field. If we have an array, then
+   *   split it up and render each part using the parent render functionality.
+   *
+   * @param $values
+   *   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);
+    }
+    
+  }
+  
+  /**
+   * 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();
+    }
+  }
+}

+ 112 - 0
base/tripal_core/views/handlers/chado_views_handler_field_numeric.inc

@@ -0,0 +1,112 @@
+<?php
+
+class chado_views_handler_field_numeric extends views_handler_field_numeric {
+
+  /**
+   * Defines the defaults for the options form
+   */
+  function option_definition() {
+    $options = parent::option_definition();
+
+    $options['type'] = array('default' => 'separator');
+    $options['separator'] = array('default' => ', ');
+
+    return $options;
+  }
+  
+  /**
+   * Defines the options form (form available to admin when they add a field to a view)
+   */
+  function options_form(&$form, &$form_state) {
+    parent::options_form($form, $form_state);
+    $form['type'] = array(
+      '#type' => 'radios',
+      '#title' => t('Display type'),
+      '#options' => array(
+        'ul' => t('Unordered list'),
+        'ol' => t('Ordered list'),
+        'separator' => t('Simple separator'),
+      ),
+      '#default_value' => $this->options['type'],
+    );
+
+    $form['separator'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Separator'),
+      '#default_value' => $this->options['separator'],
+      '#process' => array('views_process_dependency'),
+      '#dependency' => array('radio:options[type]' => array('separator')),
+    );
+  }
+  
+  /**
+   * Determines whether the current field is aggregated or not
+   * Note: The parent::query() takes care of adding the field to the query, etc.
+   */
+  function query () {
+    parent::query();
+    
+    $table = $this->query->get_table_info($this->table);
+    if (preg_match('/aggregator/',$table['join']->definition['handler'])) {
+      $this->aggregated = TRUE;
+    } else {
+      $this->aggregated = FALSE;
+    }
+  }
+  
+  /**
+   * Render the field.
+   *
+   * Note: Checks to see if we have an array or simple field. If we have an array, then
+   *   split it up and render each part using the parent render functionality.
+   *
+   * @param $values
+   *   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);
+    }
+    
+  }
+  
+  /**
+   * 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();
+    }
+  }
+}