I have built a report for an client account that shows payments and charges with totals. I am now adding an export button using the PHPExport module.
As I already built the data to display in the web report, it seems inefficient to build it again if the user wants to export it. So I am thinking of building the arrays ($header and $data) needed for the report at the same time as I build the report page to display in the browser.
In order to then have access to these arrays in my export function, which would be called by a form submit, I will need to store them in the database (is that right?). Then, if the user submits and export request, I retrieve the arrays and pass them to the
phpexcel_export() function and Robert's your mother's brother.
When the user then navigates away from the report, I will need to tidy up, by which I mean delete the arrays from the database. Do I use the onBeforeUnload API to achieve this? It seems from the api page to be little used.
Or am I approaching this from the wrong angle? Is there another way to persist the arrays from producing the page to submitting the export request from the page?