Re: Re: Datagrid and linking dataobjects
| From: | Justin Patrin | Date: | Thu, 20 Jan 2005 18:40:54 +0000 |
| Subject: | Re: Re: Datagrid and linking dataobjects | ||
| References: | 1 2 3 4 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-17050@lists.php.net to get a copy of this message | ||
On Thu, 20 Jan 2005 10:16:43 -0800, Jamie Alessio
<Jamie.Alessio@ucop.edu> wrote:
>
> >The problem here is when you may want to use both. Say you do a join
> >on 2 tables with links. It would be nice to have the FormBuilder
> >integration in this case to pull the linked records and display a nice
> >value (instead of an id), but if you "turn on" FB integration you
> >lose the join.
> >
> >
> In my case, I am only using joinAdd() to turn ID's into "nice values".
> How do you "turn on" FB integration with DG to automatically do this?
$dg->bind($do, array('formbuilder_integration' => true));
This will use FormBuilder's getDataObjectString method to get the
"display value" of linked fields. No need to do a join. ;-) (You need
to use the CVS version of Structures_DataGrid for this) It will also
use the fb_preDefOrder field in the DO for ordering if you have it.
>
> >Or maybe I'm making this too hard. Try something like this:
> >
> >$obj1 = DataObject::factory('X');
> >$obj2 = DataObject::factory('Y');
> >
> >$obj1->joinAdd($obj2, 'LEFT');
> >$obj1->fb_fieldsToRender = array_merge($obj1->fb_fieldsToRender,
> >
> >$obj2->fb_fieldsToRender);
> >$dg =& new Structures_DataGrid(15);
> >$dg->bind($obj1);
> >
> >
> Seems like the array_merge() would do the trick. That said, once I start
> using $dg->addColumn() it seems logical that any column name I specify
> should be added to the "fields to render" array (which I think is
> actually $dg->_dataSource->_options['fields'] ?). The fact that DG uses
> FB fields is great, but as far as I can tell there isn't an easy way to
> override the fb_fieldsToRender array to display other columns that might
> be in your DO.
>
> Basically, from an outsider/newbie perspective of using DG for the first
> time I was very confused as to why DG was ignoring a column/property
> name in my DO that I had explicitly asked DG to display by specifying
> it via $dg->addColumn(). Anyhow, I don't say any of this to offend -
> just hoping to offer some constructive criticism on what is a great base
> of code to work with.
>
Well...the problem with addColumn is that if DG is making the columns
for you there's no way to add them yourself. You either have to
specify *all* of the columns manually, deal with the auto-gen ones it
does, or hack it like you did. Oh, there's also the option, of course.
This probably makes more sense...
$obj1 = DataObject::factory('X');
$obj2 = DataObject::factory('Y');
$obj1->joinAdd($obj2, 'LEFT');
$dg =& new Structures_DataGrid(15);
$dg->bind($obj1, array('formbuilder_integration' => true,
'fields' =>
array_merge($obj1->fb_fieldsToRender,
$obj2->fb_fieldsToRender)));
You may also need 'generate_columns' => true in that options array.
--
Justin Patrin