public static function makeSummationWithDrillDownReport() { $report = new Report(); $report->setDescription('A test summation report with drill down description'); $report->setModuleClassName('ReportsTestModule'); $report->setName('A test summation report with drill down'); $report->setType(Report::TYPE_SUMMATION); $report->setOwner(Yii::app()->user->userModel); $report->setFiltersStructure('1'); $report->setCurrencyConversionType(Report::CURRENCY_CONVERSION_TYPE_BASE); $filter = new FilterForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType()); $filter->attributeIndexOrDerivedType = 'string'; $filter->value = '123'; $filter->operator = OperatorRules::TYPE_EQUALS; $report->addFilter($filter); $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType()); $groupBy->attributeIndexOrDerivedType = 'owner__User'; $groupBy->axis = 'x'; $report->addGroupBy($groupBy); $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType()); $displayAttribute->attributeIndexOrDerivedType = 'owner__User'; $report->addDisplayAttribute($displayAttribute); $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType()); $displayAttribute->attributeIndexOrDerivedType = 'Count'; $report->addDisplayAttribute($displayAttribute); $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType()); $displayAttribute->attributeIndexOrDerivedType = 'currencyValue__Summation'; $report->addDisplayAttribute($displayAttribute); $drillDownDisplayAttribute = new DrillDownDisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType()); $drillDownDisplayAttribute->attributeIndexOrDerivedType = 'string'; $report->addDrillDownDisplayAttribute($drillDownDisplayAttribute); $drillDownDisplayAttribute = new DrillDownDisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType()); $drillDownDisplayAttribute->attributeIndexOrDerivedType = 'hasOne___name'; $report->addDrillDownDisplayAttribute($drillDownDisplayAttribute); $drillDownDisplayAttribute = new DrillDownDisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType()); $drillDownDisplayAttribute->attributeIndexOrDerivedType = 'currencyValue'; $report->addDrillDownDisplayAttribute($drillDownDisplayAttribute); $drillDownDisplayAttribute = new DrillDownDisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType()); $drillDownDisplayAttribute->attributeIndexOrDerivedType = 'date'; $report->addDrillDownDisplayAttribute($drillDownDisplayAttribute); $chart = new ChartForReportForm(); $chart->type = 'Pie2D'; $chart->firstSeries = 'owner__User'; $chart->firstRange = 'currencyValue__Summation'; $report->setChart($chart); $savedReport = new SavedReport(); SavedReportToReportAdapter::resolveReportToSavedReport($report, $savedReport); $saved = $savedReport->save(); if (!$saved) { throw new FailedToSaveModelException(); } return $savedReport; }
/** * @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 static function makeOpportunitiesByStage() { $report = new Report(); $report->setModuleClassName('OpportunitiesModule'); $report->setName('Opportunities by Stage'); $report->setType(Report::TYPE_SUMMATION); $report->setOwner(Yii::app()->user->userModel); $report->setFiltersStructure(''); $report->setCurrencyConversionType(Report::CURRENCY_CONVERSION_TYPE_BASE); $groupBy = new GroupByForReportForm('OpportunitiesModule', 'Opportunity', $report->getType()); $groupBy->attributeIndexOrDerivedType = 'stage'; $groupBy->axis = 'x'; $report->addGroupBy($groupBy); $displayAttribute = new DisplayAttributeForReportForm('OpportunitiesModule', 'Opportunity', $report->getType()); $displayAttribute->attributeIndexOrDerivedType = 'stage'; $report->addDisplayAttribute($displayAttribute); $displayAttribute = new DisplayAttributeForReportForm('OpportunitiesModule', 'Opportunity', $report->getType()); $displayAttribute->attributeIndexOrDerivedType = 'Count'; $report->addDisplayAttribute($displayAttribute); $displayAttribute = new DisplayAttributeForReportForm('OpportunitiesModule', 'Opportunity', $report->getType()); $displayAttribute->attributeIndexOrDerivedType = 'amount__Summation'; $report->addDisplayAttribute($displayAttribute); $chart = new ChartForReportForm(); $chart->type = 'Column2D'; $chart->firstSeries = 'stage'; $chart->firstRange = 'amount__Summation'; $report->setChart($chart); $savedReport = new SavedReport(); SavedReportToReportAdapter::resolveReportToSavedReport($report, $savedReport); //set explicit $saved = $savedReport->save(); assert('$saved'); $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($savedReport); $explicitReadWriteModelPermissions->addReadWritePermitable(Group::getByName(Group::EVERYONE_GROUP_NAME)); $success = ExplicitReadWriteModelPermissionsUtil::resolveExplicitReadWriteModelPermissions($savedReport, $explicitReadWriteModelPermissions); assert('$success'); $saved = $savedReport->save(); assert('$saved'); }
public function testGetSecondSeriesDisplayLabelByKey() { $data = array(); $secondSeriesValueData = array(); $secondSeriesDisplayLabels = array('abc', 'def'); $secondSeriesValueCount = 5; $chart = new ChartForReportForm(); $chart->type = 'Bar2D'; $chart->firstSeries = 'dropDown'; $chart->firstRange = 'float__Summation'; $chart->secondSeries = 'radioDropDown'; $chart->secondRange = 'integer__Summation'; $report = new Report(); $report->setChart($chart); $adapter = new ReportDataProviderToAmChartMakerAdapter($report, $data, $secondSeriesValueData, $secondSeriesDisplayLabels, $secondSeriesValueCount); $this->assertEquals('def', $adapter->getSecondSeriesDisplayLabelByKey(1)); }