本文整理汇总了PHP中Report::addGroupBy方法的典型用法代码示例。如果您正苦于以下问题:PHP Report::addGroupBy方法的具体用法?PHP Report::addGroupBy怎么用?PHP Report::addGroupBy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Report
的用法示例。
在下文中一共展示了Report::addGroupBy方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: makeSummationWithDrillDownReport
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;
}
示例2: testRunQueryAndGrandTotalsData
public function testRunQueryAndGrandTotalsData()
{
ContactTestHelper::createContactByNameForOwner('testContact', $this->super);
$report = new Report();
$report->setType(Report::TYPE_SUMMATION);
$report->setModuleClassName('ContactsModule');
$report->setFiltersStructure('');
$groupBy = new GroupByForReportForm('ContactsModule', 'Contact', Report::TYPE_SUMMATION);
$groupBy->attributeIndexOrDerivedType = 'createdDateTime__Day';
$report->addGroupBy($groupBy);
$displayAttribute = new DisplayAttributeForReportForm('ContactsModule', 'Contact', Report::TYPE_SUMMATION);
$displayAttribute->attributeIndexOrDerivedType = 'createdDateTime__Day';
$report->addDisplayAttribute($displayAttribute);
$dataProvider = new SummationReportDataProvider($report);
$this->assertEmpty($dataProvider->runQueryAndGrandTotalsData());
}
示例3: testMakeAxisCrossingColumnCountAndLeadingHeaderRowsData
public function testMakeAxisCrossingColumnCountAndLeadingHeaderRowsData()
{
Yii::app()->user->userModel = User::getByUsername('super');
$report = new Report();
$report->setType(Report::TYPE_MATRIX);
$report->setModuleClassName('ReportsTestModule');
$report->setFiltersStructure('');
$displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_MATRIX);
$displayAttribute->attributeIndexOrDerivedType = 'integer__Maximum';
$report->addDisplayAttribute($displayAttribute);
$groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_MATRIX);
$groupBy->attributeIndexOrDerivedType = 'float';
$groupBy->axis = 'x';
$report->addGroupBy($groupBy);
$reportDataProvider = new MatrixReportDataProvider($report);
$data = $reportDataProvider->makeAxisCrossingColumnCountAndLeadingHeaderRowsData();
$compareData = array('rows' => array(), 'axisCrossingColumnCount' => 0, 'renderTotalColumn' => true);
$this->assertEquals($compareData, $data);
}
示例4: testCanCurrentUserProperlyRenderResults
public function testCanCurrentUserProperlyRenderResults()
{
$billy = User::getByUsername('billy');
$billy->setRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS);
$billy->setRight('OpportunitiesModule', OpportunitiesModule::RIGHT_ACCESS_OPPORTUNITIES);
$saved = $billy->save();
$this->assertTrue($saved);
$report = new Report();
$report->setModuleClassName('ContactsModule');
$report->setType(Report::TYPE_ROWS_AND_COLUMNS);
$this->assertTrue($report->canCurrentUserProperlyRenderResults());
//Now set to Billy
Yii::app()->user->userModel = $billy;
//Billy can't see the contacts module.
$this->assertFalse($report->canCurrentUserProperlyRenderResults());
//Billy can see accounts
$report->setModuleClassName('AccountsModule');
$this->assertTrue($report->canCurrentUserProperlyRenderResults());
//A filter on accounts is ok for Billy to see
$filter = new FilterForReportForm('AccountsModule', 'Account', $report->getType());
$filter->attributeIndexOrDerivedType = 'officePhone';
$filter->value = 'aValue';
$filter->operator = 'equals';
$report->addFilter($filter);
$this->assertTrue($report->canCurrentUserProperlyRenderResults());
//A filter on contacts is not ok for Billy to see
$filter2 = new FilterForReportForm('AccountsModule', 'Account', $report->getType());
$filter2->attributeIndexOrDerivedType = 'contacts___lastName';
$filter2->value = 'aValue';
$filter2->operator = 'equals';
$report->addFilter($filter2);
$this->assertFalse($report->canCurrentUserProperlyRenderResults());
//A related filter on opportunities would be ok for Billy to see
$report->removeAllFilters();
$filter = new FilterForReportForm('AccountsModule', 'Account', $report->getType());
$filter->attributeIndexOrDerivedType = 'opportunities___name';
$filter->value = 'aValue';
$filter->operator = 'equals';
$report->addFilter($filter);
$this->assertTrue($report->canCurrentUserProperlyRenderResults());
$report->removeAllFilters();
//Billy can see a groupBy on Accounts
$groupBy = new GroupByForReportForm('AccountsModule', 'Account', $report->getType());
$groupBy->attributeIndexOrDerivedType = 'name';
$groupBy->axis = 'y';
$report->addGroupBy($groupBy);
$this->assertTrue($report->canCurrentUserProperlyRenderResults());
//Billy cannot see a related groupBy on Contacts
$groupBy = new GroupByForReportForm('AccountsModule', 'Account', $report->getType());
$groupBy->attributeIndexOrDerivedType = 'contacts___lastName';
$groupBy->axis = 'y';
$report->addGroupBy($groupBy);
$this->assertFalse($report->canCurrentUserProperlyRenderResults());
//Billy can see a related groupBy on Opportunities
$report->removeAllGroupBys();
$groupBy = new GroupByForReportForm('AccountsModule', 'Account', $report->getType());
$groupBy->attributeIndexOrDerivedType = 'opportunities___name';
$groupBy->axis = 'y';
$report->addGroupBy($groupBy);
$this->assertTrue($report->canCurrentUserProperlyRenderResults());
$report->removeAllGroupBys();
//Billy can see an orderBy on Accounts
$orderBy = new OrderByForReportForm('AccountsModule', 'Account', $report->getType());
$orderBy->attributeIndexOrDerivedType = 'name';
$orderBy->order = 'desc';
$report->addOrderBy($orderBy);
$this->assertTrue($report->canCurrentUserProperlyRenderResults());
//Billy cannot see a related orderBy on Contacts
$orderBy = new OrderByForReportForm('AccountsModule', 'Account', $report->getType());
$orderBy->attributeIndexOrDerivedType = 'contacts___lastName';
$orderBy->order = 'desc';
$report->addOrderBy($orderBy);
$this->assertFalse($report->canCurrentUserProperlyRenderResults());
//Billy can see a related orderBy on Opportunities
$report->removeAllOrderBys();
$orderBy = new OrderByForReportForm('AccountsModule', 'Account', $report->getType());
$orderBy->attributeIndexOrDerivedType = 'opportunities___name';
$orderBy->order = 'desc';
$report->addOrderBy($orderBy);
$this->assertTrue($report->canCurrentUserProperlyRenderResults());
$report->removeAllOrderBys();
//Billy can see a displayAttribute on Accounts
$displayAttribute = new DisplayAttributeForReportForm('AccountsModule', 'Account', $report->getType());
$displayAttribute->attributeIndexOrDerivedType = 'name';
$displayAttribute->label = 'someNewLabel';
$report->addDisplayAttribute($displayAttribute);
$this->assertTrue($report->canCurrentUserProperlyRenderResults());
//Billy cannot see a related displayAttribute on Contacts
$displayAttribute = new DisplayAttributeForReportForm('AccountsModule', 'Account', $report->getType());
$displayAttribute->attributeIndexOrDerivedType = 'contacts___firstName';
$displayAttribute->label = 'someNewLabel';
$report->addDisplayAttribute($displayAttribute);
$this->assertFalse($report->canCurrentUserProperlyRenderResults());
//Billy can see a related displayAttribute on Opportunities
$report->removeAllDisplayAttributes();
$displayAttribute = new DisplayAttributeForReportForm('AccountsModule', 'Account', $report->getType());
$displayAttribute->attributeIndexOrDerivedType = 'opportunities___name';
$displayAttribute->label = 'someNewLabel';
$report->addDisplayAttribute($displayAttribute);
$this->assertTrue($report->canCurrentUserProperlyRenderResults());
//.........这里部分代码省略.........
示例5: resolveGroupBys
/**
* @param array $data
* @param Report $report
*/
protected static function resolveGroupBys($data, Report $report)
{
$report->removeAllGroupBys();
$moduleClassName = $report->getModuleClassName();
if (count($groupBysData = ArrayUtil::getArrayValue($data, ComponentForReportForm::TYPE_GROUP_BYS)) > 0) {
foreach ($groupBysData as $key => $groupByData) {
$groupBy = new GroupByForReportForm($moduleClassName, $moduleClassName::getPrimaryModelName(), $report->getType(), $key);
$groupBy->setAttributes($groupByData);
$report->addGroupBy($groupBy);
}
} else {
$report->removeAllGroupBys();
}
}
示例6: testExportReportWithMultiplePagesOfData
/**
* @depends testExportByModelIds
*/
public function testExportReportWithMultiplePagesOfData()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$numberOfUserNotifications = Notification::getCountByTypeAndUser('ExportProcessCompleted', Yii::app()->user->userModel);
$report = new Report();
$report->setType(Report::TYPE_ROWS_AND_COLUMNS);
$report->setModuleClassName('AccountsModule');
$report->setFiltersStructure('');
$displayAttribute = new DisplayAttributeForReportForm('AccountsModule', 'Account', Report::TYPE_ROWS_AND_COLUMNS);
$displayAttribute->setModelAliasUsingTableAliasName('model1');
$displayAttribute->attributeIndexOrDerivedType = 'name';
$report->addDisplayAttribute($displayAttribute);
$dataProvider = new RowsAndColumnsReportDataProvider($report);
$exportItem = new ExportItem();
$exportItem->isCompleted = 0;
$exportItem->exportFileType = 'csv';
$exportItem->exportFileName = 'rowAndColumnsTest2';
$exportItem->modelClassName = 'SavedReport';
$exportItem->serializedData = ExportUtil::getSerializedDataForExport($dataProvider);
$this->assertTrue($exportItem->save());
$id = $exportItem->id;
$exportItem->forget();
unset($exportItem);
//Delete queued jobs from test exportItems created above
Yii::app()->jobQueue->deleteAll();
ExportModule::$asynchronousPageSize = 2;
$job = new ExportJob();
$this->assertEquals(0, count(Yii::app()->jobQueue->getAll()));
$this->assertTrue($job->run());
$this->assertEquals(0, count(Yii::app()->jobQueue->getAll()));
$exportItem = ExportItem::getById($id);
$fileModel = $exportItem->exportFileModel;
$this->assertEquals(1, $exportItem->isCompleted);
$this->assertEquals(0, $exportItem->processOffset);
$this->assertEquals('csv', $exportItem->exportFileType);
$this->assertEquals('rowAndColumnsTest2', $exportItem->exportFileName);
$this->assertTrue($fileModel instanceof ExportFileModel);
$accounts = Account::getAll();
$headerData = array('Name');
$data = array();
foreach ($accounts as $account) {
$data[] = array($account->name);
}
$output = ExportItemToCsvFileUtil::export($data, $headerData, 'rowAndColumnsTest2.csv', false);
$this->assertEquals($output, $fileModel->fileContent->content);
// Check if user got notification message, and if its type is ExportProcessCompleted
$this->assertEquals($numberOfUserNotifications + 1, Notification::getCountByTypeAndUser('ExportProcessCompleted', Yii::app()->user->userModel));
//Matrix report should not paginate
$report = new Report();
$report->setType(Report::TYPE_MATRIX);
$report->setModuleClassName('AccountsModule');
$report->setFiltersStructure('');
$displayAttribute = new DisplayAttributeForReportForm('AccountsModule', 'Account', Report::TYPE_MATRIX);
$displayAttribute->setModelAliasUsingTableAliasName('model1');
$displayAttribute->attributeIndexOrDerivedType = 'Count';
$report->addDisplayAttribute($displayAttribute);
$groupBy = new GroupByForReportForm('AccountsModule', 'Account', Report::TYPE_MATRIX);
$groupBy->attributeIndexOrDerivedType = 'name';
$groupBy->axis = 'y';
$report->addGroupBy($groupBy);
$groupBy = new GroupByForReportForm('AccountsModule', 'Account', Report::TYPE_MATRIX);
$groupBy->attributeIndexOrDerivedType = 'officePhone';
$report->addGroupBy($groupBy);
$dataProvider = new MatrixReportDataProvider($report);
$exportItem = new ExportItem();
$exportItem->isCompleted = 0;
$exportItem->exportFileType = 'csv';
$exportItem->exportFileName = 'matrixTest1';
$exportItem->modelClassName = 'SavedReport';
$exportItem->serializedData = ExportUtil::getSerializedDataForExport($dataProvider);
$this->assertTrue($exportItem->save());
$id = $exportItem->id;
$exportItem->forget();
unset($exportItem);
//Delete queued jobs from test exportItems created above
Yii::app()->jobQueue->deleteAll();
ExportModule::$asynchronousPageSize = 2;
$job = new ExportJob();
$this->assertTrue($job->run());
$exportItem = ExportItem::getById($id);
$fileModel = $exportItem->exportFileModel;
$this->assertEquals(1, $exportItem->isCompleted);
$this->assertEquals(0, $exportItem->processOffset);
$this->assertEquals('csv', $exportItem->exportFileType);
$this->assertEquals('matrixTest1', $exportItem->exportFileName);
$this->assertTrue($fileModel instanceof ExportFileModel);
$fileContent = $fileModel->fileContent->content;
$this->assertContains('Test Account', $fileContent);
$this->assertContains('Test Account 2', $fileContent);
$this->assertContains('Test Account 3', $fileContent);
$this->assertContains('Test Account 4', $fileContent);
// Check if user got notification message, and if its type is ExportProcessCompleted
$this->assertEquals($numberOfUserNotifications + 2, Notification::getCountByTypeAndUser('ExportProcessCompleted', Yii::app()->user->userModel));
}
示例7: testWhereNestedGroupBysAndGettingDataForOrderBy
/**
* @depends testNextedGroupBys
*/
public function testWhereNestedGroupBysAndGettingDataForOrderBy()
{
$report = new Report();
$report->setType(Report::TYPE_SUMMATION);
$groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
$groupBy->attributeIndexOrDerivedType = 'hasOne___name';
$groupBy->axis = 'x';
$report->addGroupBy($groupBy);
$report->setModuleClassName('ReportsTestModule');
$adapter = new ReportRelationsAndAttributesToTreeAdapter($report, ComponentForReportForm::TYPE_ORDER_BYS);
$data = $adapter->getData(ComponentForReportForm::TYPE_ORDER_BYS . '_hasOne');
$this->assertEquals('OrderBys_hasOne___name', $data[0]['id']);
$this->assertEquals('OrderBys_hasOne___createdByUser', $data[1]['id']);
$this->assertEquals('OrderBys_hasOne___hasMany3', $data[2]['id']);
$this->assertEquals('OrderBys_hasOne___modifiedByUser', $data[3]['id']);
$this->assertEquals('OrderBys_hasOne___owner', $data[4]['id']);
}
示例8: makeMeetingsCategoryAndMonthStartTimeByOwner
public static function makeMeetingsCategoryAndMonthStartTimeByOwner()
{
$report = new Report();
$report->setModuleClassName('MeetingsModule');
$report->setName('Meettings Category And Month Start Time By Owner');
$report->setType(Report::TYPE_MATRIX);
$report->setOwner(Yii::app()->user->userModel);
$report->setFiltersStructure('');
$report->setCurrencyConversionType(Report::CURRENCY_CONVERSION_TYPE_BASE);
$groupBy = new GroupByForReportForm('MeetingsModule', 'Meeting', $report->getType());
$groupBy->attributeIndexOrDerivedType = 'startDateTime__Month';
$groupBy->axis = 'x';
$report->addGroupBy($groupBy);
$groupBy = new GroupByForReportForm('MeetingsModule', 'Meeting', $report->getType());
$groupBy->attributeIndexOrDerivedType = 'category';
$groupBy->axis = 'x';
$report->addGroupBy($groupBy);
$groupBy = new GroupByForReportForm('MeetingsModule', 'Meeting', $report->getType());
$groupBy->attributeIndexOrDerivedType = 'owner__User';
$groupBy->axis = 'y';
$report->addGroupBy($groupBy);
$displayAttribute = new DisplayAttributeForReportForm('MeetingsModule', 'Meeting', $report->getType());
$displayAttribute->attributeIndexOrDerivedType = 'Count';
$report->addDisplayAttribute($displayAttribute);
$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');
}
示例9: testGetAvailableAttributesForMatrixDisplayAttributes
/**
* @depends testGetAvailableAttributesForMatrixGroupBys
*/
public function testGetAvailableAttributesForMatrixDisplayAttributes()
{
//Without any group by displayed, nothing is available
$model = new ReportModelTestItem();
$rules = new ReportsTestReportRules();
$report = new Report();
$report->setType(Report::TYPE_MATRIX);
$report->setModuleClassName('ReportsTestModule');
$adapter = new ModelRelationsAndAttributesToMatrixReportAdapter($model, $rules, $report->getType());
$attributes = $adapter->getAttributesForDisplayAttributes($report->getGroupBys());
$this->assertEquals(0, count($attributes));
//Select dropDown as the groupBy attribute
$groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
$groupBy->attributeIndexOrDerivedType = 'dropDown';
$report = new Report();
$report->setType(Report::TYPE_MATRIX);
$report->setModuleClassName('ReportsTestModule');
$report->addGroupBy($groupBy);
$adapter = new ModelRelationsAndAttributesToMatrixReportAdapter($model, $rules, $report->getType());
$attributes = $adapter->getAttributesForDisplayAttributes($report->getGroupBys());
$this->assertEquals(21, count($attributes));
$compareData = array('label' => 'Count');
$this->assertEquals($compareData, $attributes['Count']);
$compareData = array('label' => 'Created Date Time -(Min)');
$this->assertEquals($compareData, $attributes['createdDateTime__Minimum']);
$compareData = array('label' => 'Created Date Time -(Max)');
$this->assertEquals($compareData, $attributes['createdDateTime__Maximum']);
$compareData = array('label' => 'Modified Date Time -(Min)');
$this->assertEquals($compareData, $attributes['modifiedDateTime__Minimum']);
$compareData = array('label' => 'Modified Date Time -(Max)');
$this->assertEquals($compareData, $attributes['modifiedDateTime__Maximum']);
$compareData = array('label' => 'Date -(Min)');
$this->assertEquals($compareData, $attributes['date__Minimum']);
$compareData = array('label' => 'Date -(Max)');
$this->assertEquals($compareData, $attributes['date__Maximum']);
$compareData = array('label' => 'Date Time -(Min)');
$this->assertEquals($compareData, $attributes['dateTime__Minimum']);
$compareData = array('label' => 'Date Time -(Max)');
$this->assertEquals($compareData, $attributes['dateTime__Maximum']);
$compareData = array('label' => 'Float -(Min)');
$this->assertEquals($compareData, $attributes['float__Minimum']);
$compareData = array('label' => 'Float -(Max)');
$this->assertEquals($compareData, $attributes['float__Maximum']);
$compareData = array('label' => 'Float -(Sum)');
$this->assertEquals($compareData, $attributes['float__Summation']);
$compareData = array('label' => 'Float -(Avg)');
$this->assertEquals($compareData, $attributes['float__Average']);
$compareData = array('label' => 'Integer -(Min)');
$this->assertEquals($compareData, $attributes['integer__Minimum']);
$compareData = array('label' => 'Integer -(Max)');
$this->assertEquals($compareData, $attributes['integer__Maximum']);
$compareData = array('label' => 'Integer -(Sum)');
$this->assertEquals($compareData, $attributes['integer__Summation']);
$compareData = array('label' => 'Integer -(Avg)');
$this->assertEquals($compareData, $attributes['integer__Average']);
$compareData = array('label' => 'Currency Value -(Min)');
$this->assertEquals($compareData, $attributes['currencyValue__Minimum']);
$compareData = array('label' => 'Currency Value -(Max)');
$this->assertEquals($compareData, $attributes['currencyValue__Maximum']);
$compareData = array('label' => 'Currency Value -(Sum)');
$this->assertEquals($compareData, $attributes['currencyValue__Summation']);
$compareData = array('label' => 'Currency Value -(Avg)');
$this->assertEquals($compareData, $attributes['currencyValue__Average']);
}
示例10: makeOpportunitiesByStage
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');
}
示例11: testResolveReportToSavedReport
public function testResolveReportToSavedReport()
{
$billy = User::getByUsername('billy');
$report = new Report();
$report->setDescription('aDescription');
$report->setModuleClassName('ReportsTestModule');
$report->setName('myFirstReport');
$report->setType(Report::TYPE_ROWS_AND_COLUMNS);
$report->setOwner($billy);
$report->setFiltersStructure('1 and 2 or 3');
$report->setCurrencyConversionType(Report::CURRENCY_CONVERSION_TYPE_SPOT);
$report->setSpotConversionCurrencyCode('CAD');
$filter = new FilterForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
$filter->attributeIndexOrDerivedType = 'string';
$filter->value = 'aValue';
$filter->operator = 'equals';
$filter->availableAtRunTime = true;
$report->addFilter($filter);
$filter = new FilterForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
$filter->attributeIndexOrDerivedType = 'currencyValue';
$filter->value = 'aValue';
$filter->secondValue = 'bValue';
$filter->operator = 'between';
$filter->currencyIdForValue = '4';
$filter->availableAtRunTime = true;
$report->addFilter($filter);
$filter = new FilterForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
$filter->attributeIndexOrDerivedType = 'owner__User';
$filter->value = 'aValue';
$filter->stringifiedModelForValue = 'someName';
$filter->availableAtRunTime = false;
$report->addFilter($filter);
$filter = new FilterForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
$filter->attributeIndexOrDerivedType = 'createdDateTime';
$filter->value = 'aValue';
$filter->secondValue = 'bValue';
$filter->operator = null;
$filter->currencyIdForValue = null;
$filter->availableAtRunTime = true;
$filter->valueType = 'Between';
$report->addFilter($filter);
$groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
$groupBy->attributeIndexOrDerivedType = 'lastName';
$groupBy->axis = 'y';
$report->addGroupBy($groupBy);
$orderBy = new OrderByForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
$orderBy->attributeIndexOrDerivedType = 'url';
$orderBy->order = 'desc';
$report->addOrderBy($orderBy);
$displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
$displayAttribute->attributeIndexOrDerivedType = 'phone';
$displayAttribute->label = 'someNewLabel';
$report->addDisplayAttribute($displayAttribute);
$drillDownDisplayAttribute = new DrillDownDisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
$drillDownDisplayAttribute->attributeIndexOrDerivedType = 'firstName';
$drillDownDisplayAttribute->label = 'someNewLabel';
$report->addDrillDownDisplayAttribute($drillDownDisplayAttribute);
$savedReport = new SavedReport();
$this->assertNull($savedReport->serializedData);
SavedReportToReportAdapter::resolveReportToSavedReport($report, $savedReport);
$this->assertEquals('ReportsTestModule', $savedReport->moduleClassName);
$this->assertEquals('myFirstReport', $savedReport->name);
$this->assertEquals('aDescription', $savedReport->description);
$this->assertEquals(Report::TYPE_ROWS_AND_COLUMNS, $savedReport->type);
$this->assertEquals('1 and 2 or 3', $report->getFiltersStructure());
$this->assertTrue($savedReport->owner->isSame($billy));
$compareData = array('Filters' => array(array('availableAtRunTime' => true, 'currencyIdForValue' => null, 'value' => 'aValue', 'secondValue' => null, 'stringifiedModelForValue' => null, 'valueType' => null, 'attributeIndexOrDerivedType' => 'string', 'operator' => 'equals'), array('availableAtRunTime' => true, 'currencyIdForValue' => '4', 'value' => 'aValue', 'secondValue' => 'bValue', 'stringifiedModelForValue' => null, 'valueType' => null, 'attributeIndexOrDerivedType' => 'currencyValue', 'operator' => 'between'), array('availableAtRunTime' => false, 'currencyIdForValue' => null, 'value' => 'aValue', 'secondValue' => null, 'stringifiedModelForValue' => 'someName', 'valueType' => null, 'attributeIndexOrDerivedType' => 'owner__User', 'operator' => null), array('availableAtRunTime' => true, 'value' => 'aValue', 'secondValue' => 'bValue', 'stringifiedModelForValue' => null, 'valueType' => 'Between', 'attributeIndexOrDerivedType' => 'createdDateTime', 'operator' => null, 'currencyIdForValue' => null)), 'OrderBys' => array(array('order' => 'desc', 'attributeIndexOrDerivedType' => 'url')), 'GroupBys' => array(array('axis' => 'y', 'attributeIndexOrDerivedType' => 'lastName')), 'DisplayAttributes' => array(array('label' => 'someNewLabel', 'attributeIndexOrDerivedType' => 'phone', 'columnAliasName' => 'col0', 'queryOnly' => false, 'valueUsedAsDrillDownFilter' => false, 'madeViaSelectInsteadOfViaModel' => false)), 'DrillDownDisplayAttributes' => array(array('label' => 'someNewLabel', 'attributeIndexOrDerivedType' => 'firstName', 'columnAliasName' => 'col0', 'queryOnly' => false, 'valueUsedAsDrillDownFilter' => false, 'madeViaSelectInsteadOfViaModel' => false)));
$unserializedData = unserialize($savedReport->serializedData);
$this->assertEquals($compareData['Filters'], $unserializedData['Filters']);
$this->assertEquals($compareData['OrderBys'], $unserializedData['OrderBys']);
$this->assertEquals($compareData['GroupBys'], $unserializedData['GroupBys']);
$this->assertEquals($compareData['DisplayAttributes'], $unserializedData['DisplayAttributes']);
$this->assertEquals($compareData['DrillDownDisplayAttributes'], $unserializedData['DrillDownDisplayAttributes']);
$this->assertEquals('1 and 2 or 3', $unserializedData['filtersStructure']);
$this->assertEquals(Report::CURRENCY_CONVERSION_TYPE_SPOT, $unserializedData['currencyConversionType']);
$this->assertEquals('CAD', $unserializedData['spotConversionCurrencyCode']);
$saved = $savedReport->save();
$this->assertTrue($saved);
}
示例12: testGetLeadingHeadersDataFromMatrixReportDataProviderWithALinkableAttribute
public function testGetLeadingHeadersDataFromMatrixReportDataProviderWithALinkableAttribute()
{
$reportModelTestItem2 = new ReportModelTestItem2();
$reportModelTestItem2->name = 'report name';
$reportModelTestItem2->phone = '123456789';
$this->assertTrue($reportModelTestItem2->save());
$reportModelTestItem2 = new ReportModelTestItem2();
$reportModelTestItem2->name = 'report name';
$reportModelTestItem2->phone = '987654321';
$this->assertTrue($reportModelTestItem2->save());
$report = new Report();
$report->setType(Report::TYPE_MATRIX);
$report->setModuleClassName('ReportsTest2Module');
$report->setFiltersStructure('');
$displayAttribute = new DisplayAttributeForReportForm('ReportsTest2Module', 'ReportModelTestItem2', Report::TYPE_MATRIX);
$displayAttribute->attributeIndexOrDerivedType = 'Count';
$report->addDisplayAttribute($displayAttribute);
$groupBy = new GroupByForReportForm('ReportsTest2Module', 'ReportModelTestItem2', Report::TYPE_MATRIX);
$groupBy->attributeIndexOrDerivedType = 'phone';
$report->addGroupBy($groupBy);
$groupBy = new GroupByForReportForm('ReportsTest2Module', 'ReportModelTestItem2', Report::TYPE_MATRIX);
$groupBy->attributeIndexOrDerivedType = 'name';
$groupBy->axis = 'y';
$report->addGroupBy($groupBy);
$dataProvider = new MatrixReportDataProvider($report);
$adapter = ReportToExportAdapterFactory::createReportToExportAdapter($report, $dataProvider);
$compareRowData = array(array(null, '123456789', '987654321', 'Total'), array('Name', 'Count', 'Count', 'Count'), array('report name', 1, 1, 2), array('Total', 1, 1));
$this->assertEmpty($adapter->getHeaderData());
$this->assertEquals($compareRowData, $adapter->getData());
$report = new Report();
$report->setType(Report::TYPE_MATRIX);
$report->setModuleClassName('ReportsTest2Module');
$report->setFiltersStructure('');
$displayAttribute = new DisplayAttributeForReportForm('ReportsTest2Module', 'ReportModelTestItem2', Report::TYPE_MATRIX);
$displayAttribute->attributeIndexOrDerivedType = 'Count';
$report->addDisplayAttribute($displayAttribute);
$groupBy = new GroupByForReportForm('ReportsTest2Module', 'ReportModelTestItem2', Report::TYPE_MATRIX);
$groupBy->attributeIndexOrDerivedType = 'name';
$report->addGroupBy($groupBy);
$groupBy = new GroupByForReportForm('ReportsTest2Module', 'ReportModelTestItem2', Report::TYPE_MATRIX);
$groupBy->attributeIndexOrDerivedType = 'phone';
$groupBy->axis = 'y';
$report->addGroupBy($groupBy);
$dataProvider = new MatrixReportDataProvider($report);
$adapter = ReportToExportAdapterFactory::createReportToExportAdapter($report, $dataProvider);
$compareRowData = array(array(null, 'report name', 'Total'), array('Phone', 'Count', 'Count'), array('123456789', 1, 1), array('987654321', 1, 1), array('Total', 2));
$this->assertEmpty($adapter->getHeaderData());
$this->assertEquals($compareRowData, $adapter->getData());
}
示例13: testGetAttributesForChartSeries
/**
* @depends testGetAttributesForOrderBysOnUser
*/
public function testGetAttributesForChartSeries()
{
$model = new ReportModelTestItem();
$rules = new ReportsTestReportRules();
$report = new Report();
$report->setType(Report::TYPE_SUMMATION);
$report->setModuleClassName('ReportsTestModule');
$adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
$attributes = $adapter->getAttributesForChartSeries($report->getGroupBys());
$this->assertEquals(0, count($attributes));
//Add a group by, but not as a display attribute
$groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
$groupBy->attributeIndexOrDerivedType = 'dropDown';
$report->setModuleClassName('ReportsTestModule');
$report->addGroupBy($groupBy);
$attributes = $adapter->getAttributesForChartSeries($report->getGroupBys());
$this->assertEquals(0, count($attributes));
//Add a group by as a display attribute
$groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
$groupBy->attributeIndexOrDerivedType = 'dropDown';
$report->setModuleClassName('ReportsTestModule');
$report->addGroupBy($groupBy);
$displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
$displayAttribute->attributeIndexOrDerivedType = 'dropDown';
$report->addDisplayAttribute($displayAttribute);
$attributes = $adapter->getAttributesForChartSeries($report->getGroupBys(), $report->getDisplayAttributes());
$this->assertEquals(1, count($attributes));
$compareData = array('label' => 'Drop Down');
$this->assertEquals($compareData, $attributes['dropDown']);
//Add a second group by as a display attribute
$groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
$groupBy->attributeIndexOrDerivedType = 'radioDropDown';
$report->setModuleClassName('ReportsTestModule');
$report->addGroupBy($groupBy);
$displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
$displayAttribute->attributeIndexOrDerivedType = 'radioDropDown';
$report->addDisplayAttribute($displayAttribute);
$attributes = $adapter->getAttributesForChartSeries($report->getGroupBys(), $report->getDisplayAttributes());
$this->assertEquals(2, count($attributes));
$compareData = array('label' => 'Drop Down');
$this->assertEquals($compareData, $attributes['dropDown']);
$compareData = array('label' => 'Radio Drop Down');
$this->assertEquals($compareData, $attributes['radioDropDown']);
//Add a third group by that is likeContactState as a display attribute
$groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
$groupBy->attributeIndexOrDerivedType = 'likeContactState';
$report->setModuleClassName('ReportsTestModule');
$report->addGroupBy($groupBy);
$displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
$displayAttribute->attributeIndexOrDerivedType = 'likeContactState';
$report->addDisplayAttribute($displayAttribute);
$attributes = $adapter->getAttributesForChartSeries($report->getGroupBys(), $report->getDisplayAttributes());
$this->assertEquals(3, count($attributes));
$compareData = array('label' => 'Drop Down');
$this->assertEquals($compareData, $attributes['dropDown']);
$compareData = array('label' => 'Radio Drop Down');
$this->assertEquals($compareData, $attributes['radioDropDown']);
$compareData = array('label' => 'A name for a state');
$this->assertEquals($compareData, $attributes['likeContactState']);
}
开发者ID:maruthisivaprasad,项目名称:zurmo,代码行数:63,代码来源:ModelRelationsAndAttributesToSummationReportAdapterTest.php