Re: Structures_DataGrid Data Sources
| From: | Olivier Guilyardi | Date: | Sun, 22 Aug 2004 01:39:50 +0000 |
| Subject: | Re: Structures_DataGrid Data Sources | ||
| References: | 1 2 3 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-32804@lists.php.net to get a copy of this message | ||
Justin Patrin wrote:
We misunderstood each other. I did not correctly express myself.- is the switch construct in Structures_DataGrid_DataSource::_detectSourceType() acceptable ? I personally think it's not. It's like using a screwdriver as hammer. But it works.I agree, it's not acceptable. An addition of a new data source would require editing of this method and that makes easy extension hard. I would suggest a two-step method (or optional one-step):
$ds =& DataGrid::createSource('dataObject', $do); $dg->bind($ds); You could add one simple check for the DS to see if it's an array and make the "old" source automatically. You could also leave the current detecting in place for those who want to use it, but make the above the preferred method. The reason I like the above method is because it requires no extra checking. You include the file, you check for the class, the instantiate the class with second param as an argument. Clean, simple, and easy to add sources to. Yes, it's a two-step process, but you could also always implement this as a shortcut: $dg->bind($do, 'dataObject');Well, all that's been thoroughly discussed with Andrew. Actually, you have many ways to bind() : either : $datagrid->bind($dataobject); or : $datagrid->bind($dataobject, null, DATAGRID_DATASOURCE_DATAOBJECT); (were null means 'no options') or the more verbose : $source = new Structures_DataGrid_DataSource_DataObject($dataobject); $source->bind($dataobject); $datagrid->bindDataSource($source); Actually, I'm the first to advocate the data source detection ;-) And well, that's not the linux kernel... How many drivers can we expect ? 15, 20 ? That's nothing. It just is smart : $datagrid->bind($dataobject); $datagrid->bind($xml); $datagrid->bind($db_result); $datagrid->bind($array); etc... Now, if you feel like optimizing, you can specify the type explicitly, using a constant : DATAGRID_DATASOURCE_ARRAY, DATAGRID_DATASOURCE_XML, etc... But this was not my point. Please look at the switch construct itself, nothing more, nothing less. To me, this is a php bug.
It doesn't matter you're a maintainer or not. We must put our efforts in common.- taking in account this new layer, how do you envisage datagrid/forms integration ? (Justin, this one's for you ;-)I haven't looked much at the source yet, but I would like to see FB used for the DO forms. Of course, I'm a maintainer, so I'm biased. ;-) We could also add a generic form renderer using HTML_QuickForm and pulling columns and such from the DataSource.
Ideally, DataGrid could use one package, similar to FormBuilder, to do all its form generation. It would pull data and meta-data from the sources through defined methods and display everything the same way. Of course, we don't have such a package. I would say we should have a "default" simple renderer and a DO specific renderer. Perhaps the DO one could be chosen automatically somehow, but we could easily make it a user's choice.Humm, all that's pretty obscure to me... What about that : How could formbuilder get plugged into the new datagrid we're working on ? This is important so that we do not make design mistakes. -- og