Index: branches/unlabeled/unlabeled-1.18.2/core/kernel/db/dblist.php =================================================================== diff -u -r5550 -r5845 --- branches/unlabeled/unlabeled-1.18.2/core/kernel/db/dblist.php (.../dblist.php) (revision 5550) +++ branches/unlabeled/unlabeled-1.18.2/core/kernel/db/dblist.php (.../dblist.php) (revision 5845) @@ -178,6 +178,7 @@ $this->AggregateFilter[FLT_SYSTEM] =& $this->Application->makeClass('kMultipleFilter', FLT_TYPE_AND); $this->AggregateFilter[FLT_NORMAL] =& $this->Application->makeClass('kMultipleFilter', FLT_TYPE_OR); + $this->AggregateFilter[FLT_VIEW] =& $this->Application->makeClass('kMultipleFilter', FLT_TYPE_AND); $this->PerPage = -1; } @@ -499,14 +500,22 @@ function GetHavingClause($for_counting=false, $system_filters_only=false, $aggregated = 0) { if ($for_counting) { - return $this->extractCalculatedFields($this->AggregateFilter[FLT_SYSTEM]->getSQL(), 2); + $aggregate_filter =& $this->Application->makeClass('kMultipleFilter'); + $aggregate_filter->addFilter('aggregate_system', $this->AggregateFilter[FLT_SYSTEM]); + if (!$system_filters_only) { + $aggregate_filter->addFilter('aggregate_view', $this->AggregateFilter[FLT_VIEW]); + } + return $this->extractCalculatedFields($aggregate_filter->getSQL(), 2); } $having =& $this->Application->makeClass('kMultipleFilter'); $having->addFilter('system_having', $this->HavingFilter[FLT_SYSTEM] ); if ($aggregated == 0) { - $having->addFilter('system_aggregated', $this->AggregateFilter[FLT_SYSTEM] ); + if (!$system_filters_only) { + $having->addFilter('view_aggregated', $this->AggregateFilter[FLT_VIEW] ); + } + $having->addFilter('system_aggregated', $this->AggregateFilter[FLT_SYSTEM]); } if (!$system_filters_only) {