Exemplo n.º 1
0
 public function testMakeDataAndLabelsForSeriesOrRange()
 {
     $attributesData = array('a' => array('label' => 'an A'), 'b' => array('label' => 'a b'));
     $dataAndLabels = ReportUtil::makeDataAndLabelsForSeriesOrRange($attributesData);
     $compareData = array('a' => 'an A', 'b' => 'a b');
     $this->assertEquals($compareData, $dataAndLabels);
 }
 /**
  * @param $savedReport
  * @return Report
  */
 public static function makeReportBySavedReport($savedReport)
 {
     $report = new Report();
     if ($savedReport->id > 0) {
         $report->setId((int) $savedReport->id);
     }
     $report->setDescription($savedReport->description);
     $report->setModuleClassName($savedReport->moduleClassName);
     $report->setName($savedReport->name);
     $report->setOwner($savedReport->owner);
     $report->setType($savedReport->type);
     $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($savedReport);
     $report->setExplicitReadWriteModelPermissions($explicitReadWriteModelPermissions);
     if ($savedReport->serializedData != null) {
         $unserializedData = unserialize($savedReport->serializedData);
         if (isset($unserializedData['filtersStructure'])) {
             $report->setFiltersStructure($unserializedData['filtersStructure']);
         }
         if (isset($unserializedData['currencyConversionType'])) {
             $report->setCurrencyConversionType((int) $unserializedData['currencyConversionType']);
         }
         if (isset($unserializedData['spotConversionCurrencyCode'])) {
             $report->setSpotConversionCurrencyCode($unserializedData['spotConversionCurrencyCode']);
         }
         self::makeComponentFormAndPopulateReportFromData($unserializedData[ComponentForReportForm::TYPE_FILTERS], $report, 'Filter');
         self::makeComponentFormAndPopulateReportFromData($unserializedData[ComponentForReportForm::TYPE_ORDER_BYS], $report, 'OrderBy');
         self::makeComponentFormAndPopulateReportFromData($unserializedData[ComponentForReportForm::TYPE_GROUP_BYS], $report, 'GroupBy');
         self::makeComponentFormAndPopulateReportFromData($unserializedData[ComponentForReportForm::TYPE_DISPLAY_ATTRIBUTES], $report, 'DisplayAttribute');
         self::makeComponentFormAndPopulateReportFromData($unserializedData[ComponentForReportForm::TYPE_DRILL_DOWN_DISPLAY_ATTRIBUTES], $report, 'DrillDownDisplayAttribute');
         if (isset($unserializedData['chart'])) {
             $moduleClassName = $report->getModuleClassName();
             $modelClassName = $moduleClassName::getPrimaryModelName();
             $adapter = ModelRelationsAndAttributesToSummationReportAdapter::make($moduleClassName, $modelClassName, $report->getType());
             $chart = new ChartForReportForm(ReportUtil::makeDataAndLabelsForSeriesOrRange($adapter->getAttributesForChartSeries($report->getGroupBys(), $report->getDisplayAttributes())), ReportUtil::makeDataAndLabelsForSeriesOrRange($adapter->getAttributesForChartRange($report->getDisplayAttributes())));
             $chart->setAttributes($unserializedData['chart']);
             $report->setChart($chart);
         }
     }
     return $report;
 }
 /**
  * @param array $data
  * @param Report $report
  */
 protected static function resolveChart($data, Report $report)
 {
     if ($report->getType() != Report::TYPE_SUMMATION) {
         return;
     }
     $moduleClassName = $report->getModuleClassName();
     if ($moduleClassName != null) {
         $modelClassName = $moduleClassName::getPrimaryModelName();
         $adapter = ModelRelationsAndAttributesToSummationReportAdapter::make($moduleClassName, $modelClassName, $report->getType());
         $seriesDataAndLabels = ReportUtil::makeDataAndLabelsForSeriesOrRange($adapter->getAttributesForChartSeries($report->getGroupBys(), $report->getDisplayAttributes()));
         $rangeDataAndLabels = ReportUtil::makeDataAndLabelsForSeriesOrRange($adapter->getAttributesForChartRange($report->getDisplayAttributes()));
     } else {
         $seriesDataAndLabels = array();
         $rangeDataAndLabels = array();
     }
     $chart = new ChartForReportForm($seriesDataAndLabels, $rangeDataAndLabels);
     if (null != ($chartData = ArrayUtil::getArrayValue($data, 'ChartForReportForm'))) {
         $chart->setAttributes($chartData);
     }
     $report->setChart($chart);
 }
 public function actionGetAvailableSeriesAndRangesForChart($type, $id = null, $isBeingCopied = false)
 {
     $postData = PostUtil::getData();
     $savedReport = null;
     $report = null;
     $this->resolveSavedReportAndReportByPostData($postData, $savedReport, $report, $type, $id, (bool) $isBeingCopied);
     $moduleClassName = $report->getModuleClassName();
     $modelClassName = $moduleClassName::getPrimaryModelName();
     $modelToReportAdapter = ModelRelationsAndAttributesToReportAdapter::make($moduleClassName, $modelClassName, $report->getType());
     if (!$modelToReportAdapter instanceof ModelRelationsAndAttributesToSummationReportAdapter) {
         throw new NotSupportedException();
     }
     $seriesAttributesData = $modelToReportAdapter->getAttributesForChartSeries($report->getGroupBys(), $report->getDisplayAttributes());
     $rangeAttributesData = $modelToReportAdapter->getAttributesForChartRange($report->getDisplayAttributes());
     $dataAndLabels = array();
     $dataAndLabels['firstSeriesDataAndLabels'] = array('' => Zurmo::t('Core', '(None)'));
     $dataAndLabels['firstSeriesDataAndLabels'] = array_merge($dataAndLabels['firstSeriesDataAndLabels'], ReportUtil::makeDataAndLabelsForSeriesOrRange($seriesAttributesData));
     $dataAndLabels['firstRangeDataAndLabels'] = array('' => Zurmo::t('Core', '(None)'));
     $dataAndLabels['firstRangeDataAndLabels'] = array_merge($dataAndLabels['firstRangeDataAndLabels'], ReportUtil::makeDataAndLabelsForSeriesOrRange($rangeAttributesData));
     $dataAndLabels['secondSeriesDataAndLabels'] = array('' => Zurmo::t('Core', '(None)'));
     $dataAndLabels['secondSeriesDataAndLabels'] = array_merge($dataAndLabels['secondSeriesDataAndLabels'], ReportUtil::makeDataAndLabelsForSeriesOrRange($seriesAttributesData));
     $dataAndLabels['secondRangeDataAndLabels'] = array('' => Zurmo::t('Core', '(None)'));
     $dataAndLabels['secondRangeDataAndLabels'] = array_merge($dataAndLabels['secondRangeDataAndLabels'], ReportUtil::makeDataAndLabelsForSeriesOrRange($rangeAttributesData));
     echo CJSON::encode($dataAndLabels);
 }