Index: branches/5.1.x/core/units/visits/visits_list.php =================================================================== diff -u -N -r12127 -r12657 --- branches/5.1.x/core/units/visits/visits_list.php (.../visits_list.php) (revision 12127) +++ branches/5.1.x/core/units/visits/visits_list.php (.../visits_list.php) (revision 12657) @@ -1,6 +1,6 @@ GetSelectSQL(true,true); - $sql = $this->getCountSQL($system_sql); - if( $this->GetGroupClause() ) + class VisitsList extends kDBList { + /** + * Counts the total number of records base on the query resulted from {@link kDBList::GetSelectSQL()} + * + * The method modifies the query to substitude SELECT part (fields listing) with COUNT(*). + * Special care should be applied when working with lists based on grouped queries, all aggregate function fields + * like SUM(), AVERAGE() etc. should be added to CountedSQL by using {@link kDBList::SetCountedSQL()} + * + * @access public + * @param string + * @return void + */ + function CountRecs() { - if (!isset($this->OriginalParams['types']) && $this->Special == 'incommerce') { - //$sql = preg_replace('/GROUP BY.*/', '', $sql); - $sql = 'SELECT COUNT(*) FROM '.$this->TableName; - $this->NoFilterCount = (int)$this->Conn->GetOne($sql); + $system_sql = $this->GetSelectSQL(true,true); + $sql = $this->getCountSQL($system_sql); + if( $this->GetGroupClause() ) { + if (!isset($this->OriginalParams['types']) && $this->Special == 'incommerce') { + //$sql = preg_replace('/GROUP BY.*/', '', $sql); + $sql = 'SELECT COUNT(*) FROM '.$this->TableName; + $this->NoFilterCount = (int)$this->Conn->GetOne($sql); + } + else { + $this->NoFilterCount = count( $this->Conn->GetCol($sql) ); + } } else { - $this->NoFilterCount = count( $this->Conn->GetCol($sql) ); + $this->NoFilterCount = (int)$this->Conn->GetOne($sql); } - } - else - { - $this->NoFilterCount = (int)$this->Conn->GetOne($sql); - } - $all_sql = $this->GetSelectSQL(true,false); - if($system_sql == $all_sql) //no need to query the same again - { - $this->RecordsCount = $this->NoFilterCount; - return; - } + $all_sql = $this->GetSelectSQL(true,false); + if($system_sql == $all_sql) { //no need to query the same again + $this->RecordsCount = $this->NoFilterCount; + return; + } - $sql = $this->getCountSQL($all_sql); + $sql = $this->getCountSQL($all_sql); - if( $this->GetGroupClause() ) - { - $this->RecordsCount = count( $this->Conn->GetCol($sql) ); + if( $this->GetGroupClause() ) { + $this->RecordsCount = count( $this->Conn->GetCol($sql) ); + } + else { + $this->RecordsCount = (int)$this->Conn->GetOne($sql); + } + + $this->Counted = true; } - else - { - $this->RecordsCount = (int)$this->Conn->GetOne($sql); - } - - - $this->Counted = true; - } - -} \ No newline at end of file + } \ No newline at end of file