Re: Structures_DataGrid Data Sources
| From: | Justin Patrin | Date: | Fri, 20 Aug 2004 17:28:43 +0000 |
| Subject: | Re: Structures_DataGrid Data Sources | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-32790@lists.php.net to get a copy of this message | ||
On Fri, 20 Aug 2004 03:03:08 +0200, Olivier Guilyardi <ml@xung.org> wrote:
> Hi,
>
> Andrew Nagy wrote:
> > Many of you may have noticed the fairly long thread about Integrating
> > DB_DataObject with Structures_DataGrid. Olivier Guilyardi and I (mainly
> > Olivier) have put together an Abstract Data Source Driver class as well
> > as 4 Data Source Driver classes.
> >
> > As I am focusing the next release for SDG on beta, I hope that all who
> > are interested would take a look at the code in CVS and leave some
> > feedback.
> >
> > I think that Olivier would like to see this concept progress into a new
> > Package for combining any datasource to any type of "renderer" other
> > than just DataGrid.
>
> Some additional information :
>
> Tests and documentation :
> http://xung.org/misc/dgdo/sdg_source/test/index.html
>
> Our goal is :
>
> $datagrid->bind($source);
>
> Where source can be : a dataobject, an associative array, an xml string, a db result,
> or an rss document (more to come).
>
> The bind method is smart, it will detect the kind of data you pass to it. Like :
>
> $datagrid->bind($dataobject); or $datagrid->bind($xml);
>
> As discussed in the original "DG/DO integration" thread, the bind() method will
> establish
> a two-way connection with the source.
>
> All of that's achieved by a new layer : the Structures_DataGrid_DataSource* classes.
>
> The create() method is a factory to load a datasource driver. This is where the real
> work gets done, detection, driver instantiation and the like.
>
> The DataSource layers features drivers which are classes that extend the base
> Structures_DataGrid_DataSource abstract class, like :
>
> Structures_DataGrid_DataSource_XML,
> Structures_DataGrid_DataSource_DataObject,
> etc...
>
> All of this new layer is tested and works with php4 and php5, as you can see
> by pointing your browser to the link I provide above. (except the RSS driver,
> not tested yet).
>
> In the Structures_DataGrid_DataSource class phpdoc documentation, you can
> also read about how to create a new driver. There's a howto in the class
> description. The documentation is still pretty incomplete, though.
>
> Comments are very welcome. Andrew and I have been discussing a lot on
> the design and implementation. Some of the questions :
>
> - if we are to raise errors from constructors, is PEAR::raiseError()
> sufficient ? I personally consider that it is not, because it outputs
> nothing on a default setup.
> - 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');
> - 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.
> - what do you think of the XPath feature of the XML driver ?
>
> --
> og
>
--
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder
paperCrane --Justin Patrin--