Author: francois
Date: 2010-03-22 12:22:06 +0100 (Mon, 22 Mar 2010)
New Revision: 28667
Modified:
plugins/sfPropel15Plugin/trunk/README
plugins/sfPropel15Plugin/trunk/data/generator/sfPropelModule/admin15/parts/configuration.php
plugins/sfPropel15Plugin/trunk/data/generator/sfPropelModule/admin15/parts/paginationAction.php
Log:
[sfPropel15Plugin] added the `with` list setting to the admin generator
Modified: plugins/sfPropel15Plugin/trunk/README
===================================================================
--- plugins/sfPropel15Plugin/trunk/README 2010-03-22 10:49:39 UTC (rev
28666)
+++ plugins/sfPropel15Plugin/trunk/README 2010-03-22 11:22:06 UTC (rev
28667)
@@ -69,31 +69,83 @@
You can now use the additional features listed below.
-*Tip*: Settings of the admin generator referencing the Peer classes are
ignored in this theme. This includes `peer_method`, and `peer_count_method`.
The new theme provides alternatives for these settings (see below).
+### Hydrating Related Objects ###
-### Additional Query Methods ###
+The `admin15` theme doesn't use the Peer classes anymore, therefore settings
referencing the Peer classes are ignored in this theme. This includes
`peer_method`, and `peer_count_method`. The new theme provides a simple
alternative for these settings, called `with`. Add each of the objects to
hydrate together with the main object in the `with` setting list:
-You can executed additional query methods by setting the `query_methods`
parameter. For instance, in a list of `Books`, to hydrate the `Author` object
together with each `Book`, setup your `list` view as follows:
-
[yaml]
list:
display: [title, Author]
- query_methods: [joinWithAuthor]
+ with: [Author]
-The admin generator will then execute the following query to display the list:
+The admin generator will then execute the following query to display the list,
effectively executing a single query instead of 1+n queries:
[php]
$books = BookQuery::create()
->joinWithAuthor()
->paginate();
-Of course, you can add as many `query_methods` as you want, to hydrate
multiple objects, or hide some results by default:
+Of course, you can add as many `with` names as you want, to hydrate multiple
objects:
[yaml]
list:
display: [title, Author, Publisher]
- query_methods: [joinWithAuthor, joinWithPublisher, filterByPublished]
+ with: [Author, Publisher]
+*Tip*: Before adding relations to the `with` setting, check that you don't
already have a filter on the foreign key column that already makes the query to
list all the related objects. If it's the case, then Propel's Instance Pooling
will make the `with` superfluous, as each call to a related object will not
trigger an additional query anyway.
+
+### Additional Query Methods ###
+
+You can execute additional query methods in the list by setting the
`query_methods` parameter. For instance, in a list of `Books`, to limit the
list of published books, setup your `list` view as follows:
+
+ [yaml]
+ list:
+ display: [title]
+ query_methods: [filterByAlreadyPublished]
+
+The admin generator will then execute the following query to display the list:
+
+ [php]
+ $books = BookQuery::create()
+ ->filterByAlreadyPublished()
+ ->paginate();
+
+You must implement each `query_method` in the main object's query class. In
this exemple, here is how you can implement
`Bookquery::filterByAlreadyPublished()`:
+
+ [php]
+ class BookQuery extends BaseBookQuery
+ {
+ public function filterByAlreadyPublished()
+ {
+ return $this->filterByPublishedAt(array('min' => time()));
+ }
+ }
+
+You can use this feature to add calculated columns to the list without
additional queries:
+
+ [yaml]
+ list:
+ display: [title]
+ query_methods: [withNbReviews]
+
+For this to work, add the following method to the query class:
+
+ [php]
+ class BookQuery extends BaseBookQuery
+ {
+ public function withNbReviews()
+ {
+ return $this
+ ->leftJoin('Book.Review')
+ ->withColumn('COUNT(Review.Id)', 'NbReviews');
+ }
+ }
+
+Now you can add a partial column and use the virtual `NbReviews` column in the
list:
+
+ [php]
+ <?php echo $book->getVirtualColumn('NbReviews') ?>
+
### Sorting On A Virtual Column ###
The new theme provides an easy way to make virtual columns sortable in the
list view. Just declare the corresponding fields with `is_sortable` to `true`,
and the generated module will look for an `orderByXXX()` method in the
generated query. For instance, to allow a book list to be sortable on the
author name:
Modified:
plugins/sfPropel15Plugin/trunk/data/generator/sfPropelModule/admin15/parts/configuration.php
===================================================================
---
plugins/sfPropel15Plugin/trunk/data/generator/sfPropelModule/admin15/parts/configuration.php
2010-03-22 10:49:39 UTC (rev 28666)
+++
plugins/sfPropel15Plugin/trunk/data/generator/sfPropelModule/admin15/parts/configuration.php
2010-03-22 11:22:06 UTC (rev 28667)
@@ -45,6 +45,12 @@
<?php include dirname(__FILE__).'/sortingConfiguration.php' ?>
+ public function getWiths()
+ {
+ return <?php echo $this->asPhp(isset($this->config['list']['with']) ?
$this->config['list']['with'] : array()) ?>;
+<?php unset($this->config['list']['with']) ?>
+ }
+
public function getQueryMethods()
{
return <?php echo
$this->asPhp(isset($this->config['list']['query_methods']) ?
$this->config['list']['query_methods'] : array()) ?>;
Modified:
plugins/sfPropel15Plugin/trunk/data/generator/sfPropelModule/admin15/parts/paginationAction.php
===================================================================
---
plugins/sfPropel15Plugin/trunk/data/generator/sfPropelModule/admin15/parts/paginationAction.php
2010-03-22 10:49:39 UTC (rev 28666)
+++
plugins/sfPropel15Plugin/trunk/data/generator/sfPropelModule/admin15/parts/paginationAction.php
2010-03-22 11:22:06 UTC (rev 28667)
@@ -32,6 +32,10 @@
$this->processSort($query);
+ foreach ($this->configuration->getWiths() as $with) {
+ $query->joinWith($with);
+ }
+
foreach ($this->configuration->getQueryMethods() as $method) {
$query->$method();
}
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" 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-svn?hl=en.