webform_handler_filter_submission_data.inc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * Definition of webform_handler_filter_submission_data.
  4. *
  5. * Extended version of the string filter handler specialized for Webform values.
  6. *
  7. * @ingroup views_filter_handlers
  8. */
  9. class webform_handler_filter_submission_data extends views_handler_filter_string {
  10. /**
  11. * Add to the list of operators.
  12. *
  13. * This kind of construct makes it relatively easy for a child class to add or
  14. * remove functionality by overriding this function and adding/removing items
  15. * from this array.
  16. */
  17. public function operators() {
  18. $operators = parent::operators();
  19. // Add additional operators for date/time ranges.
  20. $operators['>'] = array(
  21. 'title' => t('Greater than'),
  22. 'short' => t('>'),
  23. 'method' => 'op_greater_than',
  24. 'values' => 1,
  25. );
  26. $operators['<'] = array(
  27. 'title' => t('Less than'),
  28. 'short' => t('<'),
  29. 'method' => 'op_less_than',
  30. 'values' => 1,
  31. );
  32. return $operators;
  33. }
  34. /**
  35. * Build strings from the operators() for 'select' options.
  36. */
  37. public function operator_options($which = 'title') {
  38. $options = parent::operator_options($which);
  39. // Adjust the exposed filter options based on the component selected.
  40. if ($which === 'title') {
  41. $nid = $this->view->relationship[$this->options['relationship']]->options['webform_nid'];
  42. $cid = $this->view->relationship[$this->options['relationship']]->options['webform_cid'];
  43. if ($nid && $node = $node = node_load($nid)) {
  44. module_load_include('inc', 'webform', 'includes/webform.components');
  45. $component = $node->webform['components'][$cid];
  46. if (webform_component_feature($component['type'], 'views_range')) {
  47. $options['='] = t('Is');
  48. $options['!='] = t('Is not');
  49. $options['>'] = t('After');
  50. $options['<'] = t('Before');
  51. $options = array_intersect_key($options, array('=' => '=', '!=' => '!=', '>' => '>', '<' => '<'));
  52. }
  53. }
  54. }
  55. return $options;
  56. }
  57. /**
  58. *
  59. */
  60. public function operator_values($values = 1) {
  61. $options = array();
  62. foreach ($this->operators() as $id => $info) {
  63. if (isset($info['values']) && $info['values'] == $values) {
  64. $options[] = $id;
  65. }
  66. }
  67. return $options;
  68. }
  69. /**
  70. * Provide a simple textfield for equality.
  71. */
  72. public function value_form(&$form, &$form_state) {
  73. // @todo: Adjust the exposed filter form based on component form.
  74. return parent::value_form($form, $form_state);
  75. }
  76. /**
  77. *
  78. */
  79. public function op_greater_than($field) {
  80. $this->query->add_where($this->options['group'], $field, $this->value, '>');
  81. }
  82. /**
  83. *
  84. */
  85. public function op_less_than($field) {
  86. $this->query->add_where($this->options['group'], $field, $this->value, '<');
  87. }
  88. }