My second proposal to improve tablelib is to have a third way to add data to a table.
Most tables are constructed from an array of data returned by a sql query.
I propose that we have a method on flexible_table, get_data();
get_data can be called after the columns array is set.
It will call a virtual private method on itself to construct the sql and fetch any data needed from the db or elsewhere.
Then it will iterate through the data and :
- For each column in the array get_data will call a method on the object passed to it 'get_data_{$columnname}' with parameters :
- $data - a row from the returned sql and
- $download - a parameter indicating whether we are building data for download or for display.
The parameters are only for convenience. The get_data_{$columnname} can also pull data from properties on $this.
If no method get_data_{$columnname} is found then the column content is assumed to be $data->$columname. So for a simple table with just text you don't need to define get_data_{$columnname} methods at all. Or you can define them one by one after checking that the correct data is being fetched from the db.
Then people who want to use this new api for building table data need to create a child class of flexible_table overriding the virtual function to fetch data and optionally add get_data_{$columnname} methods.
some of the improvments have been done already on the item analysis report i.e. adding a HTML output and adding columns so that the data can be more useful for other software analysis