I've been around and around with paging. I started using the Containable behavior, which is fantastic for something like 'view', but is highly problematic for listings, especially with pagination. I discovered the Linkable behavior, and it's much more database efficient, and I actually can get it to work with pagination (except when using GROUP BY). I did have to tweak it though, to handle some of the more complex queries that I intend. This checkin includes a bunch of garbage, but given the amount of time I've spent on this crap, I'm afraid to lose anything that might later be useful information. I'll clean up on the next checkin.

git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@49 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-06-01 02:36:26 +00:00
parent 9db4dd737d
commit 23a81ae924
5 changed files with 419 additions and 56 deletions

View File

@@ -38,6 +38,8 @@
*/
class AppModel extends Model {
//var $actsAs = array('Containable');
var $actsAs = array('Linkable');
/**
* Get Enum Values
@@ -75,4 +77,63 @@ class AppModel extends Model {
));
} //end getEnumValues
// Overriding pagination, since the stupid count mechanism blows.
// This is also a crappy solution, especially if the query returns
// a really large number of rows. However, trying to untagle this
// without changing a bunch of core code is near impossible.
var $paginate_rows_save;
function paginate($conditions, $fields, $order, $limit, $page = 1, $recursive = null) {
/* pr("paginate"); */
/* pr(array_merge(compact('conditions', 'fields', 'order', 'limit', 'page', 'recursive'))); */
if ($page > 1 && isset($limit))
$offset = ($page - 1) * $limit;
else
$offset = 0;
return array_slice($this->paginate_rows_save, $offset, $limit);
}
function paginateCount($conditions = null, $recursive = null, $extra = null) {
/* pr("paginateCount"); */
if (!isset($recursive))
$recursive = $this->recursive;
$parameters = array_merge(compact('conditions', 'recursive'), $extra);
$results = $this->find('all', $parameters);
$this->paginate_rows_save = $results;
return count($this->paginate_rows_save);
}
// Code as found in the controller
/* function paginate($conditions, $fields, $order, $limit, $page = 1, $recursive = null) { */
/* pr("paginate"); */
/* pr(array_merge(compact('conditions', 'fields', 'order', 'limit', 'page', 'recursive'))); */
/* $parameters = compact('conditions', 'fields', 'order', 'limit', 'page'); */
/* if ($recursive != $this->recursive) { */
/* $parameters['recursive'] = $recursive; */
/* } */
/* $results = $this->find($type, array_merge($parameters, $extra)); */
/* pr("paginate end"); */
/* pr($results); */
/* } */
/* function paginateCount($conditions = null, $recursive = null, $extra = null) { */
/* pr("paginateCount"); */
/* pr(array_merge(compact('conditions', 'recursive'), $extra)); */
/* $parameters = compact('conditions'); */
/* if ($recursive != $this->recursive) { */
/* $parameters['recursive'] = $recursive; */
/* } */
/* $count = $this->find('count', array_merge($parameters, $extra)); */
/* pr("paginateCount end: $count"); */
/* return $count; */
/* } */
}