Skip to content

Instantly share code, notes, and snippets.

@gordonbanderson
Created August 1, 2011 09:21
Show Gist options
  • Save gordonbanderson/1117846 to your computer and use it in GitHub Desktop.
Save gordonbanderson/1117846 to your computer and use it in GitHub Desktop.
function PagedChildren($klazz, $childrenPerPage = 10) {
$pageLength = $childrenPerPage;
$parentID = $this->ID;
if ($this->ClassName == 'NewsItemsFolder') {
if ($this->ItemsPerPage) {
$pageLength = $this->ItemsPerPage;
//error_log("Items per page:".$childrenPerPage);
}
}
$start = isset($_GET['start']) ? (int)$_GET['start'] : 0;
$sort = '';
$total = DB::query("SELECT COUNT(*) FROM SiteTree where ParentID=".$parentID)->value();
$NumberPages = 1 + ($total / $pageLength);
error_log("KLAZZ:".$klazz);
error_log("SORT:".$sort);
$results= DataObject::get($klazz,
"ParentID=".$parentID,//filter
$sort,//sort
//'',
'',
$start.','.$pageLength//limit
);
$this->lastPagedResults = $results;
return $results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment