Hello, I am trying to solve a problem with pagination for two days now! I'll explain:
//on a controller
function showActivities() {
isset($_GET['start']) ? $start = $_GET['start'] : $start = 0;
$list = DataObject::get("ActiviteitPage", "","", "","{$start}," . AANTAL_ITEMS_ACTIVITEITENOVERZICHT );
return ($list) ? $list : null;
}
On the template:
<!-- pagination -->
<% if showActivities.MoreThanOnePage %>
<div id="head_itc_file">
<% control showActivities.Pages %>
<% if CurrentBool %>
<img src="/themes/inventheon/images/file_itc.gif" alt="" />
<% else %>
<a href="$Link"><img src="/themes/inventheon/images/file_off_itc.gif" alt="" /></a>
<% end_if %>
<% end_control %>
</div>
<% end_if %>
<!-- end pagination -->
//...cut
$ActiviteitenLijst.Count //PRINTS 3
<% include ActiviteitenLijst %> //PRINTS 3 ITEMS
Now the problem: The pagination returns pages for 107 items. Whatever the numer of items per page, it is based on 107 item (1 -> 107 pages, 10 -> 11 pages )
looking in the code I see the problem comes from:
$this->setPageLimits($start, $length, $query->unlimitedRowCount());
The last parameter is 107 and should be 5 (there are 5 ActiviteitPage items)
Now: it gets odd:
in this code in SQLQuery.php:
function unlimitedRowCount( $column = "*" ) {
$clone = clone $this;
$clone->select = array("count($column)");
$clone->limit = null;
$clone->orderby = null;
$clone->groupby = null;
Debug::show($clone); // THIS DUMP LINE!!!!!!!!!!!!!!!!!!!!!!!!!!!
$queryContent = singleton('SiteTree')->extendedSQL();
return $queryContent->execute()->value();
}
The dump line prints:
SQLQuery::__set_state(array( 'select' => array ( 0 => 'count(*)', ), 'from' => array ( 'SiteTree' => '`SiteTree_Live`', 'InventheonPage' => 'LEFT JOIN `InventheonPage_Live` ON `InventheonPage_Live`.ID = `SiteTree_Live`.ID', 'ActiviteitPage' => 'LEFT JOIN `ActiviteitPage_Live` ON `ActiviteitPage_Live`.ID = `SiteTree_Live`.ID', ), 'where' => array ( 0 => '`SiteTree_Live`.ClassName IN (\'ActiviteitPage\')', ), 'orderby' => NULL, 'groupby' => NULL, 'having' => NULL, 'limit' => NULL, 'distinct' => NULL, 'delete' => NULL, 'extension_instances' => array ( ), 'class' => 'SQLQuery', ))
I translate it myself to sql and that is:
SELECT count(*)
FROM SiteTree_Live
LEFT JOIN `InventheonPage_Live` ON `InventheonPage_Live`.ID = `SiteTree_Live`.ID
LEFT JOIN `ActiviteitPage_Live` ON `ActiviteitPage_Live`.ID = `SiteTree_Live`.ID
WHERE `SiteTree_Live`.ClassName IN ('ActiviteitPage')
And when I run it: 5 !!!!!!
But the function SQLQuery::unlimitedRowCount() returns 107
Please any help!!!
I don't understand this anymore...
Thanks,
Oscar