value} protected $aCSSClasses; public function __construct($sId) { $this->sId = $sId; $this->bRedrawNeeded = true; // By default: redraw each time a property changes $this->bFormRedrawNeeded = false; // By default: no need to redraw the form (independent fields) $this->aProperties = array(); // By default: there is no property $this->aCSSClasses = array('dashlet'); } // Assuming that a property has the type of its default value, set in the constructor // public function Str2Prop($sProperty, $sValue) { $refValue = $this->aProperties[$sProperty]; $sRefType = gettype($refValue); if ($sRefType == 'boolean') { $ret = ($sValue == 'true'); } else { $ret = $sValue; settype($ret, $sRefType); } return $ret; } public function Prop2Str($value) { if (gettype($value) == 'boolean') { $sRet = $value ? 'true' : 'false'; } else { $sRet = (string) $value; } return $sRet; } public function FromDOMNode($oDOMNode) { foreach ($this->aProperties as $sProperty => $value) { $this->oDOMNode = $oDOMNode->getElementsByTagName($sProperty)->item(0); if ($this->oDOMNode != null) { $newvalue = $this->Str2Prop($sProperty, $this->oDOMNode->textContent); $this->aProperties[$sProperty] = $newvalue; } } } public function ToDOMNode($oDOMNode) { foreach ($this->aProperties as $sProperty => $value) { $sXmlValue = $this->Prop2Str($value); $oPropNode = $oDOMNode->ownerDocument->createElement($sProperty, $sXmlValue); $oDOMNode->appendChild($oPropNode); } } public function FromXml($sXml) { $oDomDoc = new DOMDocument('1.0', 'UTF-8'); $oDomDoc->loadXml($sXml); $this->FromDOMNode($oDomDoc->firstChild); } public function FromParams($aParams) { foreach ($this->aProperties as $sProperty => $value) { if (array_key_exists($sProperty, $aParams)) { $this->aProperties[$sProperty] = $aParams[$sProperty]; } } } public function DoRender($oPage, $bEditMode = false, $aExtraParams = array()) { $sCSSClasses = implode(' ', $this->aCSSClasses); if ($bEditMode) { $sId = $this->GetID(); $oPage->add('
Please enter a valid OQL query
'); } elseif ($sGroupBy == '') { $oPage->add('Please select the field on which the objects will be grouped together
'); } else { $oFilter = DBObjectSearch::FromOQL($sQuery); $sClassAlias = $oFilter->GetClassAlias(); if (preg_match('/^(.*):(.*)$/', $sGroupBy, $aMatches)) { $sAttCode = $aMatches[1]; $sFunction = $aMatches[2]; switch($sFunction) { case 'hour': $sGroupByLabel = 'Hour of '.$sAttCode. ' (0-23)'; $sGroupByExpr = "DATE_FORMAT($sClassAlias.$sAttCode, '%H')"; // 0 -> 31 break; case 'month': $sGroupByLabel = 'Month of '.$sAttCode. ' (1 - 12)'; $sGroupByExpr = "DATE_FORMAT($sClassAlias.$sAttCode, '%m')"; // 0 -> 31 break; case 'day_of_week': $sGroupByLabel = 'Day of week for '.$sAttCode. ' (sunday to saturday)'; $sGroupByExpr = "DATE_FORMAT($sClassAlias.$sAttCode, '%w')"; break; case 'day_of_month': $sGroupByLabel = 'Day of month for'.$sAttCode; $sGroupByExpr = "DATE_FORMAT($sClassAlias.$sAttCode, '%e')"; // 0 -> 31 break; default: $sGroupByLabel = 'Unknown group by function '.$sFunction; $sGroupByExpr = $sClassAlias.'.'.$sAttCode; } } else { $sAttCode = $sGroupBy; $sGroupByExpr = $sClassAlias.'.'.$sAttCode; $sGroupByLabel = MetaModel::GetLabel($oFilter->GetClass(), $sAttCode); } switch($sStyle) { case 'bars': $sType = 'open_flash_chart'; $aExtraParams = array( 'chart_type' => 'bars', 'chart_title' => $sTitle, 'group_by' => $sGroupByExpr, 'group_by_label' => $sGroupByLabel, ); $sHtmlTitle = ''; // done in the itop block break; case 'pie': $sType = 'open_flash_chart'; $aExtraParams = array( 'chart_type' => 'pie', 'chart_title' => $sTitle, 'group_by' => $sGroupByExpr, 'group_by_label' => $sGroupByLabel, ); $sHtmlTitle = ''; // done in the itop block break; case 'table': default: $sHtmlTitle = htmlentities(Dict::S($sTitle), ENT_QUOTES, 'UTF-8'); // done in the itop block $sType = 'count'; $aExtraParams = array( 'group_by' => $sGroupByExpr, 'group_by_label' => $sGroupByLabel, ); break; } $oPage->add('