/** * @return ReportDataProviderToAmChartMakerAdapter */ protected function makeStackedReportDataProviderToAmChartMakerAdapter() { $resultsData = $this->fetchChartData(); $firstRangeAttributeName = $this->resolveChartFirstRangeAttributeNameForReportResultsRowData(); $secondRangeAttributeName = $this->resolveChartSecondRangeAttributeNameForReportResultsRowData(); $chartData = array(); $secondSeriesValueData = array(); $secondSeriesDisplayLabels = array(); $secondSeriesValueCount = 1; $firstSeriesDisplayAttributeKey = $this->getDisplayAttributeKeyByAttribute($this->report->getChart()->firstSeries); $secondSeriesDisplayAttributeKey = $this->getDisplayAttributeKeyByAttribute($this->report->getChart()->secondSeries); foreach ($resultsData as $data) { $firstSeriesDataValue = $data->resolveRawValueByDisplayAttributeKey($firstSeriesDisplayAttributeKey); $chartData[$firstSeriesDataValue] = array(ReportDataProviderToAmChartMakerAdapter::resolveFirstSeriesDisplayLabelName(1) => $this->getDisplayAttributeByAttribute($this->report->getChart()->firstSeries)->resolveValueAsLabelForHeaderCell($firstSeriesDataValue, true)); $secondSeriesDataValue = $data->resolveRawValueByDisplayAttributeKey($secondSeriesDisplayAttributeKey); if (!isset($secondSeriesValueData[$secondSeriesDataValue])) { $secondSeriesValueData[$secondSeriesDataValue] = $secondSeriesValueCount; $secondSeriesDisplayLabels[$secondSeriesValueCount] = $this->getDisplayAttributeByAttribute($this->report->getChart()->secondSeries)->resolveValueAsLabelForHeaderCell($secondSeriesDataValue, true); $secondSeriesValueCount++; } } foreach ($resultsData as $data) { $firstSeriesDataValue = $data->resolveRawValueByDisplayAttributeKey($firstSeriesDisplayAttributeKey); $secondSeriesDataValue = $data->resolveRawValueByDisplayAttributeKey($secondSeriesDisplayAttributeKey); $secondSeriesKey = $secondSeriesValueData[$secondSeriesDataValue]; if (!isset($chartData[$firstSeriesDataValue][ReportDataProviderToAmChartMakerAdapter::resolveFirstSeriesValueName($secondSeriesKey)])) { $chartData[$firstSeriesDataValue][ReportDataProviderToAmChartMakerAdapter::resolveFirstSeriesValueName($secondSeriesKey)] = 0; } $chartData[$firstSeriesDataValue][ReportDataProviderToAmChartMakerAdapter::resolveFirstSeriesValueName($secondSeriesKey)] += $data->{$firstRangeAttributeName}; if (!isset($chartData[$firstSeriesDataValue][ReportDataProviderToAmChartMakerAdapter::resolveFirstRangeDisplayLabelName($secondSeriesKey)])) { $chartData[$firstSeriesDataValue][ReportDataProviderToAmChartMakerAdapter::resolveFirstRangeDisplayLabelName($secondSeriesKey)] = $this->getDisplayAttributeByAttribute($this->report->getChart()->firstRange)->label; } if (!isset($chartData[$firstSeriesDataValue][ReportDataProviderToAmChartMakerAdapter::resolveSecondSeriesValueName($secondSeriesKey)])) { $chartData[$firstSeriesDataValue][ReportDataProviderToAmChartMakerAdapter::resolveSecondSeriesValueName($secondSeriesKey)] = 0; } $chartData[$firstSeriesDataValue][ReportDataProviderToAmChartMakerAdapter::resolveSecondSeriesValueName($secondSeriesKey)] += $data->{$secondRangeAttributeName}; if (!isset($chartData[$firstSeriesDataValue][ReportDataProviderToAmChartMakerAdapter::resolveSecondSeriesDisplayLabelName($secondSeriesKey)])) { $chartData[$firstSeriesDataValue][ReportDataProviderToAmChartMakerAdapter::resolveSecondSeriesDisplayLabelName($secondSeriesKey)] = $secondSeriesDisplayLabels[$secondSeriesKey]; } if (!isset($chartData[$firstSeriesDataValue][ReportDataProviderToAmChartMakerAdapter::resolveSecondSeriesDisplayLabelName($secondSeriesKey)])) { $chartData[$firstSeriesDataValue][ReportDataProviderToAmChartMakerAdapter::resolveSecondSeriesDisplayLabelName($secondSeriesKey)] = $this->getDisplayAttributeByAttribute($this->report->getChart()->secondRange)->label; } } return new ReportDataProviderToAmChartMakerAdapter($this->report, array_values($chartData), $secondSeriesValueData, $secondSeriesDisplayLabels, $secondSeriesValueCount - 1); }
public function testResolveSecondSeriesValueName() { $value = ReportDataProviderToAmChartMakerAdapter::resolveSecondSeriesValueName(5); $this->assertEquals('SecondSeriesValue5', $value); }