I have a custom module that's a multi-page form that collects one value from a user for each page of the form (3 pages, 3 total values collected). On the final page of the form (the recommendations page) it displays recommended resources from our database that match the user's selections. Because we need to put all 'timely events' first, followed by 'quick study' events, and finally 'deep dive' events the recommendations page uses 3 SQL queries to output the data to the screen.

All that works fine. However, now we'd like to add some way to allow the user to EXPORT the recommendations they see on the screen to a CSV file (or some other type) with an 'export' link. That's why I'm here asking you guys...does anyone know a great way to make this happen?

1 Answer
1

If it would be an option to create that "report" on your recommendations page using the Forena module, then it would be just a matter of specifying what kind of hyperlinks you want to make available for performing such "export". These hyperlinks correspond to various supported "formats", such as: CSV, PDF, XLS, XML, DOC, HTML ...

To get an idea of how that would look like, visit the demo site samples. Checkout the samples such as the Master detail with nested blocks. There is a link "PDF" (upper right), which in this case would "export" the results there in a PDF doc. Though it could as well (or "also") be a CSV, XLS, DOC, etc (if that is what the "report designer" would have selected as one of the allowed/enabled export formats).

For more details about Forena, 2 types of documentation are available:

Forena samples - use the link 'Reporting samples' or visit relative link /reports/samples (these samples are fully functional, so make sure to experiment a bit with it, such as the drill downs available on the SVG Graph sample).

Access to reports (and export links):

Who can "Access" a specific report is a matter of granting access to the "data block" (= results of an SQL query). While access to those (export) links is a matter of being able to access the report (via its data block). So if "Anonymous" is allowed to access some data block, then those links on its report can be accessed also (and hence perform a save/export also). Those PDF links in the demo site samples are an illustration of that (since you visit that site anonymous).

Extra feature: yes or no showing a link for (eg) CSV or PDF export and (eg) not for XLS is something you can specify when designing / creating a report. Though that yes or no then applies to anybody.

Reports audience:

The "audience" of reports can be however you want it to be, which is typically implemented using what's called report "categories". As an illustration (based on various reports delivered out-of-the-box):

the Forena 'Sample' reports are a set of reports with a specific category (= 'Samples' also), for which Anonymous users are granted access also.

the Forena 'Drupal Admin' reports is another set, with some other category, and which can only be accessed by users with role "admin". So if somebody installs Forena in some Drupal site, and they have the "admin" role, then they get access to all sorts of Drupal admin related reports (like watchdog reports) in their "own" environment. Some of those reports are:

Active Users - A variation of D7's admin/people, including hyperlinks to the Logs for User report.

Logs for User - Most recent watchdog log entries for a user (specified as a report parameter).

Role Details - A table displaying all users for a Drupal role (specified as a report parameter), and the Drupal permissions granted to them, with for each user hyperlinks to either view or edit the user's profile.

this looks interesting; I'll explore it more. Would this module allow an anonymous user to be able to save their own report and export it? That's what I want...a user customized report for anonymous users (based on their form responses). I'm a little worried this module is only for admins or admin-created reports for users (ie. no interaction involved with users).
– SageJul 11 '15 at 0:32

it makes sense, thank you. I do have another follow up question however: will this module allow for user-created reports using parameters they set by selecting options in my form? (ie. can I plug php variables into parameters fields in forena reports so they read what the user selected in my custom module?)
– SageJul 14 '15 at 19:13

Thank you for the update, looks like we're going in the right direction to get your question solved. I'm assuming that for that "using parms they set" it should be possible also. However I'd first want to better understand what you mean with those php variables. E.g. in which format are they available at that point, like did you save those parms by then in some Drupal table? If not how "are" they available?
– Pierre.VriensJul 14 '15 at 19:25

Great, so the module is a multi-page form where users enter their selections. Once they've made them they submit the values which get send to a recommendations page (the code above). The values they selected are, right now being stored in session variables (see the beginning of the code above) ... there are only 3 variables. The SQL statements (later in the code above) then use those session variables to compare to the data in the DB to determine which records to display to the user (their 'recommendations'). So, the values being selected are being saved as sessions only.
– SageJul 14 '15 at 19:31

I suppose so. So I create a report, setup the data block in a .sql file in a custom dir on my server (with the sql and params to call) and then call it from structure > reports? I tried this and followed the videos. I have my sql in sites/files/recs/test.sql and I setup my forena report (config > forena) so custom data block repo is set to the above path. I then created a new report in structure > forena reports and tried to create a new sql query to map to my sql file I setup but it can't seem to find it anywhere. I type in 're' in source and it only gives registry or reg_file.
– SageJul 14 '15 at 22:04