chado_views_handler_field_boolean.inc

A chado wrapper for the views_handler_field_boolean.

Handles fields which may be aggregated during the chado join process. This field will render an aggregated field as a pre_rendered list and will dynamically detect whether the field is aggregated or not.

File

tripal_views/views/handlers/chado_views_handler_field_boolean.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * A chado wrapper for the views_handler_field_boolean.
  5. *
  6. * Handles fields which may be aggregated during the chado join process. This field
  7. * will render an aggregated field as a pre_rendered list and will dynamically detect
  8. * whether the field is aggregated or not.
  9. */
  10. class chado_views_handler_field_boolean extends views_handler_field_boolean {
  11. function init(&$view, $options) {
  12. include_once('chado_wrapper_functions.inc');
  13. parent::init($view, $options);
  14. }
  15. /**
  16. * Defines the defaults for the options form
  17. */
  18. function option_definition() {
  19. $options = parent::option_definition();
  20. $options['type'] = array('default' => 'separator');
  21. $options['separator'] = array('default' => ', ');
  22. return $options;
  23. }
  24. /**
  25. * Defines the options form (form available to admin when they add a field to a view)
  26. */
  27. function options_form(&$form, &$form_state) {
  28. parent::options_form($form, $form_state);
  29. $form['type'] = array(
  30. '#type' => 'radios',
  31. '#title' => t('Display type'),
  32. '#options' => array(
  33. 'ul' => t('Unordered list'),
  34. 'ol' => t('Ordered list'),
  35. 'separator' => t('Simple separator'),
  36. ),
  37. '#default_value' => $this->options['type'],
  38. );
  39. $form['separator'] = array(
  40. '#type' => 'textfield',
  41. '#title' => t('Separator'),
  42. '#default_value' => $this->options['separator'],
  43. '#process' => array('views_process_dependency'),
  44. '#dependency' => array('radio:options[type]' => array('separator')),
  45. );
  46. }
  47. /**
  48. * Determines whether the current field is aggregated or not
  49. * Note: The parent::query() takes care of adding the field to the query, etc.
  50. */
  51. function query() {
  52. parent::query();
  53. $this->aggregated = chado_wrapper_is_aggregated_by_join($this);
  54. }
  55. /**
  56. * Splits the aggregated values up for use in rendering
  57. */
  58. function pre_render(&$values) {
  59. // further check the results to see if this field is a postgresql array
  60. $this->aggregated = chado_wrapper_is_aggregated_by_result($this, $values);
  61. // Split Aggregated Results
  62. chado_wrapper_split_array_agg_results($this, $values);
  63. }
  64. /**
  65. * Render the field.
  66. *
  67. * Note: Checks to see if we have an array or simple field. If we have an array, then
  68. * split it up and render each part using the parent render functionality.
  69. *
  70. * @param $values
  71. * The values retrieved from the database.
  72. */
  73. function render($values) {
  74. // check to see if this is a t/f boolean field or a 1/0 boolean field
  75. // parent render expects 1/0 so need to translate to that form before rendering
  76. if (!is_array($values->{$this->field_alias})) {
  77. if (!preg_match('/[01]/', $values->{$this->field_alias})) {
  78. if (preg_match('/^[tT]/', $values->{$this->field_alias})) {
  79. $values->{$this->field_alias} = 1;
  80. }
  81. elseif (preg_match('/^[fF]/', $values->{$this->field_alias})) {
  82. $values->{$this->field_alias} = 0;
  83. }
  84. }
  85. }
  86. else {
  87. if (!preg_match('/[01]/', $values->{$this->field_alias}[0])) {
  88. foreach ($values->{$this->field_alias} as $k => $v) {
  89. if (preg_match('/^[tT]/', $v)) {
  90. $values->{$this->field_alias}[$k] = 1;
  91. }
  92. elseif (preg_match('/^[fF]/', $v)) {
  93. $values->{$this->field_alias}[$k] = 0;
  94. }
  95. }
  96. }
  97. }
  98. return chado_wrapper_render_items($this, $values);
  99. }
  100. function parent_render($val) {
  101. return parent::render($val);
  102. }
  103. }