[Solar-svn] Revision 3035
pmjones at solarphp.com
pmjones at solarphp.com
Fri Mar 21 15:08:46 CDT 2008
[ADD] Support for automated count-pages in Solar_Sql_Model::fetchAll()
Solar_Sql_Model
---------------
* [ADD] New param key 'count_pages' for fetchAll() and fetchAssoc(). When
true, will execute countPages() with the same params used for the fetch,
and will then set that information in the resulting collection. This lets
you avoid making dual calls to fetchAll() and countPages(), and keeps the
pager information with the collection itself.
Solar_Sql_Model_Collection
--------------------------
* [ADD] New methods setPagerInfo() and getPagerInfo(), to go with the new
'count_pages' param for fetchAll() and fetchAssoc().
Modified: trunk/Solar/Sql/Model/Collection.php
===================================================================
--- trunk/Solar/Sql/Model/Collection.php 2008-03-21 19:11:31 UTC (rev 3034)
+++ trunk/Solar/Sql/Model/Collection.php 2008-03-21 20:08:45 UTC (rev 3035)
@@ -37,6 +37,8 @@
*/
protected $_related = array();
+ protected $_pager_info;
+
/**
*
* Returns a record from the collection based on its key value. Converts
@@ -108,6 +110,23 @@
return $this->_model;
}
+ public function setPagerInfo($info)
+ {
+ $base = array(
+ 'count' => null,
+ 'pages' => null,
+ 'paging' => null,
+ 'page' => null,
+ );
+
+ $this->_pager_info = array_merge($base, $info);
+ }
+
+ public function getPagerInfo()
+ {
+ return $this->_pager_info;
+ }
+
/**
*
* Loads the struct with data from an array or another struct.
Modified: trunk/Solar/Sql/Model.php
===================================================================
--- trunk/Solar/Sql/Model.php 2008-03-21 19:11:31 UTC (rev 3034)
+++ trunk/Solar/Sql/Model.php 2008-03-21 20:08:45 UTC (rev 3035)
@@ -742,6 +742,19 @@
$coll->loadRelated($name, $data);
}
}
+
+ // 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'],
+ ));
+ }
+
+ // done
return $coll;
} else {
return array();
@@ -833,6 +846,19 @@
$coll->loadRelated($name, $data);
}
}
+
+ // 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'],
+ ));
+ }
+
+ // done
return $coll;
} else {
return array();
@@ -1269,6 +1295,10 @@
$params['bind'] = null;
}
+ if (empty($params['count_pages'])) {
+ $params['count_pages'] = false;
+ }
+
return $params;
}
More information about the Solar-svn
mailing list