1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
<?php
class PHPReportField {
var $sName; // field name
var $sType; // field type
var $dVal; // current value
var $dMin; // stores min value
var $dMax; // stores max value
var $dSum; // stores sum
var $bNum; // is it a numeric field?
/**
Constructor
*/
function PHPReportField($sName_=null,$sType_=null) {
$this->sName = $sName_;
$this->sType = $sType_;
$this->dVal = -1;
$this->dMin = null;
$this->dMax = null;
$this->dSum = 0;
$this->bNum = $this->checkNumeric();
}
/**
Reset field values
*/
function reset() {
$this->dVal = (is_numeric($this->dVal)?0:"");
$this->resetStats();
}
/**
Reset statistics
*/
function resetStats() {
$this->dMin = null;
$this->dMax = null;
$this->dSum = 0;
}
/*
Field name
*/
function getName() {
return $this->sName;
}
/*
Field type
*/
function getType() {
return $this->sType;
}
/**
Is a numeric field?
*/
function isNumeric(){
return $this->bNum;
}
/**
Returns if its a numeric field
@param
*/
function checkNumeric() {
// just make statistics on the numeric fields - change here if your
// database treats numeric fields with other description
// there is a workaround on numeric fields that some
// databases don't return the correct type (some ODBC databases)
// and I return UNDEFINED as the type and presume they are numeric
$sStr =
"NUMBER,NUMERIC,INT,DOUBLE,DECIMAL,REAL,TINY,SHORT,LONG,FLOAT,LONGLONG,INT24,YEAR,CID,FLOAT4,FLOAT8,INT2,".
"INT4,MONEY,OID,RELTIME,XID,DOUBLE PRECISION,SMALLINT,TINYINT,BIGINT,INT64,INT8,DATE,DATETIME";
return stristr($sStr,$this->sType);
}
/**
Set the values and statistics about this
field here.
@param value
*/
function set($oVal_=-1) {
$this->setVal($oVal_);
/*
If not numeric, don't make statistics, or
if the type is UNDEFINED, tries to make statistics for all kind of
data. note that is a bug on the way the database returns the data
type, and not a PHPReports bug.
*/
if($this->isNumeric($oVal_) ||
$this->sType=="UNDEFINED") {
$this->setMin($oVal_);
$this->setMax($oVal_);
$this->setSum($oVal_);
}
}
/**
Set the value
*/
function setVal($oVal_=-1) {
$this->dVal=$oVal_;
}
/**
Return the value
*/
function getVal() {
return $this->dVal;
}
/**
Set the minimum value
*/
function setMin($oVal_=0) {
if(is_null($this->dMin)){
$this->dMin=$oVal_;
return;
}
$this->dMin=$oVal_<$this->dMin?$oVal_:$this->dMin;
}
/**
Returns the minimum value
*/
function getMin() {
return $this->dMin;
}
/**
Sets the maximum value
@param value
*/
function setMax($oVal_=0) {
if(is_null($this->dMax)){
$this->dMax=$oVal_;
return;
}
$this->dMax=$oVal_>$this->dMax?$oVal_:$this->dMax;
}
/**
Returns the maximum value
*/
function getMax() {
return $this->dMax;
}
/**
Set the field sum
*/
function setSum($oVal_=0) {
$this->dSum+=$oVal_;
}
/**
Returns the field sum
*/
function getSum() {
return $this->dSum;
}
}
?>
|