public function testExportRelationAttributes()
 {
     $report = new Report();
     $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
     $report->setModuleClassName('EmailMessagesModule');
     $report->setFiltersStructure('');
     $emailMessage = new EmailMessage();
     $emailMessage->owner = Yii::app()->user->userModel;
     $emailMessage->subject = 'A test email';
     $emailContent = new EmailMessageContent();
     $emailContent->textContent = 'A test text message from Zurmo.';
     $emailContent->htmlContent = 'A test text message from Zurmo.';
     $emailMessage->content = $emailContent;
     $sender = new EmailMessageSender();
     $sender->fromAddress = '*****@*****.**';
     $sender->fromName = 'super';
     $sender->personsOrAccounts->add(Yii::app()->user->userModel);
     $emailMessage->sender = $sender;
     $recipient = new EmailMessageRecipient();
     $recipient->toAddress = '*****@*****.**';
     $recipient->toName = 'Test Recipient';
     $recipient->type = EmailMessageRecipient::TYPE_TO;
     $emailMessage->recipients->add($recipient);
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_SENT);
     $this->assertTrue($emailMessage->save());
     $displayAttribute1 = new DisplayAttributeForReportForm('EmailMessagesModule', 'EmailMessage', Report::TYPE_ROWS_AND_COLUMNS);
     $displayAttribute1->setModelAliasUsingTableAliasName('relatedModel');
     $displayAttribute1->attributeIndexOrDerivedType = 'sender___User__personsOrAccounts__Inferred___firstName';
     $report->addDisplayAttribute($displayAttribute1);
     $displayAttribute2 = new DisplayAttributeForReportForm('EmailMessagesModule', 'EmailMessage', Report::TYPE_ROWS_AND_COLUMNS);
     $displayAttribute2->setModelAliasUsingTableAliasName('relatedModel');
     $displayAttribute2->attributeIndexOrDerivedType = 'sender___Contact__personsOrAccounts__Inferred___firstName';
     $report->addDisplayAttribute($displayAttribute2);
     $dataProvider = new RowsAndColumnsReportDataProvider($report);
     $adapter = ReportToExportAdapterFactory::createReportToExportAdapter($report, $dataProvider);
     $compareHeaderData = array('Sender >> Users >> First Name', 'Sender >> Contacts >> First Name');
     $compareRowData = array(array('Clark', ''));
     $this->assertEquals($compareHeaderData, $adapter->getHeaderData());
     $this->assertEquals($compareRowData, $adapter->getData());
 }
 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());
 }
 public function testSqlQueryWithLinkTypeSpecificOnRelatedModels()
 {
     $quote = DatabaseCompatibilityUtil::getQuote();
     Yii::app()->user->userModel = User::getByUsername('super');
     $reportModelTestItem2 = new ReportModelTestItem2();
     $reportModelTestItem2->name = 'name';
     $this->assertTrue($reportModelTestItem2->save());
     $reportModelTestItem = new ReportModelTestItem();
     $reportModelTestItem->lastName = 'lastName';
     $reportModelTestItem->string = 'string';
     $reportModelTestItem->hasOne = $reportModelTestItem2;
     $this->assertTrue($reportModelTestItem->save());
     $report = new Report();
     $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
     $report->setModuleClassName('ReportsTest2Module');
     $report->setFiltersStructure('');
     $displayAttribute1 = new DisplayAttributeForReportForm('ReportsTest2Module', 'ReportModelTestItem2', Report::TYPE_ROWS_AND_COLUMNS);
     $displayAttribute1->setModelAliasUsingTableAliasName('relatedModel');
     $displayAttribute1->attributeIndexOrDerivedType = 'hasMany2___FullName';
     $report->addDisplayAttribute($displayAttribute1);
     $dataProvider = new RowsAndColumnsReportDataProvider($report);
     $content = $dataProvider->makeSqlQueryForDisplay();
     $compareContent = "select {$quote}reportmodeltestitem{$quote}.{$quote}id{$quote} reportmodeltestitemid " . "from {$quote}reportmodeltestitem2{$quote} " . "left join {$quote}reportmodeltestitem{$quote} on " . "{$quote}reportmodeltestitem{$quote}.{$quote}hasone_reportmodeltestitem2_id{$quote} " . "= {$quote}reportmodeltestitem2{$quote}.{$quote}id{$quote}  limit 10 offset 0";
     $this->assertEquals($compareContent, $content);
 }
 /**
  * @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));
 }
 public function testViaSelectAndViaModelTogether()
 {
     $reportModelTestItem = new ReportModelTestItem();
     $reportModelTestItem->string = 'string';
     $reportModelTestItem->lastName = 'lastName';
     $reportModelTestItem->integer = 9000;
     $reportModelTestItem->boolean = true;
     $this->assertTrue($reportModelTestItem->save());
     $report = new Report();
     $report->setType(Report::TYPE_SUMMATION);
     $report->setModuleClassName('ReportsTestModule');
     $report->setFiltersStructure('');
     //viaSelect attribute
     $displayAttribute1 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute1->attributeIndexOrDerivedType = 'integer__Minimum';
     $displayAttribute1->madeViaSelectInsteadOfViaModel = true;
     $this->assertTrue($displayAttribute1->columnAliasName == 'col0');
     $report->addDisplayAttribute($displayAttribute1);
     //viaModel attribute
     $reportModelTestItem->boolean = true;
     $displayAttribute2 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute2->setModelAliasUsingTableAliasName('model1');
     $displayAttribute2->attributeIndexOrDerivedType = 'boolean';
     $report->addDisplayAttribute($displayAttribute2);
     $dataProvider = new SummationReportDataProvider($report);
     $adapter = ReportToExportAdapterFactory::createReportToExportAdapter($report, $dataProvider);
     $compareHeaderData = array('Integer -(Min)', 'Boolean');
     $compareRowData = array(array(9000, true), array('Total'));
     $this->assertEquals($compareHeaderData, $adapter->getHeaderData());
     $this->assertEquals($compareRowData, $adapter->getData());
     $reportModelTestItem->delete();
 }
 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');
 }
 /**
  * @depends testGetAvailableAttributesForSummationOrderBys
  */
 public function testGetAvailableAttributesForSummationOrderBysThatAreDisplayCalculations()
 {
     //You can only order what is grouped on or a display calculation attribute
     $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->getAttributesForOrderBys($report->getGroupBys(), $report->getDisplayAttributes());
     $this->assertEquals(0, count($attributes));
     $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $this->assertNull($displayAttribute->label);
     $displayAttribute->attributeIndexOrDerivedType = 'createdDateTime__Minimum';
     $report->addDisplayAttribute($displayAttribute);
     $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
     $attributes = $adapter->getAttributesForOrderBys($report->getGroupBys(), $report->getDisplayAttributes());
     $this->assertEquals(1, count($attributes));
     $this->assertTrue(isset($attributes['createdDateTime__Minimum']));
     $compareData = array('label' => 'Created Date Time -(Min)');
     $this->assertEquals($compareData, $attributes['createdDateTime__Minimum']);
     $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $this->assertNull($displayAttribute->label);
     $displayAttribute->attributeIndexOrDerivedType = 'integer__Minimum';
     $report->addDisplayAttribute($displayAttribute);
     $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
     $attributes = $adapter->getAttributesForOrderBys($report->getGroupBys(), $report->getDisplayAttributes());
     $this->assertEquals(2, count($attributes));
     $this->assertTrue(isset($attributes['integer__Minimum']));
     $compareData = array('label' => 'Integer -(Min)');
     $this->assertEquals($compareData, $attributes['integer__Minimum']);
     //This should not add because we are at the wrong point in the chain
     $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $this->assertNull($displayAttribute->label);
     $displayAttribute->attributeIndexOrDerivedType = 'hasOne___createdDateTime__Minimum';
     $report->addDisplayAttribute($displayAttribute);
     $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
     $attributes = $adapter->getAttributesForOrderBys($report->getGroupBys(), $report->getDisplayAttributes());
     $this->assertEquals(2, count($attributes));
     $this->assertFalse(isset($attributes['hasOne___createdDateTime__Minimum']));
 }
 public static function makeSimpleContactRowsAndColumnsReport()
 {
     $report = new Report();
     $report->setDescription('A test contact report');
     $report->setModuleClassName('ContactsModule');
     $report->setName('A rows and columns report');
     $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
     $report->setOwner(Yii::app()->user->userModel);
     $report->setCurrencyConversionType(Report::CURRENCY_CONVERSION_TYPE_BASE);
     $report->setFiltersStructure('');
     $displayAttribute = new DisplayAttributeForReportForm('ContactsModule', 'Contact', $report->getType());
     $displayAttribute->attributeIndexOrDerivedType = 'lastName';
     $report->addDisplayAttribute($displayAttribute);
     $savedReport = new SavedReport();
     SavedReportToReportAdapter::resolveReportToSavedReport($report, $savedReport);
     $saved = $savedReport->save();
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
     return $savedReport;
 }
 public function testCalculateTotalGroupingsCount()
 {
     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);
     $reportDataProvider = new MatrixReportDataProvider($report);
     $count = $reportDataProvider->calculateTotalGroupingsCount();
     $this->assertEquals(0, $count);
 }
 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);
 }
 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());
 }
 /**
  * @depends testGetAttributesForChartSeries
  */
 public function testGetAttributesForChartRange()
 {
     $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->getAttributesForChartRange($report->getDisplayAttributes());
     $this->assertEquals(0, count($attributes));
     //Add a display attribute that cannot be a range
     $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
     $displayAttribute->attributeIndexOrDerivedType = 'dropDown';
     $report->setModuleClassName('ReportsTestModule');
     $report->addDisplayAttribute($displayAttribute);
     $attributes = $adapter->getAttributesForChartRange($report->getDisplayAttributes());
     $this->assertEquals(0, count($attributes));
     //Add a display attribute that can be a range
     $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
     $displayAttribute->attributeIndexOrDerivedType = 'float__Summation';
     $report->setModuleClassName('ReportsTestModule');
     $report->addDisplayAttribute($displayAttribute);
     $attributes = $adapter->getAttributesForChartRange($report->getDisplayAttributes());
     $this->assertEquals(1, count($attributes));
     $compareData = array('label' => 'Float -(Sum)');
     $this->assertEquals($compareData, $attributes['float__Summation']);
     //Add a second display attribute that can be a range
     $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', $report->getType());
     $displayAttribute->attributeIndexOrDerivedType = 'float__Average';
     $report->setModuleClassName('ReportsTestModule');
     $report->addDisplayAttribute($displayAttribute);
     $attributes = $adapter->getAttributesForChartRange($report->getDisplayAttributes());
     $this->assertEquals(2, count($attributes));
     $compareData = array('label' => 'Float -(Sum)');
     $this->assertEquals($compareData, $attributes['float__Summation']);
     $compareData = array('label' => 'Float -(Avg)');
     $this->assertEquals($compareData, $attributes['float__Average']);
 }
 /**
  * Running a report centered on notes, with a display attribute from notes and accounts. With a created
  * by dateTime filter should produce proper query filter notes.
  * This test just makes sure the sql is structured properly
  */
 public function testFiltersWorksOnAccountsAndNoteReport()
 {
     $report = new Report();
     $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
     $filter = new FilterForReportForm('NotesModule', 'Note', $report->getType());
     $filter->attributeIndexOrDerivedType = 'createdDateTime';
     $filter->valueType = MixedDateTypesSearchFormAttributeMappingRules::TYPE_BETWEEN;
     $filter->value = '1991-05-05';
     $filter->secondValue = '1991-06-05';
     $filter->availableAtRunTime = true;
     $report->addFilter($filter);
     $report->setFiltersStructure('1');
     $report->setModuleClassName('NotesModule');
     $displayAttribute = new DisplayAttributeForReportForm('NotesModule', 'Note', $report->getType());
     $displayAttribute->attributeIndexOrDerivedType = 'description';
     $report->addDisplayAttribute($displayAttribute);
     $displayAttribute2 = new DisplayAttributeForReportForm('NotesModule', 'Note', $report->getType());
     $displayAttribute2->attributeIndexOrDerivedType = 'Account__activityItems__Inferred___name';
     $report->addDisplayAttribute($displayAttribute2);
     $reportDataProvider = new RowsAndColumnsReportDataProvider($report);
     $sql = $reportDataProvider->makeSqlQueryForDisplay();
     $q = DatabaseCompatibilityUtil::getQuote();
     $compareSql = "select {$q}note{$q}.{$q}id{$q} noteid, {$q}account{$q}.{$q}id{$q} accountid " . "from ({$q}note{$q}, {$q}activity{$q}, {$q}ownedsecurableitem{$q} ownedsecurableitem1, {$q}securableitem{$q} securableitem1, {$q}item{$q} item1) " . "left join {$q}activity_item{$q} on {$q}activity_item{$q}.{$q}activity_id{$q} = {$q}activity{$q}.{$q}id{$q} " . "left join {$q}item{$q} on {$q}item{$q}.{$q}id{$q} = {$q}activity_item{$q}.{$q}item_id{$q} " . "left join {$q}securableitem{$q} on {$q}securableitem{$q}.{$q}item_id{$q} = {$q}item{$q}.{$q}id{$q} " . "left join {$q}ownedsecurableitem{$q} on {$q}ownedsecurableitem{$q}.{$q}securableitem_id{$q} = {$q}securableitem{$q}.{$q}id{$q} " . "left join {$q}account{$q} on {$q}account{$q}.{$q}ownedsecurableitem_id{$q} = {$q}ownedsecurableitem{$q}.{$q}id{$q} " . "where ((({$q}item1{$q}.{$q}createddatetime{$q} >= '1991-05-05 00:00:00') " . "and ({$q}item1{$q}.{$q}createddatetime{$q} <= '1991-06-05 23:59:59'))) " . "and {$q}activity{$q}.{$q}id{$q} = {$q}note{$q}.{$q}activity_id{$q} " . "and {$q}ownedsecurableitem1{$q}.{$q}id{$q} = {$q}activity{$q}.{$q}ownedsecurableitem_id{$q} " . "and {$q}securableitem1{$q}.{$q}id{$q} = {$q}ownedsecurableitem1{$q}.{$q}securableitem_id{$q} " . "and {$q}item1{$q}.{$q}id{$q} = {$q}securableitem1{$q}.{$q}item_id{$q} limit 10 offset 0";
     $this->assertEquals($compareSql, $sql);
 }
 public function testGetDataStacked()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $data = array(1 => array(ReportDataProviderToAmChartMakerAdapter::FIRST_SERIES_VALUE . 0 => 500.42134), 2 => array(ReportDataProviderToAmChartMakerAdapter::SECOND_SERIES_VALUE . 0 => 32));
     $secondSeriesValueData = array(0);
     $secondSeriesDisplayLabels = array();
     $secondSeriesValueCount = 5;
     $chart = new ChartForReportForm();
     $chart->type = 'StackedBar3D';
     $chart->firstSeries = 'dropDown';
     $chart->firstRange = 'float__Summation';
     $chart->secondSeries = 'radioDropDown';
     $chart->secondRange = 'integer__Summation';
     $report = new Report();
     $report->setChart($chart);
     $displayAttribute = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute->attributeIndexOrDerivedType = 'float__Summation';
     $report->addDisplayAttribute($displayAttribute);
     $displayAttribute2 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute2->attributeIndexOrDerivedType = 'integer__Summation';
     $report->addDisplayAttribute($displayAttribute2);
     $adapter = new ReportDataProviderToAmChartMakerAdapter($report, $data, $secondSeriesValueData, $secondSeriesDisplayLabels, $secondSeriesValueCount);
     $compareData = array(1 => array('FirstSeriesValue0' => 500.42134, 'FirstSeriesFormattedValue0' => 500.421), 2 => array('SecondSeriesValue0' => 32, 'SecondSeriesFormattedValue0' => 32));
     $this->assertEquals($compareData, $adapter->getData());
     //todo: more coverage needed. date, dateTime, string, and currency
 }
 public function testGetDataWithNoRelationsSet()
 {
     $values = array('Test1', 'Test2', 'Test3', 'Sample', 'Demo');
     $customFieldData = CustomFieldData::getByName('ReportTestDropDown');
     $customFieldData->serializedData = serialize($values);
     $saved = $customFieldData->save();
     $this->assertTrue($saved);
     //for fullname attribute  (derived attribute)
     $reportModelTestItem1 = new ReportModelTestItem();
     $reportModelTestItem1->firstName = 'xFirst';
     $reportModelTestItem1->lastName = 'xLast';
     $reportModelTestItem1->boolean = true;
     $reportModelTestItem1->date = '2013-02-12';
     $reportModelTestItem1->dateTime = '2013-02-12 10:15:00';
     $reportModelTestItem1->float = 10.5;
     $reportModelTestItem1->integer = 10;
     $reportModelTestItem1->phone = '7842151012';
     $reportModelTestItem1->string = 'xString';
     $reportModelTestItem1->textArea = 'xtextAreatest';
     $reportModelTestItem1->url = 'http://www.test.com';
     $reportModelTestItem1->dropDown->value = $values[1];
     $currencies = Currency::getAll();
     $currencyValue = new CurrencyValue();
     $currencyValue->value = 100;
     $currencyValue->currency = $currencies[0];
     $this->assertEquals('USD', $currencyValue->currency->code);
     $reportModelTestItem1->currencyValue = $currencyValue;
     $reportModelTestItem1->primaryAddress->street1 = 'someString';
     $reportModelTestItem1->primaryEmail->emailAddress = "*****@*****.**";
     $customFieldValue = new CustomFieldValue();
     $customFieldValue->value = 'Multi 1';
     $reportModelTestItem1->multiDropDown->values->add($customFieldValue);
     $customFieldValue = new CustomFieldValue();
     $customFieldValue->value = 'Multi 2';
     $reportModelTestItem1->multiDropDown->values->add($customFieldValue);
     $customFieldValue = new CustomFieldValue();
     $customFieldValue->value = 'Cloud 2';
     $reportModelTestItem1->tagCloud->values->add($customFieldValue);
     $customFieldValue = new CustomFieldValue();
     $customFieldValue->value = 'Cloud 3';
     $reportModelTestItem1->tagCloud->values->add($customFieldValue);
     $reportModelTestItem1->radioDropDown->value = $values[1];
     $reportModelTestItem7 = new ReportModelTestItem7();
     $reportModelTestItem7->name = 'someName';
     $reportModelTestItem1->likeContactState = $reportModelTestItem7;
     $reportModelTestItem1->owner = Yii::app()->user->userModel;
     $saved = $reportModelTestItem1->save();
     $this->assertTrue($saved);
     $reportModelTestItem2 = new ReportModelTestItem();
     $reportModelTestItem2->firstName = 'xFirst';
     $reportModelTestItem2->lastName = 'xLast';
     $reportModelTestItem2->boolean = true;
     $reportModelTestItem2->date = '2013-02-14';
     $reportModelTestItem2->dateTime = '2013-02-14 23:15:00';
     $reportModelTestItem2->float = 200.5;
     $reportModelTestItem2->integer = 1010;
     $reportModelTestItem2->phone = '7842151012';
     $reportModelTestItem2->string = 'xString';
     $reportModelTestItem2->textArea = 'xtextAreatest';
     $reportModelTestItem2->url = 'http://www.test.com';
     $reportModelTestItem2->dropDown->value = $values[1];
     $reportModelTestItem2->currencyValue = $currencyValue;
     $reportModelTestItem2->primaryAddress->street1 = 'someString';
     $reportModelTestItem2->primaryEmail->emailAddress = "*****@*****.**";
     $reportModelTestItem2->multiDropDown->values->add($customFieldValue);
     $reportModelTestItem2->tagCloud->values->add($customFieldValue);
     $reportModelTestItem2->radioDropDown->value = $values[1];
     $reportModelTestItem2->likeContactState = $reportModelTestItem7;
     $reportModelTestItem2->owner = Yii::app()->user->userModel;
     $saved = $reportModelTestItem2->save();
     $this->assertTrue($saved);
     $report = new Report();
     $report->setType(Report::TYPE_SUMMATION);
     $report->setModuleClassName('ReportsTestModule');
     $report->setFiltersStructure('');
     //for date summation
     $displayAttribute1 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute1->attributeIndexOrDerivedType = 'date__Maximum';
     $displayAttribute1->madeViaSelectInsteadOfViaModel = true;
     $this->assertTrue($displayAttribute1->columnAliasName == 'col0');
     $report->addDisplayAttribute($displayAttribute1);
     $displayAttribute2 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute2->attributeIndexOrDerivedType = 'date__Minimum';
     $displayAttribute2->madeViaSelectInsteadOfViaModel = true;
     $this->assertTrue($displayAttribute2->columnAliasName == 'col1');
     $report->addDisplayAttribute($displayAttribute2);
     //for dateTime summation
     $displayAttribute3 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute3->attributeIndexOrDerivedType = 'dateTime__Maximum';
     $displayAttribute3->madeViaSelectInsteadOfViaModel = true;
     $this->assertTrue($displayAttribute3->columnAliasName == 'col2');
     $report->addDisplayAttribute($displayAttribute3);
     $displayAttribute4 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute4->attributeIndexOrDerivedType = 'dateTime__Minimum';
     $displayAttribute4->madeViaSelectInsteadOfViaModel = true;
     $this->assertTrue($displayAttribute4->columnAliasName == 'col3');
     $report->addDisplayAttribute($displayAttribute4);
     //for createdDateTime summation
     $displayAttribute5 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute5->attributeIndexOrDerivedType = 'createdDateTime__Maximum';
     $displayAttribute5->madeViaSelectInsteadOfViaModel = true;
     $this->assertTrue($displayAttribute5->columnAliasName == 'col4');
     $report->addDisplayAttribute($displayAttribute5);
     $displayAttribute6 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute6->attributeIndexOrDerivedType = 'createdDateTime__Minimum';
     $displayAttribute6->madeViaSelectInsteadOfViaModel = true;
     $this->assertTrue($displayAttribute6->columnAliasName == 'col5');
     $report->addDisplayAttribute($displayAttribute6);
     //for modifiedDateTime summation
     $displayAttribute7 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute7->attributeIndexOrDerivedType = 'modifiedDateTime__Maximum';
     $displayAttribute7->madeViaSelectInsteadOfViaModel = true;
     $this->assertTrue($displayAttribute7->columnAliasName == 'col6');
     $report->addDisplayAttribute($displayAttribute7);
     $displayAttribute8 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute8->attributeIndexOrDerivedType = 'modifiedDateTime__Minimum';
     $displayAttribute8->madeViaSelectInsteadOfViaModel = true;
     $this->assertTrue($displayAttribute8->columnAliasName == 'col7');
     $report->addDisplayAttribute($displayAttribute8);
     //for float summation
     $displayAttribute9 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute9->attributeIndexOrDerivedType = 'float__Minimum';
     $displayAttribute9->madeViaSelectInsteadOfViaModel = true;
     $this->assertTrue($displayAttribute9->columnAliasName == 'col8');
     $report->addDisplayAttribute($displayAttribute9);
     $displayAttribute10 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute10->attributeIndexOrDerivedType = 'float__Maximum';
     $displayAttribute10->madeViaSelectInsteadOfViaModel = true;
     $this->assertTrue($displayAttribute10->columnAliasName == 'col9');
     $report->addDisplayAttribute($displayAttribute10);
     $displayAttribute11 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute11->attributeIndexOrDerivedType = 'float__Summation';
     $displayAttribute11->madeViaSelectInsteadOfViaModel = true;
     $this->assertTrue($displayAttribute11->columnAliasName == 'col10');
     $report->addDisplayAttribute($displayAttribute11);
     $displayAttribute12 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute12->attributeIndexOrDerivedType = 'float__Average';
     $displayAttribute12->madeViaSelectInsteadOfViaModel = true;
     $this->assertTrue($displayAttribute12->columnAliasName == 'col11');
     $report->addDisplayAttribute($displayAttribute12);
     //for integer summation
     $displayAttribute13 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute13->attributeIndexOrDerivedType = 'integer__Minimum';
     $displayAttribute13->madeViaSelectInsteadOfViaModel = true;
     $this->assertTrue($displayAttribute13->columnAliasName == 'col12');
     $report->addDisplayAttribute($displayAttribute13);
     $displayAttribute14 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute14->attributeIndexOrDerivedType = 'integer__Maximum';
     $displayAttribute14->madeViaSelectInsteadOfViaModel = true;
     $this->assertTrue($displayAttribute14->columnAliasName == 'col13');
     $report->addDisplayAttribute($displayAttribute14);
     $displayAttribute15 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute15->attributeIndexOrDerivedType = 'integer__Summation';
     $displayAttribute15->madeViaSelectInsteadOfViaModel = true;
     $this->assertTrue($displayAttribute15->columnAliasName == 'col14');
     $report->addDisplayAttribute($displayAttribute15);
     $displayAttribute16 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute16->attributeIndexOrDerivedType = 'integer__Average';
     $displayAttribute16->madeViaSelectInsteadOfViaModel = true;
     $this->assertTrue($displayAttribute16->columnAliasName == 'col15');
     $report->addDisplayAttribute($displayAttribute16);
     //for currency summation
     $displayAttribute17 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute17->attributeIndexOrDerivedType = 'currencyValue__Minimum';
     $displayAttribute17->madeViaSelectInsteadOfViaModel = true;
     $this->assertTrue($displayAttribute17->columnAliasName == 'col16');
     $report->addDisplayAttribute($displayAttribute17);
     $displayAttribute18 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute18->attributeIndexOrDerivedType = 'currencyValue__Maximum';
     $displayAttribute18->madeViaSelectInsteadOfViaModel = true;
     $this->assertTrue($displayAttribute18->columnAliasName == 'col17');
     $report->addDisplayAttribute($displayAttribute18);
     $displayAttribute19 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute19->attributeIndexOrDerivedType = 'currencyValue__Summation';
     $displayAttribute19->madeViaSelectInsteadOfViaModel = true;
     $this->assertTrue($displayAttribute19->columnAliasName == 'col18');
     $report->addDisplayAttribute($displayAttribute19);
     $displayAttribute20 = new DisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $displayAttribute20->attributeIndexOrDerivedType = 'currencyValue__Average';
     $displayAttribute20->madeViaSelectInsteadOfViaModel = true;
     $this->assertTrue($displayAttribute20->columnAliasName == 'col19');
     $report->addDisplayAttribute($displayAttribute20);
     $dataProvider = new SummationReportDataProvider($report);
     $adapter = ReportToExportAdapterFactory::createReportToExportAdapter($report, $dataProvider);
     $compareHeaderData = array('Date -(Max)', 'Date -(Min)', 'Date Time -(Max)', 'Date Time -(Min)', 'Created Date Time -(Max)', 'Created Date Time -(Min)', 'Modified Date Time -(Max)', 'Modified Date Time -(Min)', 'Float -(Min)', 'Float -(Max)', 'Float -(Sum)', 'Float -(Avg)', 'Integer -(Min)', 'Integer -(Max)', 'Integer -(Sum)', 'Integer -(Avg)', 'Currency Value -(Min)', 'Currency Value -(Min) Currency', 'Currency Value -(Max)', 'Currency Value -(Max) Currency', 'Currency Value -(Sum)', 'Currency Value -(Sum) Currency', 'Currency Value -(Avg)', 'Currency Value -(Avg) Currency');
     $compareRowData = array(array('2013-02-14', '2013-02-12', '2013-02-14 23:15:00', '2013-02-12 10:15:00', $reportModelTestItem2->createdDateTime, $reportModelTestItem1->createdDateTime, $reportModelTestItem2->modifiedDateTime, $reportModelTestItem1->modifiedDateTime, 10.5, 200.5, 211, 105.5, 10, 1010, 1020, 510, 100, 'Mixed Currency', 100, 'Mixed Currency', 200, 'Mixed Currency', 100, 'Mixed Currency'), array('Total', '2013-02-12', '2013-02-14 23:15:00', '2013-02-12 10:15:00', $reportModelTestItem2->createdDateTime, $reportModelTestItem1->createdDateTime, $reportModelTestItem2->modifiedDateTime, $reportModelTestItem1->modifiedDateTime, 10.5, 200.5, 211, 105.5, 10, 1010, 1020, 510, 100, '', 100, '', 200, '', 100, ''));
     $this->assertEquals($compareHeaderData, $adapter->getHeaderData());
     $this->assertEquals($compareRowData, $adapter->getData());
     //With drill down
     $groupBy = new GroupByForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $groupBy->attributeIndexOrDerivedType = 'firstName';
     $report->addGroupBy($groupBy);
     $drillDownDisplayAttribute1 = new DrillDownDisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $drillDownDisplayAttribute1->attributeIndexOrDerivedType = 'float';
     $report->addDrillDownDisplayAttribute($drillDownDisplayAttribute1);
     $drillDownDisplayAttribute2 = new DrillDownDisplayAttributeForReportForm('ReportsTestModule', 'ReportModelTestItem', Report::TYPE_SUMMATION);
     $drillDownDisplayAttribute2->attributeIndexOrDerivedType = 'integer';
     $report->addDrillDownDisplayAttribute($drillDownDisplayAttribute2);
     $dataProvider = new SummationReportDataProvider($report);
     $adapter = ReportToExportAdapterFactory::createReportToExportAdapter($report, $dataProvider);
     $compareHeaderData = array('Date -(Max)', 'Date -(Min)', 'Date Time -(Max)', 'Date Time -(Min)', 'Created Date Time -(Max)', 'Created Date Time -(Min)', 'Modified Date Time -(Max)', 'Modified Date Time -(Min)', 'Float -(Min)', 'Float -(Max)', 'Float -(Sum)', 'Float -(Avg)', 'Integer -(Min)', 'Integer -(Max)', 'Integer -(Sum)', 'Integer -(Avg)', 'Currency Value -(Min)', 'Currency Value -(Min) Currency', 'Currency Value -(Max)', 'Currency Value -(Max) Currency', 'Currency Value -(Sum)', 'Currency Value -(Sum) Currency', 'Currency Value -(Avg)', 'Currency Value -(Avg) Currency', 'First Name');
     $compareRowData = array(array('2013-02-14', '2013-02-12', '2013-02-14 23:15:00', '2013-02-12 10:15:00', $reportModelTestItem2->createdDateTime, $reportModelTestItem1->createdDateTime, $reportModelTestItem2->modifiedDateTime, $reportModelTestItem1->modifiedDateTime, 10.5, 200.5, 211, 105.5, 10, 1010, 1020, 510, 100, 'Mixed Currency', 100, 'Mixed Currency', 200, 'Mixed Currency', 100, 'Mixed Currency', 'xFirst'), array(null, 'Float', 'Integer'), array(null, '10.5', '10'), array(null, '200.5', '1010'), array('Total', '2013-02-12', '2013-02-14 23:15:00', '2013-02-12 10:15:00', $reportModelTestItem2->createdDateTime, $reportModelTestItem1->createdDateTime, $reportModelTestItem2->modifiedDateTime, $reportModelTestItem1->modifiedDateTime, 10.5, 200.5, 211, 105.5, 10, 1010, 1020, 510, 100, '', 100, '', 200, '', 100, ''));
     $this->assertEquals($compareHeaderData, $adapter->getHeaderData());
     $this->assertEquals($compareRowData, $adapter->getData());
 }
 /**
  * @param array $data
  * @param Report $report
  */
 protected static function resolveDisplayAttributes($data, Report $report)
 {
     $report->removeAllDisplayAttributes();
     DisplayAttributeForReportForm::resetCount();
     $moduleClassName = $report->getModuleClassName();
     if (count($displayAttributesData = ArrayUtil::getArrayValue($data, ComponentForReportForm::TYPE_DISPLAY_ATTRIBUTES)) > 0) {
         foreach ($displayAttributesData as $key => $displayAttributeData) {
             $displayAttribute = new DisplayAttributeForReportForm($moduleClassName, $moduleClassName::getPrimaryModelName(), $report->getType(), $key);
             $displayAttribute->setAttributes($displayAttributeData);
             $report->addDisplayAttribute($displayAttribute);
         }
     } else {
         $report->removeAllDisplayAttributes();
     }
 }
示例#17
0
 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());
     $report->removeAllDisplayAttributes();
     //Billy can see a drillDownDisplayAttribute on Accounts
     $drillDownDisplayAttribute = new DrillDownDisplayAttributeForReportForm('AccountsModule', 'Account', $report->getType());
     $drillDownDisplayAttribute->attributeIndexOrDerivedType = 'name';
     $drillDownDisplayAttribute->label = 'someNewLabel';
     $report->addDrillDownDisplayAttribute($drillDownDisplayAttribute);
     $this->assertTrue($report->canCurrentUserProperlyRenderResults());
     //Billy cannot see a related drillDownDisplayAttribute on Contacts
     $drillDownDisplayAttribute = new DrillDownDisplayAttributeForReportForm('AccountsModule', 'Account', $report->getType());
     $drillDownDisplayAttribute->attributeIndexOrDerivedType = 'contacts___firstName';
     $drillDownDisplayAttribute->label = 'someNewLabel';
     $report->addDrillDownDisplayAttribute($drillDownDisplayAttribute);
     $this->assertFalse($report->canCurrentUserProperlyRenderResults());
     //Billy can see a related drillDownDisplayAttribute on Opportunities
     $report->removeAllDrillDownDisplayAttributes();
     $drillDownDisplayAttribute = new DrillDownDisplayAttributeForReportForm('AccountsModule', 'Account', $report->getType());
     $drillDownDisplayAttribute->attributeIndexOrDerivedType = 'opportunities___name';
     $drillDownDisplayAttribute->label = 'someNewLabel';
     $report->addDrillDownDisplayAttribute($drillDownDisplayAttribute);
     $this->assertTrue($report->canCurrentUserProperlyRenderResults());
 }
示例#18
0
 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 testResolveFiltersForVariableStatesWithOneDisplayAttributeAndOneFilterForANonSuperUserWhoCanSeeAnotherState()
 {
     Yii::app()->user->userModel = User::getByUsername('sarah');
     $report = new Report();
     $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
     $report->setModuleClassName('AccountsModule');
     $displayAttribute = new DisplayAttributeForReportForm('AccountsModule', 'Account', Report::TYPE_ROWS_AND_COLUMNS);
     $displayAttribute->attributeIndexOrDerivedType = 'contacts___officePhone';
     $report->addDisplayAttribute($displayAttribute);
     $reportDataProvider = new RowsAndColumnsReportDataProvider($report);
     $filtersStructure = '1';
     $filter = new FilterForReportForm('AccountsModule', 'Account', Report::TYPE_ROWS_AND_COLUMNS);
     $filter->attributeIndexOrDerivedType = 'opportunities___contacts___website';
     $filter->operator = OperatorRules::TYPE_EQUALS;
     $filter->value = 'Zurmo';
     $filters = array($filter);
     $filters = $reportDataProvider->resolveFiltersForVariableStates($filters, $filtersStructure);
     $stateAdapter = new LeadsStateMetadataAdapter(array('clauses' => array(), 'structure' => ''));
     $this->assertTrue(count($stateAdapter->getStateIds()) > 0);
     $this->assertEquals(3, count($filters));
     $this->assertEquals('contacts___state', $filters[1]->attributeIndexOrDerivedType);
     $this->assertEquals(OperatorRules::TYPE_ONE_OF, $filters[1]->operator);
     $this->assertEquals($stateAdapter->getStateIds(), $filters[1]->value);
     $this->assertEquals('opportunities___contacts___state', $filters[2]->attributeIndexOrDerivedType);
     $this->assertEquals(OperatorRules::TYPE_ONE_OF, $filters[2]->operator);
     $this->assertEquals($stateAdapter->getStateIds(), $filters[2]->value);
     $this->assertEquals('1 and (2 and 3)', $filtersStructure);
 }
 /**
  * Running a report centered on notes, with a display attribute from notes and accounts.  Ordered by
  * created date time in notes.  Should produce proper query to order by notes.  This test just makes sure
  * the sql is structured properly
  */
 public function testOrderByWorksOnAccountsAndNoteReport()
 {
     $report = new Report();
     $report->setFiltersStructure('');
     $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
     $report->setModuleClassName('NotesModule');
     $displayAttribute = new DisplayAttributeForReportForm('NotesModule', 'Note', $report->getType());
     $displayAttribute->attributeIndexOrDerivedType = 'description';
     $report->addDisplayAttribute($displayAttribute);
     $displayAttribute2 = new DisplayAttributeForReportForm('NotesModule', 'Note', $report->getType());
     $displayAttribute2->attributeIndexOrDerivedType = 'Account__activityItems__Inferred___name';
     $report->addDisplayAttribute($displayAttribute2);
     $orderBy = new OrderByForReportForm('NotesModule', 'Note', Report::TYPE_SUMMATION);
     $orderBy->attributeIndexOrDerivedType = 'createdDateTime';
     $report->addOrderBy($orderBy);
     $reportDataProvider = new RowsAndColumnsReportDataProvider($report);
     $sql = $reportDataProvider->makeSqlQueryForDisplay();
     $q = DatabaseCompatibilityUtil::getQuote();
     $compareSql = "select {$q}note{$q}.{$q}id{$q} noteid, {$q}account{$q}.{$q}id{$q} accountid " . "from ({$q}note{$q}, {$q}activity{$q}, {$q}ownedsecurableitem{$q} ownedsecurableitem1, {$q}securableitem{$q} securableitem1, {$q}item{$q} item1) " . "left join {$q}activity_item{$q} on {$q}activity_item{$q}.{$q}activity_id{$q} = {$q}activity{$q}.{$q}id{$q} " . "left join {$q}item{$q} on {$q}item{$q}.{$q}id{$q} = {$q}activity_item{$q}.{$q}item_id{$q} " . "left join {$q}securableitem{$q} on {$q}securableitem{$q}.{$q}item_id{$q} = {$q}item{$q}.{$q}id{$q} " . "left join {$q}ownedsecurableitem{$q} on {$q}ownedsecurableitem{$q}.{$q}securableitem_id{$q} = {$q}securableitem{$q}.{$q}id{$q} " . "left join {$q}account{$q} on {$q}account{$q}.{$q}ownedsecurableitem_id{$q} = {$q}ownedsecurableitem{$q}.{$q}id{$q}  " . "where {$q}activity{$q}.{$q}id{$q} = {$q}note{$q}.{$q}activity_id{$q} and " . "{$q}ownedsecurableitem1{$q}.{$q}id{$q} = {$q}activity{$q}.{$q}ownedsecurableitem_id{$q} " . "and {$q}securableitem1{$q}.{$q}id{$q} = {$q}ownedsecurableitem1{$q}.{$q}securableitem_id{$q} and " . "{$q}item1{$q}.{$q}id{$q} = {$q}securableitem1{$q}.{$q}item_id{$q} order by {$q}item1{$q}.{$q}createddatetime{$q} asc limit 10 offset 0";
     $this->assertEquals($compareSql, $sql);
 }