I have a client that needs to be able to view the analysis report of a webform but with certain filters for respondents in place (eg. all users in a department, all users that answered yes to quenstion N etc.) (D5 btw)
I'm quite up to writing a module to allow them to do the filters in the user interface, but for it to work I'll need to modify the _webform_analysis_rows_XXXX for each component. Before I do that I'd like to get input on what I intend to do so that it is likely to be accepted as a path to the module.
What I'm thinking is to add an additional parameter $whereclause to each analysis function with default "".
If the whereclause isn't "" you AND it with the current query. Then in the new module I can do a variantion on the code that currently generates the analysis.
Will this be a good way of approaching it?
Anton
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | webform-sidfilter-2.6.patch | 14.1 KB | asciikewl |
| #12 | webform-sidfilter-2.4.patch | 14.12 KB | asciikewl |
| #11 | webform-2.3-sidfilter.patch | 14 KB | asciikewl |
| #8 | webform-2.3-sidfilter.patch | 10.81 KB | asciikewl |
| #1 | webform-analysis-filter.diff | 10.15 KB | asciikewl |
Comments
Comment #1
asciikewl commentedNo feedback and the client couldn't wait, so I've done a patch that adds an optional filter to all the analysis functions.
You can then render an analysis for a partial group of users with:
$filter = "sid in (select sid from webform_submissions where uid in ($uidlist) and nid=$nid)";
$output = webform_results_analysis($node,$filter);
Comment #2
quicksketchThanks AsciiKewl. I think I'd be fine with this addition, though with a few minor changes. I'd prefer the $filter argument were an array, rather than just a string, it just seems a bit hackish tacking on a raw string at the end of the query. I guess at the same time, I don't know how we'd setup such an array that would allow the flexibility of the string.
Is there anything in particular that these results are being filtered by (UID, IP address, something else?) that we could make arguments directly?
Comment #3
asciikewl commentedI was thinking about that as well ans wishing for the db api in D7 :)
In principle filtering for anything would be nice but becomes messy without being able to add tables etc.
My current use cases I filter for UID. In future I might have to filter for the result of a specific component as well. Eg. show the results of favourite color broken into male and female respondents as per question 1.
As that becomes tricky, one option I was thinking is an array with the additional where clause and maybe an additional table clause as well so you can do joins.
Leaving them strings may allow for maximum flexibility for extending the ideas in future.
The client is under pressure to get data out, so for now I'm just coding the reports. I'm pretty sure I'll get them interested in an interface in future that I can put in a separate module that allows you to do the analysis interactively. One part I just finished is being able to display Question 1 and then the analysis per group just for that question etc.
Anton
Comment #4
quicksketchI am planning on adding Views support to Webform (#273837: Views Integration for Webform), but I don't think this will be able to support the Analysis feature. Maybe it *could* if it were a very, very detailed implementation. But as-is, the analysis feature is too complicated to be included in the first-round of Views support (and it will only be for Drupal 6 anyway, since Views 1 doesn't support anything but nodes). I think for the time-being, I'd be satisfied with adding a $uid parameter alone. The addition of a free-form WHERE clause is too hackish for me and I think UID is about the only practical use-case currently. Implementing a variable array of clauses would basically be a whole query system that I don't think we need to create in Webform (especially since we have real query objects in D7, it'd just be wasted work). Plus, it'd also be a gateway patch to appease the users in #246371: Adding new permissions for accessing own webform results and deleting webform submissions. Do you think this would be an acceptable solution for you?
Comment #5
asciikewl commentedOK, I'll clean it up to use an array of uids. I think for now that is fine and a great reason to get them to move to D6 for next the round of
surveys.
so instead of the $filter parameter, I do $uids = array() and use array_vaules($uids) so you can use any keys?
Or should I leave it open and use $filters = array() and then use $filters['uids']? That way we can later add $filters['sids'] for the other use case?
Anton
Comment #6
quicksketch$filters['uids'] sounds good to me. It seems conceivable that $filters['nids'] or $filters['sids'] might be desirable later.
I was just thinking we'd need a single $uid value originally. But if you need multiple UIDs we can take this approach.
Comment #7
asciikewl commentedYes, analysis over a single uid doesn't make that much sense ;)
Excellent, I'll make up the new patch in the week.
Comment #8
asciikewl commentedOh well, took more than a week, but here goes.
After looking at how I use it, I decided to make it filter on an array of passed SIDs rather than UIDs. It is easy enough to get the SIDs from the UID where you call it and using SIDs turns out to be more general.
The next mission is to extend the Analysis report so that on certain types of fields (like select boxes) you can click to drill down and see the analysis for all submissions with that specific value for that field. I'll first to it as a separate module and if it works well and makes sense it can be merged into webform.
Comment #9
quicksketchNice, I like it. A much, much better solution to use SIDs rather than UIDs. The only change I think are minor code style changes:
Comments should be sentences:
Spacing issues:
+ $crows = $analysis_function($component,$sids);
+ $crows = $analysis_function($component, $sids);
And we should be using the secure way of writing "IN" statements using array_fill and creating placeholders. See an example in http://drupal.org/writing-secure-code
Comment #10
quicksketchComment #11
asciikewl commentedSecured and cleaned up (I hope).
Thanx for helping, I'm also learning a lot here :)
New patch attached.
Comment #12
asciikewl commentedHere is the same patch updated to patch against 2.4 (and against the current CV 5--2 branch)
What is the chance of this going into the next version?
Comment #13
quicksketchHey AsciiKewl, I'd say "pretty good" chance. The 2.5 version needs to come out fairly quickly to fix a few bugs in the 2.4 release, and I think it'd be great to include this feature. Especially since it'd make #246371: Adding new permissions for accessing own webform results and deleting webform submissions possible at some later point. I'm getting busy again quickly, but I'll review this as soon as I can.
Comment #14
asciikewl commentedHere is an updated patch for 5.x-2.6.
Comment #15
quicksketchThanks AsciiKewl, you're a champ for rerolling and sticking with my absences. Committed to both 5 and 6 branches. You rock, thanks for the patches. :)