diff --git a/application/dashlet.class.inc.php b/application/dashlet.class.inc.php index 240a462c3..35b595781 100644 --- a/application/dashlet.class.inc.php +++ b/application/dashlet.class.inc.php @@ -467,8 +467,14 @@ abstract class DashletGroupBy extends Dashlet foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef) { if (!$oAttDef->IsScalar()) continue; // skip link sets - if ($oAttDef->IsExternalKey(EXTKEY_ABSOLUTE)) continue; // skip external keys - $aGroupBy[$sAttCode] = $oAttDef->GetLabel(); + + $sLabel = $oAttDef->GetLabel(); + if ($oAttDef->IsExternalKey(EXTKEY_ABSOLUTE)) + { + $sLabel = $oAttDef->GetLabel().' (strict)'; + } + + $aGroupBy[$sAttCode] = $sLabel; if ($oAttDef instanceof AttributeDateTime) { @@ -479,13 +485,10 @@ abstract class DashletGroupBy extends Dashlet } } - - $oField = new DesignerComboField('group_by', 'Group by', $this->aProperties['group_by']); $oField->SetAllowedValues($aGroupBy); $oForm->AddField($oField); - $aStyles = array( 'pie' => 'Pie chart', 'bars' => 'Bar chart', @@ -778,7 +781,8 @@ class DashletProto extends Dashlet $oFilter = DBObjectSearch::FromOQL('SELECT FunctionalCI AS fci'); $sGroupBy1 = 'status'; - $sGroupBy2 = 'org_id_friendlyname'; + //$sGroupBy2 = 'org_id_friendlyname'; + $sGroupBy2 = 'org_id'; $sHtmlTitle = "Hardcoded on $sGroupBy1 and $sGroupBy2..."; $sAlias = $oFilter->GetClassAlias(); @@ -807,6 +811,9 @@ class DashletProto extends Dashlet $sValue1 = $aRow['grouped_by_1']; $sValue2 = $aRow['grouped_by_2']; + $sDisplayValue1 = $aGroupBy['grouped_by_1']->MakeValueLabel($oFilter, $sValue1, $sValue1); // default to the raw value + $sDisplayValue2 = $aGroupBy['grouped_by_2']->MakeValueLabel($oFilter, $sValue2, $sValue2); // default to the raw value + // Build the search for this subset $oSubsetSearch = clone $oFilter; $oCondition = new BinaryExpression($oGroupByExp1, '=', new ScalarExpression($sValue1)); @@ -816,8 +823,8 @@ class DashletProto extends Dashlet $sFilter = urlencode($oSubsetSearch->serialize()); $aData[] = array ( - 'group1' => htmlentities($sValue1, ENT_QUOTES, 'UTF-8'), - 'group2' => htmlentities($sValue2, ENT_QUOTES, 'UTF-8'), + 'group1' => $sDisplayValue1, + 'group2' => $sDisplayValue2, 'value' => "$iCount" ); // TO DO: add the context information } diff --git a/application/displayblock.class.inc.php b/application/displayblock.class.inc.php index 4a449f95e..1194f9ef5 100644 --- a/application/displayblock.class.inc.php +++ b/application/displayblock.class.inc.php @@ -366,28 +366,32 @@ class DisplayBlock $aRes = CMDBSource::QueryToArray($sSql); $aGroupBy = array(); - $sLabels = array(); + $aLabels = array(); + $aValues = array(); $iTotalCount = 0; - foreach ($aRes as $aRow) + foreach ($aRes as $iRow => $aRow) { $sValue = $aRow['grouped_by_1']; - $sLabels[$sValue] = htmlentities($sValue, ENT_QUOTES, 'UTF-8'); - $aGroupBy[$sValue] = (int) $aRow['_itop_count_']; + $aValues[$iRow] = $sValue; + $sHtmlValue = $oGroupByExp->MakeValueLabel($this->m_oFilter, $sValue, $sValue); + $aLabels[$iRow] = $sHtmlValue; + $aGroupBy[$iRow] = (int) $aRow['_itop_count_']; $iTotalCount += $aRow['_itop_count_']; } + $aData = array(); $oAppContext = new ApplicationContext(); $sParams = $oAppContext->GetForLink(); - foreach($aGroupBy as $sValue => $iCount) + foreach($aGroupBy as $iRow => $iCount) { // Build the search for this subset $oSubsetSearch = clone $this->m_oFilter; - $oCondition = new BinaryExpression($oGroupByExp, '=', new ScalarExpression($sValue)); + $oCondition = new BinaryExpression($oGroupByExp, '=', new ScalarExpression($aValues[$iRow])); $oSubsetSearch->AddConditionExpression($oCondition); $sFilter = urlencode($oSubsetSearch->serialize()); - $aData[] = array ( 'group' => $sLabels[$sValue], + $aData[] = array ( 'group' => $aLabels[$iRow], 'value' => "$iCount"); // TO DO: add the context information } $aAttribs =array( @@ -798,25 +802,27 @@ EOF $aRes = CMDBSource::QueryToArray($sSql); $aGroupBy = array(); - $sLabels = array(); + $aLabels = array(); + $aValues = array(); $iTotalCount = 0; - foreach ($aRes as $aRow) + foreach ($aRes as $iRow => $aRow) { $sValue = $aRow['grouped_by_1']; - $sLabels[$sValue] = htmlentities($sValue, ENT_QUOTES, 'UTF-8'); - $aGroupBy[$sValue] = (int) $aRow['_itop_count_']; + $aValues[$iRow] = $sValue; + $sHtmlValue = $oGroupByExp->MakeValueLabel($this->m_oFilter, $sValue, $sValue); + $aLabels[$iRow] = $sHtmlValue; + $aGroupBy[$iRow] = (int) $aRow['_itop_count_']; $iTotalCount += $aRow['_itop_count_']; } $aData = array(); - $aLabels = array(); $idx = 0; $aURLs = array(); - foreach($aGroupBy as $sValue => $iValue) + foreach($aGroupBy as $iRow => $iCount) { // Build the search for this subset $oSubsetSearch = clone $this->m_oFilter; - $oCondition = new BinaryExpression($oGroupByExp, '=', new ScalarExpression($sValue)); + $oCondition = new BinaryExpression($oGroupByExp, '=', new ScalarExpression($aValues[$iRow])); $oSubsetSearch->AddConditionExpression($oCondition); $aURLs[$idx] = $oSubsetSearch->serialize(); $idx++; @@ -871,26 +877,27 @@ EOF $aRes = CMDBSource::QueryToArray($sSql); $aGroupBy = array(); - $sLabels = array(); + $aLabels = array(); $iTotalCount = 0; - foreach ($aRes as $aRow) + foreach ($aRes as $iRow => $aRow) { $sValue = $aRow['grouped_by_1']; - $sLabels[$sValue] = htmlentities($sValue, ENT_QUOTES, 'UTF-8'); - $aGroupBy[$sValue] = (int) $aRow['_itop_count_']; + $sHtmlValue = $oGroupByExp->MakeValueLabel($this->m_oFilter, $sValue, $sValue); + $aLabels[$iRow] = strip_tags($sHtmlValue); + $aGroupBy[$iRow] = (int) $aRow['_itop_count_']; $iTotalCount += $aRow['_itop_count_']; } $aData = array(); - $aLabels = array(); + $aChartLabels = array(); $maxValue = 0; - foreach($aGroupBy as $sValue => $iValue) + foreach($aGroupBy as $iRow => $iCount) { - $oBarValue = new bar_value($iValue); + $oBarValue = new bar_value($iCount); $oBarValue->on_click("ofc_drill_down_$sId"); $aData[] = $oBarValue; - if ($iValue > $maxValue) $maxValue = $iValue; - $aLabels[] = $sValue; + if ($iCount > $maxValue) $maxValue = $iCount; + $aChartLabels[] = $aLabels[$iRow]; } $oYAxis = new y_axis(); $aMagicValues = array(1,2,5,10); @@ -916,7 +923,7 @@ EOF // set them vertical $oXLabels->set_vertical(); // set the label text - $oXLabels->set_labels($aLabels); + $oXLabels->set_labels($aChartLabels); // Add the X Axis Labels to the X Axis $oXAxis->set_labels( $oXLabels ); $oChart->set_x_axis( $oXAxis ); @@ -951,25 +958,25 @@ EOF $aRes = CMDBSource::QueryToArray($sSql); $aGroupBy = array(); - $sLabels = array(); + $aLabels = array(); $iTotalCount = 0; - foreach ($aRes as $aRow) + foreach ($aRes as $iRow => $aRow) { $sValue = $aRow['grouped_by_1']; - $sLabels[$sValue] = htmlentities($sValue, ENT_QUOTES, 'UTF-8'); - $aGroupBy[$sValue] = (int) $aRow['_itop_count_']; + $sHtmlValue = $oGroupByExp->MakeValueLabel($this->m_oFilter, $sValue, $sValue); + $aLabels[$iRow] = strip_tags($sHtmlValue); + $aGroupBy[$iRow] = (int) $aRow['_itop_count_']; $iTotalCount += $aRow['_itop_count_']; } $aData = array(); - foreach($aGroupBy as $sValue => $iValue) + foreach($aGroupBy as $iRow => $iCount) { - $PieValue = new pie_value($iValue, $sValue); //@@ BUG: not passed via ajax !!! + $PieValue = new pie_value($iCount, $aLabels[$iRow]); //@@ BUG: not passed via ajax !!! $PieValue->on_click("ofc_drill_down_$sId"); $aData[] = $PieValue; } - $oChartElement->set_values( $aData ); $oChart->x_axis = null; } diff --git a/core/expression.class.inc.php b/core/expression.class.inc.php index fe414112b..dd51e37a8 100644 --- a/core/expression.class.inc.php +++ b/core/expression.class.inc.php @@ -91,6 +91,19 @@ abstract class Expression } abstract public function RenameParam($sOldName, $sNewName); + + /** + * Make the most relevant label, given the value of the expression + * + * @param DBObjectSearch oFilter The context in which this expression has been used + * @param string sValue The value returned by the query, for this expression + * @param string sDefault The default value if no relevant label could be computed + * @return The label + */ + public function MakeValueLabel($oFilter, $sValue, $sDefault) + { + return $sDefault; + } } class SQLExpression extends Expression @@ -465,6 +478,36 @@ class FieldExpression extends UnaryExpression } return $oRet; } + + /** + * Make the most relevant label, given the value of the expression + * + * @param DBObjectSearch oFilter The context in which this expression has been used + * @param string sValue The value returned by the query, for this expression + * @param string sDefault The default value if no relevant label could be computed + * @return The label + */ + public function MakeValueLabel($oFilter, $sValue, $sDefault) + { + $sAttCode = $this->GetName(); + $sParentAlias = $this->GetParent(); + + $aSelectedClasses = $oFilter->GetSelectedClasses(); + $sClass = $aSelectedClasses[$sParentAlias]; + + $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode); + if ($oAttDef->IsExternalKey()) + { + $sTargetClass = $oAttDef->GetTargetClass(); + $oObject = MetaModel::GetObject($sTargetClass, (int)$sValue); + $sRes = $oObject->GetHyperlink(); + } + else + { + $sRes = $oAttDef->GetAsHtml($sValue); + } + return $sRes; + } } // Has been resolved into an SQL expression