This is in response to this request for a patch to provide useful data structures to third party charting or analysis modules. This provides another hook that can be invoked by other modules: _webform_analysis_data_*component*, to all core webform components that can provide analysis data. This is invoked via "webform_component_invoke('*component_name*', 'analysis_data', $component, $sids);";

For most components, all this does is proxy the main _webform_analysis_*component* function, and returns a two-keyed array containing the original component along with the result from _webform_analysis_*component*. The exception is the grid component, which provides all of the constituent questions and answers in the array returned from _webform_analysis_data_grid.

This unifies the format of data returned from each question so it can be more easily analyzed, and makes the grid component actually return data, not rendered HTML. I will be pushing an updated snapshot of my sandbox project that implements (but does not require) these new found hooks very soon. I rolled these against the webform release (3.16?) that came out today. Let me know if you need anything else. Thanks!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

Thanks hotspoons! I'd prefer to flip the logic around though, and have the new _webform_analysis_data_* functions contain the SQL queries and logic generation, then have the existing _webform_analysis_* functions call those. That should (hopefully) make it so we don't have two functions doing SQL queries/logic generation for the Grid (and other advanced) components.

The end result of the called functions would remain the same as the current patch, I'd just like to move the logic around so that analysis_data hooks are the source of the data, and the existing analysis hook just does the formatting (if necessary).

hotspoons’s picture

Quicksketch, your logic makes perfect sense. I'll get this done in the coming week. Stay tuned...

quicksketch’s picture

Fantastic, thanks hotspoons. I'm stoked for a real charting solution for Webform. There's a planned release for this coming Wednesday (I know it's really soon after 3.16) to address an issue I forgot about plus a few minor fixes others have found with the new version.

quicksketch’s picture

Version: 7.x-3.16 » 7.x-4.x-dev
Status: Needs review » Needs work

This feature needs some work per #1. I'm still very interested in charting solutions for Webform even though not a lot of progress has been made on that front recently.

quicksketch’s picture

Status: Needs work » Needs review
FileSize
27.91 KB

I revised this patch's approach by simply reusing _webform_analysis_[component]() and having it returned structured data that is suitable for charting. We basically already were creating chartable data, we just were shoving in non-chartable data at the same time. To fix this problem, I've split the return array into 3 pieces (per the new documentation):

+ *   An array containing one or more of the following keys:
+ *   - table_rows: If this component has numeric data that can be represented in
+ *     a grid, return the values here. This array assumes a 2-dimensional
+ *     structure, with the first value being a label and subsequent values
+ *     containing a decimal or integer.
+ *   - table_header: If this component has more than a single set of values,
+ *     include a table header so each column can be labeled.
+ *   - other_data: If your component has non-numeric data to include, such as
+ *     a description or link, include that in the other_data array. Each item
+ *     may be a string or an array of values that matches the number of columns
+ *     in the table_header property.

So we don't actually need to change any of our current analysis callbacks at all. They all generate the needed data already. I didn't feel the need for a new component-hook for these things, since we can run the values through alter hooks and the theme layer. Besides changing the return value, this patch introduces:

  • hook_webform_analysis_alter()
  • hook_webform_analysis_component_data_alter()
  • webform-analysis.tpl.php
  • webform-analysis-component.tpl.php

The templates both can be made granular (webform-analysis--[nid].tpl.php) and the alter hooks allow for expansion by other module. Most specifically this has #282885: Combining webform with charts in mind, allowing us to extend the existing analysis pages with charts (and reuse the existing data at the same time).

Dom.’s picture

Hi !

I'm taking over the module maintenance of Webform Chart. Please find it here:
http://drupal.org/project/webform_chart

I am very interested by this latest patch !

Miro.

quicksketch’s picture

Hi Miro! I've got an update to this patch that fixes a few issues I've discovered. At the same time, I'm working on the "webform_charts" module. Maybe we can work together instead of separately? My module is based on http://drupal.org/project/charts, as opposed to your project with (I assume) would be built on top of the "chart" module. I'll try to get my work up somewhere public today, as I've pretty much got a full working module at this point, I'm just working out kinks.

Dom.’s picture

Hi !

I will also commit as an alpha or beta version when ready. I have the following features almost ready:
- hookable to be used in conjunction with any charting API
- bundlers included for chart, charts, visualize and a custom google_visualization_api module. (I don't know yet which bundles will be included in the initial commit, I'm trying various APIs).
- the charting library to use can be choosen separately for each webform of your site
- two configuration mode: either global per webform or per field of your webform
- in per field mode, the chart type (pie, bar, etc..) can be configure for each field
- the chart result page have view/admin permissions
- the result page if build using various template files, so you can easily theme it.

Here is what I have almost ready for now and I planned to comit it soon.

quicksketch’s picture

Revised patch that fixes a few issues:

- Select list "other" options were not being displayed properly on the extended detail page.
- The theming was incorrectly outputting the title of each component one level too deep in the $analysis renderable.

Overall I think this patch is good to go. I've been testing it for the past couple weeks with no additional changes.

quicksketch’s picture

Status: Needs review » Fixed

Committed and pushed to 7.x-4.x.

Dom.’s picture

Thanks a lot. I have also release my work on Webform Chart a 7.x-1.0-rc1 ! I will now try using your new hooks to add various chart analysis for each component !

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.