I have the need to create an arbitrary amount of reports in many different file formats. Most of the formats I am able to use Smarty to template the output. However, outputting to Excel and PDF complicate things and require the use of FPDF or TCPDF and PHPExcel.
I am trying to figure out the best way to organize my classes via one or more design patterns (if possible).
Output formats: Text - Smarty Text (w/PCL formatting) - Smarty CSV - Smarty HTML - Smarty Excel - PHPExcel PDF - FPDF / TCPDF
These formats need to be able to be in memory for streaming or written to file for later use.
The only thing that is consistent across all reports is that they need data and up until the addition of PDF and Excel support, a template. Currently I have a Report class that has an abstract method called getData(). Each subclass (e.g. SpecificReport) gets the data it needs and stores it in a class property for binding to a template etc.
Each report needs to be available in all formats.
The Report class handles the output at the moment, but adding support for Excel and PDF is making that impossible. There is a lot more than just binding the data to a template like with Smarty. Each report requires specific code. I suppose I could just overload those methods in each report subclass.
Has anyone encountered a similar task? Any advice is welcome.