views_handler_filter_chado_boolean.inc

Purpose: This handler provides a TRUE/FALSE or YES/NO select for chado fields of type boolean (includes both 0/1 and t/f booleans)

File

tripal_views/views/handlers/deprecated/views_handler_filter_chado_boolean.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Purpose: This handler provides a TRUE/FALSE or YES/NO select for chado fields
  5. * of type boolean (includes both 0/1 and t/f booleans)
  6. *
  7. * @ingroup views_filter_handlers
  8. * @ingroup tripal_core
  9. */
  10. class views_handler_filter_chado_boolean extends views_handler_filter_boolean_operator {
  11. /**
  12. * Checks if this field uses 0/1 or t/f
  13. * @todo Implement LIMIT 1 functionality for tripal_core_chado_select().
  14. */
  15. function init(&$view, $options) {
  16. parent::init($view, $options);
  17. $results = tripal_core_chado_select($this->table, array($this->field), array());
  18. $this->boolean_type_tf = FALSE;
  19. if (preg_match('/[tf]/', $results[0]->{$this->field})) {
  20. $this->boolean_type_tf = TRUE;
  21. }
  22. }
  23. /**
  24. * This function sets the options array for the select.
  25. * If we are using a t/f boolean then the options need to evaluate to either t or f
  26. * Otherwise, (0/1 boolean) the options evaluate to 0 or 1
  27. */
  28. function get_value_options() {
  29. if ($this->boolean_type_tf) {
  30. if (isset($this->definition['type'])) {
  31. if ($this->definition['type'] == 'yes-no') {
  32. $this->value_options = array('t' => t('Yes'), 'f' => t('No'));
  33. }
  34. if ($this->definition['type'] == 'on-off') {
  35. $this->value_options = array('t' => t('On'), 'f' => t('Off'));
  36. }
  37. }
  38. // Provide a fallback if the above didn't set anything.
  39. if (!isset($this->value_options)) {
  40. $this->value_options = array('t' => t('True'), 'f' => t('False'));
  41. }
  42. }
  43. else { //end of t/f boolean
  44. if (isset($this->definition['type'])) {
  45. if ($this->definition['type'] == 'yes-no') {
  46. $this->value_options = array(1 => t('Yes'), 0 => t('No'));
  47. }
  48. if ($this->definition['type'] == 'on-off') {
  49. $this->value_options = array(1 => t('On'), 0 => t('Off'));
  50. }
  51. }
  52. // Provide a fallback if the above didn't set anything.
  53. if (!isset($this->value_options)) {
  54. $this->value_options = array(1 => t('True'), 0 => t('False'));
  55. }
  56. } //end of 0/1 boolean
  57. }
  58. function query() {
  59. $this->ensure_my_table();
  60. $where = "$this->table_alias.$this->real_field ";
  61. if ($this->boolean_type_tf) {
  62. if (preg_match('/f/', $this->value)) {
  63. $where .= "= 'f'";
  64. }
  65. else {
  66. $where .= "= 't'";
  67. }
  68. $this->query->add_where($this->options['group'], $where);
  69. }
  70. else {
  71. if (empty($this->value)) {
  72. $where .= '= 0';
  73. if ($this->accept_null) {
  74. $where = '(' . $where . " OR $this->table_alias.$this->real_field IS NULL)";
  75. }
  76. }
  77. else {
  78. $where .= '<> 0';
  79. }
  80. $this->query->add_where($this->options['group'], $where);
  81. }
  82. }
  83. }

Related topics