I've updated the sfDataSourcePropel implementation last days and I am
getting pretty happy about it.
In short the idea:
we want to have a grid, with widgets in order to generate a sortable-
paginated-table-view, from many different datasources (SOAP/XML/CSV/
Database (Propel/Doctrine)/Array)
This rendering of the grid and table is done with the sfGrid class,
however we need to feed this a standardised interface for the
datasource: sfDataSourceInterface.
This can be implemented for all your dataSources. I have now defined
it for Propel, Bernhard had already written it for Doctrine and Arrays
(I might have broken this implementation during my latest improvements
for the sfDataSourcePropel, this will of course be restored).
sfDataSourcePropel uses a new helper for Propel that I have defined:
sfPropelPropertyPathHelper, in order to simplify the customisation of
joining and hydrating related objects.
Two examples of this helper:
Example 1:
$criteria = new Criteria();
$objectPaths = array('Foto', 'Foto.Album');
$criteria = addJoinsAndSelectColumns($criteria, $objectPaths);
$fotos = hydrate($criteria, $objectPaths, $connection = null);
foreach ($fotos as $foto)
{
echo $foto->getAlbum()->getTitle();
}
Example 2:
$criteria = new Criteria();
$objectPaths = array('Album.Foto'); // no need to provide Album first,
this can be deducted (similar in the first example)
$criteria = addJoinsAndSelectColumns($criteria, $objectPaths);
$albums = hydrate($criteria, $objectPaths, $connection = null);
foreach ($albums as $album)
{
foreach ($album->getFotos() as $foto)
{
echo $foto->getTitle();
}
}
The DataSourcePropel-implementation is making use of this helper
(although you can extend the DataSourcePropel implementation to your
like and use default doSelectJoin and doCountJoin methods from your
peer-class). Currently it makes it possible to join and hydrate easily
and also allows you to automatically sort on related-columns. Support
for custom-columns is already partly available and only needs some
minor improvements.
An example of using the sfDataSourcePropel with sfGrids is:
$source = new sfDataSourcePropel('Foto');
$this->grid = new sfWebGrid($source);
$this->grid->bind($request);
$this->grid->setSortable(sfGrid::ALL);
$this->grid->setColumns(array(
'Title',
'Album.Title'
));
echo $grid;
The album table will automatically be joined after it has been
requested by the grid.
There currently is support for the following relations
// - directly
related:
RelatedTableName
// - related by multiple pk/fk
pairs: RelatedTableName (pk/fk-
pairs are automatically resolved)
// - directly related, but multiple relations from base to
parent exist: RelatedTableNameRelatedByForeignKeyName
// - reversely related (one-to-
many): RelatedTableNames (with the
s)
// - NOT tested are self referencing relations (the issue with
this is there depth is unknown)
// - NOT implemented is joining i18n related tables automatically.
The definition of these relations is being generated by an extension
of the propel builders and can be fully modified in your peer classes
Feedback is (again) appreciated!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en
-~----------~----~----~----~------~----~------~--~---