diff --git a/views/webform.views.inc b/views/webform.views.inc index dab3fe3..ef8bb58 100644 --- a/views/webform.views.inc +++ b/views/webform.views.inc @@ -123,6 +123,10 @@ function webform_views_data() { 'handler' => 'views_handler_sort_date', ), ); + // Add date module support, if present. + if (module_exists('date')) { + $data['webform_submissions']['submitted']['filter']['handler'] = 'date_views_filter_handler_simple'; + } // remote_addr $data['webform_submissions']['remote_addr'] = array( @@ -171,6 +175,71 @@ function webform_views_data() { ), ); + // Relation to webform data. + $data['webform_submissions']['data'] = array( + 'title' => t('Data'), + 'help' => t('Relates to a webform submission data'), + 'real field' => 'sid', + 'relationship' => array( + 'handler' => 'webform_handler_relationship_submission_data', + 'base' => 'webform_submitted_data', + 'base field' => 'sid', + 'label' => t('Submission Data'), + ), + ); + + /** + * Submission data table definitions. + */ + $data['webform_submitted_data']['table']['group'] = t('Webform submission data'); + $data['webform_submitted_data']['data'] = array( + 'table' => 'webform_submitted_data', + 'title' => t('Data field (raw)'), + 'help' => t('The submitted data value as raw output string.'), + 'real field' => 'data', + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + 'field' => array( + 'handler' => 'views_handler_field_xss', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // data_formatted + $data['webform_submitted_data']['data_formatted'] = array( + 'title' => t('Data field (formatted)'), + 'help' => t('The submitted data in component specific format.'), + 'real field' => 'data', + 'field' => array( + 'handler' => 'webform_handler_field_submission_data', + ), + ); + + // no + $data['webform_submitted_data']['no'] = array( + 'title' => t('Delta'), + 'help' => t('The delta value of the submitted data in a multi value component.'), + 'real field' => 'no', + 'argument' => array( + 'handler' => 'views_handler_argument_numeric', + ), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + return $data; } @@ -273,6 +342,10 @@ function webform_views_handlers() { 'parent' => 'views_handler_field', 'file' => 'webform_handler_field_submission_link.inc', ), + 'webform_handler_field_submission_data' => array( + 'parent' => 'views_handler_field', + 'file' => 'webform_handler_field_submission_data.inc', + ), 'webform_handler_field_submission_count' => array( 'parent' => 'views_handler_field', 'file' => 'webform_handler_field_submission_count.inc', @@ -303,6 +376,10 @@ function webform_views_handlers() { 'parent' => 'views_handler_filter_boolean_operator', 'file' => 'webform_handler_filter_webform_status.inc', ), + 'webform_handler_relationship_submission_data' => array( + 'parent' => 'views_handler_relationship', + 'file' => 'webform_handler_relationship_submission_data.inc', + ), ), ); } \ No newline at end of file diff --git a/views/webform_handler_field_submission_data.inc b/views/webform_handler_field_submission_data.inc new file mode 100644 index 0000000..cf86523 --- /dev/null +++ b/views/webform_handler_field_submission_data.inc @@ -0,0 +1,98 @@ +additional_fields['nid'] = 'nid'; + $this->additional_fields['cid'] = 'cid'; + $this->additional_fields['no'] = 'no'; + } + + /** + * Definition and defaults for the option form/values. + */ + function option_definition() { + $options = parent::option_definition(); + $options['format'] = array('default' => 'html'); + $options['display_label'] = array('default' => FALSE); + return $options; + } + + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + // Provide the selection for the display format. + $options['format'] = array( + '#type' => 'select', + '#title' => t('Display format'), + '#options' => array( + 'html' => 'html', + 'plain' => 'plain', + '#required' => TRUE, + ), + '#default_value' => $this->options['format'], + ); + + // Title display settings. + $form['display_label'] = array( + '#type' => 'checkbox', + '#title' => t('Display label'), + '#default_value' => $this->options['display_label'], + '#description' => t('Show the label of the component as it is provied by webform.'), + ); + } + + /** + * Pre render the query, to get the + */ + function pre_render($values) { + $this->component_instances = webform_component_instances(); + // @TODO: maybe we add a multi value pre query here? + } + + /** + * Render the field. + * + * @param $row + * The row retrieved + */ + function render($row) { + $value = $this->get_value($row); + if (isset($value)) { + $nid = $this->get_value($row, 'nid'); + $cid = $this->get_value($row, 'cid'); + // @TODO: use a delta = 0 on every item? + $delta = $this->get_value($row, 'no'); + $component = $this->component_instances["$nid-$cid"]; + + // Remove display label. + if (empty($this->options['display_label'])) { + $component['name'] = ''; + } + + $format = $this->options['format']; + $render = webform_component_invoke($component['type'], 'display', $component, array($delta => $value), $format); + // @TODO: add a theme layer? + return render($render); + } + } +} \ No newline at end of file diff --git a/views/webform_handler_relationship_submission_data.inc b/views/webform_handler_relationship_submission_data.inc new file mode 100644 index 0000000..38e1e60 --- /dev/null +++ b/views/webform_handler_relationship_submission_data.inc @@ -0,0 +1,154 @@ + NULL); + $options['components'] = array('default' => array()); + return $options; + } + + /** + * Extends the relationship options form. + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + $component_types = $this->get_webform_component_types(); + + $form['component_type'] = array( + '#title' => t('Component type'), + '#type' => 'select', + '#description' => t('Select component type for this relationship'), + '#required' => TRUE, + '#default_value' => $this->options['component_type'], + '#options' => $component_types, + ); + + ctools_include('dependent'); + foreach ($component_types as $type => $label) { + $id = drupal_html_id('options-components-'. $type); + + $options = $this->get_webform_component_instances($type); + // If there are no instances, we remove the component from selection. + if (empty($options)) { + unset($form['component_type']['#options'][$type]); + if ($form['component_type']['#default_value'] == $type) { + $form['component_type']['#default_value'] = NULL; + } + } + else { + $form['components'][$type] = array( + '#title' => t('Components: %label', array('%label' => $label)), + '#prefix' => '