diff --git a/src/chartgenerator.php b/src/chartgenerator.php index d0d1475..977f744 100644 --- a/src/chartgenerator.php +++ b/src/chartgenerator.php @@ -307,7 +307,7 @@ if ( !$content['error_occured'] ) // Setup Y-AXIS $graph->yaxis->SetFont(FF_ARIAL,FS_NORMAL,8); - $graph->yaxis->scale->SetGrace(10); // So the value is readable + $graph->yaxis->scale->SetGrace(20); // So the value is readable $graph->yaxis->SetLabelAlign('center','top'); $graph->yaxis->SetLabelFormat('%d'); $graph->yaxis->SetLabelSide(SIDE_RIGHT); diff --git a/src/classes/logstreamdb.class.php b/src/classes/logstreamdb.class.php index 6558b2a..7d1e0c2 100644 --- a/src/classes/logstreamdb.class.php +++ b/src/classes/logstreamdb.class.php @@ -508,6 +508,46 @@ class LogStreamDB extends LogStream { */ public function GetCountSortedByField($szFieldId, $nFieldType, $nRecordLimit) { + global $content, $dbmapping; + + // Copy helper variables, this is just for better readability + $szTableType = $this->_logStreamConfigObj->DBTableType; + + if ( isset($dbmapping[$szTableType][$szFieldId]) ) + { + $myDBFieldName = $dbmapping[$szTableType][$szFieldId]; + + // Create SQL String now! + $szSql = "SELECT " . + $myDBFieldName . ", " . + "count(" . $myDBFieldName . ") as TotalCount " . + " FROM " . $this->_logStreamConfigObj->DBTableName . + " GROUP BY " . $myDBFieldName . + " ORDER BY TotalCount DESC" . + " LIMIT " . $nRecordLimit; + + + // Perform Database Query + $myquery = mysql_query($szSql, $this->_dbhandle); + if ( !$myquery ) + return ERROR_DB_QUERYFAILED; + + // Initialize Array variable + $aResult = array(); + + // read data records + while ($myRow = mysql_fetch_array($myquery, MYSQL_ASSOC)) + $aResult[ $myRow[$myDBFieldName] ] = $myRow['TotalCount']; +//print_r ($aResult); +//exit; + // return finished array + return $aResult; + } + else + { + // return error code, field mapping not found + return ERROR_DB_DBFIELDNOTFOUND; + } } diff --git a/src/classes/logstreamdisk.class.php b/src/classes/logstreamdisk.class.php index 296896b..2c6c8ce 100644 --- a/src/classes/logstreamdisk.class.php +++ b/src/classes/logstreamdisk.class.php @@ -613,17 +613,7 @@ class LogStreamDisk extends LogStream { else $aResult[ $content['LN_STATS_OTHERS'] ] = 1; } - } - /* - if ( isset($aResult[ $logArray[$szFieldId] ][CHARTDATA_COUNT]) ) - $aResult[ $logArray[$szFieldId] ][CHARTDATA_COUNT]++; - else - { - $aResult[ $logArray[$szFieldId] ][CHARTDATA_NAME] = $logArray[$szFieldId]; - $aResult[ $logArray[$szFieldId] ][CHARTDATA_COUNT] = 1; - } - */ } } while ( ($ret = $this->ReadNext($uID, $logArray)) == SUCCESS ); diff --git a/src/classes/logstreampdo.class.php b/src/classes/logstreampdo.class.php index 57bccc8..9dcc3fc 100644 --- a/src/classes/logstreampdo.class.php +++ b/src/classes/logstreampdo.class.php @@ -518,6 +518,54 @@ class LogStreamPDO extends LogStream { */ public function GetCountSortedByField($szFieldId, $nFieldType, $nRecordLimit) { + global $content, $dbmapping; + + // Copy helper variables, this is just for better readability + $szTableType = $this->_logStreamConfigObj->DBTableType; + + if ( isset($dbmapping[$szTableType][$szFieldId]) ) + { + $myDBFieldName = $dbmapping[$szTableType][$szFieldId]; + + // Create SQL String now! + $szSql = "SELECT " . + $myDBFieldName . ", " . + "count(" . $myDBFieldName . ") as TotalCount " . + " FROM " . $this->_logStreamConfigObj->DBTableName . + " GROUP BY " . $myDBFieldName . + " ORDER BY TotalCount DESC"; + // Append LIMIT in this case! + if ( $this->_logStreamConfigObj->DBType == DB_MYSQL || + $this->_logStreamConfigObj->DBType == DB_PGSQL ) + $szSql .= " LIMIT " . $nRecordLimit; + + // Perform Database Query + $this->_myDBQuery = $this->_dbhandle->query($szSql); + if ( !$this->_myDBQuery ) + return ERROR_DB_QUERYFAILED; + + if ( $this->_myDBQuery->rowCount() == 0 ) + return ERROR_NOMORERECORDS; + + // Initialize Array variable + $aResult = array(); + + // read data records + $iCount = 0; + while ( ($myRow = $this->_myDBQuery->fetch(PDO::FETCH_ASSOC)) && $iCount < $nRecordLimit) + { + $aResult[ $myRow[$myDBFieldName] ] = $myRow['TotalCount']; + $iCount++; + } + + // return finished array + return $aResult; + } + else + { + // return error code, field mapping not found + return ERROR_DB_DBFIELDNOTFOUND; + } } diff --git a/src/include/constants_errors.php b/src/include/constants_errors.php index 6323849..4cefa0a 100644 --- a/src/include/constants_errors.php +++ b/src/include/constants_errors.php @@ -58,6 +58,7 @@ define('ERROR_DB_NOPROPERTIES', 13); define('ERROR_DB_INVALIDDBMAPPING', 14); define('ERROR_DB_INVALIDDBDRIVER', 16); define('ERROR_DB_TABLENOTFOUND', 17); +define('ERROR_DB_DBFIELDNOTFOUND', 19); define('ERROR_MSG_NOMATCH', 18);