Hi,
Taking modExtra as a starting point, I have a question about building the list of objects to display in the grid.
My situation requires two instances for each row in the list: a (primary) tariff object and an (associated) property object.
I have created the schema like so:
<object class="Tariff" table="tariffs" extends="xPDOSimpleObject">
<field key="date_from" dbtype="date" precision="10" phptype="string" null="false" default="" />
<field key="date_to" dbtype="date" precision="10" phptype="string" null="false" default="" />
<field key="tariff" dbtype="smallint" precision ="6" phptype="integer" null="false" default="" />
<field key="tariff3" dbtype="smallint" precision ="6" phptype="integer" null="false" default="" />
<field key="tariff4" dbtype="smallint" precision ="6" phptype="integer" null="false" default="" />
<field key="tariff5" dbtype="smallint" precision ="6" phptype="integer" null="false" default="" />
<field key="tariff6" dbtype="smallint" precision ="6" phptype="integer" null="false" default="" />
<field key="property" dbtype="int" precision="11" phptype="integer" null="false" default="0" />
<aggregate alias="property" class="Property" local="property" foreign="id" cardinality="one" owner="foreign" />
</object>
<object class="Property" table="properties" extends="xPDOSimpleObject">
<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
<field key="address" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
<field key="postcode" dbtype="varchar" precision="2" phptype="string" null="false" default="" />
<field key="town" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
</object>
Now in getlist.php (in the processors subdirectory) the list is created which is passed to the grid for display (I removed the query code, which produces the result array of $tariffs):
foreach ($tariffs as $tariff) {
$tariffArray = $tariff->toArray();
$tariffArray['menu'] = array();
$tariffArray['menu'][] = array(
'text' => 'Update Tariff',
'handler' => 'this.updateTariff',
);
$tariffArray['menu'][] = '-';
$tariffArray['menu'][] = array(
'text' => 'Remove Tariff',
'handler' => 'this.removeTariff',
);
$list[]= $tariffArray;
}
What I’m struggling with is how to get the aggregate instances of "property" in each instance of "tariff" in such a way that it is accessible for the grid object to display.
I experimented by adding:
$property = $tariff->getOne("property");
... to the above foreach loop which neatly delivers the correct instance of $property. I suppose I could then add the relevant data from $property into $tariffArray.
But is that the proper way of doing it?