[Solar-svn] Revision 3059
pmjones at solarphp.com
pmjones at solarphp.com
Sat Mar 29 18:51:15 CDT 2008
Solar_Sql_Model: [REF] "Dry up" setting of pager information in collections. Also adds 'begin' and 'end' keys for pager info.
Modified: trunk/Solar/Sql/Model.php
===================================================================
--- trunk/Solar/Sql/Model.php 2008-03-29 22:54:08 UTC (rev 3058)
+++ trunk/Solar/Sql/Model.php 2008-03-29 23:51:15 UTC (rev 3059)
@@ -745,13 +745,7 @@
// if we're doing "count_pages", add pager info to the collection
if ($params['count_pages']) {
- $total = $this->countPages($params);
- $coll->setPagerInfo(array(
- 'count' => $total['count'],
- 'pages' => $total['pages'],
- 'paging' => $params['paging'],
- 'page' => $params['page'],
- ));
+ $this->_setCollectionPagerInfo($coll, $params);
}
// done
@@ -849,13 +843,7 @@
// if we're doing "count_pages", add pager info to the collection
if ($params['count_pages']) {
- $total = $this->countPages($params);
- $coll->setPagerInfo(array(
- 'count' => $total['count'],
- 'pages' => $total['pages'],
- 'paging' => $params['paging'],
- 'page' => $params['page'],
- ));
+ $this->_setCollectionPagerInfo($coll, $params);
}
// done
@@ -867,6 +855,33 @@
/**
*
+ * Sets the pager info in a collection, calling countPages() along the
+ * way.
+ *
+ * @param Solar_Sql_Model_Collection $coll The record collection to set
+ * pager info on.
+ *
+ * @param array $params The params for the original fetchAll() or
+ * fetchAssoc().
+ *
+ * @return void
+ */
+ protected function _setCollectionPagerInfo($coll, $params)
+ {
+ $total = $this->countPages($params);
+ $begin = ($params['page'] - 1) * $params['paging'] + 1;
+ $coll->setPagerInfo(array(
+ 'count' => $total['count'],
+ 'pages' => $total['pages'],
+ 'paging' => $params['paging'],
+ 'page' => $params['page'],
+ 'begin' => $begin,
+ 'end' => $begin + $coll->count(),
+ ));
+ }
+
+ /**
+ *
* Fetches one record by arbitrary parameters.
*
* Recognized parameters for the fetch are:
More information about the Solar-svn
mailing list