Ejemplo n.º 1
0
 /**
  * @param Report $report
  * @param $pageSize
  * @return MatrixReportDataProvider|RowsAndColumnsReportDataProvider|SummationReportDataProvider
  * @throws NotSupportedException
  */
 public static function makeByReport(Report $report, $pageSize)
 {
     $config = array('pagination' => array('pageSize' => $pageSize));
     if ($report->getType() == Report::TYPE_ROWS_AND_COLUMNS) {
         $dataProvider = new RowsAndColumnsReportDataProvider($report, $config);
     } elseif ($report->getType() == Report::TYPE_SUMMATION) {
         $dataProvider = new SummationReportDataProvider($report, $config);
     } elseif ($report->getType() == Report::TYPE_MATRIX) {
         $dataProvider = new MatrixReportDataProvider($report);
     } else {
         throw new NotSupportedException();
     }
     return $dataProvider;
 }
 /**
  * @param Report $report
  * @param ReportDataProvider $dataProvider
  * @return ReportResultsGridView based object
  * @throws NotSupportedException if the report type is not valid or null
  */
 public static function makeByReportAndDataProvider($controllerId, $moduleId, Report $report, ReportDataProvider $dataProvider = null)
 {
     assert('is_string($controllerId)');
     assert('is_string($moduleId)');
     if ($report->getType() == Report::TYPE_ROWS_AND_COLUMNS) {
         $className = 'RowsAndColumnsReportResultsGridView';
     } elseif ($report->getType() == Report::TYPE_SUMMATION) {
         $className = 'SummationReportResultsGridView';
     } elseif ($report->getType() == Report::TYPE_MATRIX) {
         $className = 'MatrixReportResultsGridView';
     } else {
         throw new NotSupportedException();
     }
     return new $className($controllerId, $moduleId, $dataProvider);
 }
 /**
  * @param ReportWizardForm $formModel
  */
 protected function setCommonAttributes(ReportWizardForm $formModel)
 {
     $formModel->id = $this->report->getId();
     $formModel->description = $this->report->getDescription();
     $formModel->moduleClassName = $this->report->getModuleClassName();
     if ($this->report->getOwner()->id > 0) {
         $formModel->ownerId = (int) $this->report->getOwner()->id;
         $formModel->ownerName = strval($this->report->getOwner());
     }
     $formModel->name = $this->report->getName();
     $formModel->type = $this->report->getType();
     $formModel->filtersStructure = $this->report->getFiltersStructure();
     $formModel->currencyConversionType = $this->report->getCurrencyConversionType();
     $formModel->spotConversionCurrencyCode = $this->report->getSpotConversionCurrencyCode();
     if ($this->report->isNew()) {
         $formModel->setIsNew();
     }
     $formModel->setExplicitReadWriteModelPermissions($this->report->getExplicitReadWriteModelPermissions());
     $formModel->filters = $this->report->getFilters();
     $formModel->orderBys = $this->report->getOrderBys();
     $formModel->groupBys = $this->report->getGroupBys();
     $formModel->displayAttributes = $this->report->getDisplayAttributes();
     $formModel->drillDownDisplayAttributes = $this->report->getDrillDownDisplayAttributes();
     $formModel->chart = $this->report->getChart();
 }
 public static function createReportToExportAdapter(Report $report, ReportDataProvider $dataProvider)
 {
     $dataProviderClassName = get_class($dataProvider);
     if ($dataProviderClassName == 'SummationDrillDownReportDataProvider') {
         $className = 'SummationDrillDownReportToExportAdapter';
     } else {
         $className = $report->getType() . 'ReportToExportAdapter';
     }
     return new $className($dataProvider, $report);
 }
 /**
  * @param string $attributeIndexOrDerivedTypePrefix
  * @param array $variableStateData
  * @return FilterForReportForm
  */
 protected function resolveFilterForVariableStateAttributeIndex($attributeIndexOrDerivedTypePrefix, $variableStateData)
 {
     assert('is_string($attributeIndexOrDerivedTypePrefix) || $attributeIndexOrDerivedTypePrefix == null');
     assert('is_array($variableStateData) && count($variableStateData) == 2');
     $moduleClassName = $this->report->getModuleClassName();
     $filter = new FilterForReportForm($moduleClassName, $moduleClassName::getPrimaryModelName(), $this->report->getType());
     $filter->attributeIndexOrDerivedType = $attributeIndexOrDerivedTypePrefix . $variableStateData[0];
     $filter->operator = OperatorRules::TYPE_ONE_OF;
     $filter->value = $variableStateData[1];
     return $filter;
 }
 /**
  * @param Report $report
  * @return  MatrixReportStepsAndProgressBarForWizardView|
  *          RowsAndColumnsReportStepsAndProgressBarForWizardView|
  *          SummationReportStepsAndProgressBarForWizardView
  * @throws NotSupportedException
  */
 public static function makeStepsAndProgressBarViewFromReport(Report $report)
 {
     $type = $report->getType();
     if ($type == Report::TYPE_ROWS_AND_COLUMNS) {
         return new RowsAndColumnsReportStepsAndProgressBarForWizardView();
     } elseif ($type == Report::TYPE_SUMMATION) {
         return new SummationReportStepsAndProgressBarForWizardView();
     } elseif ($type == Report::TYPE_MATRIX) {
         return new MatrixReportStepsAndProgressBarForWizardView();
     } else {
         throw new NotSupportedException();
     }
 }
 /**
  * @param array $data
  * @param Report $report
  */
 protected static function resolveChart($data, Report $report)
 {
     if ($report->getType() != Report::TYPE_SUMMATION) {
         return;
     }
     $moduleClassName = $report->getModuleClassName();
     if ($moduleClassName != null) {
         $modelClassName = $moduleClassName::getPrimaryModelName();
         $adapter = ModelRelationsAndAttributesToSummationReportAdapter::make($moduleClassName, $modelClassName, $report->getType());
         $seriesDataAndLabels = ReportUtil::makeDataAndLabelsForSeriesOrRange($adapter->getAttributesForChartSeries($report->getGroupBys(), $report->getDisplayAttributes()));
         $rangeDataAndLabels = ReportUtil::makeDataAndLabelsForSeriesOrRange($adapter->getAttributesForChartRange($report->getDisplayAttributes()));
     } else {
         $seriesDataAndLabels = array();
         $rangeDataAndLabels = array();
     }
     $chart = new ChartForReportForm($seriesDataAndLabels, $rangeDataAndLabels);
     if (null != ($chartData = ArrayUtil::getArrayValue($data, 'ChartForReportForm'))) {
         $chart->setAttributes($chartData);
     }
     $report->setChart($chart);
 }
 /**
  * @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']);
 }
Ejemplo n.º 9
0
 /**
  * Process attribute addition from tree and than renders it.
  *
  * @param string $nodeId
  * @param string $treeType
  * @param Report $report
  * @param int $rowNumber
  * @param bool $trackableStructurePosition
  */
 public static function processAttributeAdditionFromTree($nodeId, $treeType, Report $report, $rowNumber, $trackableStructurePosition)
 {
     $nodeIdWithoutTreeType = ReportRelationsAndAttributesToTreeAdapter::removeTreeTypeFromNodeId($nodeId, $treeType);
     $moduleClassName = $report->getModuleClassName();
     $modelClassName = $moduleClassName::getPrimaryModelName();
     $form = new WizardActiveForm();
     $form->id = 'edit-form';
     $form->enableAjaxValidation = true;
     //ensures error validation populates correctly
     $wizardFormClassName = ReportToWizardFormAdapter::getFormClassNameByType($report->getType());
     $model = ComponentForReportFormFactory::makeByComponentType($moduleClassName, $modelClassName, $report->getType(), $treeType);
     $form->modelClassNameForError = $wizardFormClassName;
     $attribute = ReportRelationsAndAttributesToTreeAdapter::resolveAttributeByNodeId($nodeIdWithoutTreeType);
     $model->attributeIndexOrDerivedType = ReportRelationsAndAttributesToTreeAdapter::resolveAttributeByNodeId($nodeIdWithoutTreeType);
     $inputPrefixData = ReportRelationsAndAttributesToTreeAdapter::resolveInputPrefixData($wizardFormClassName, $treeType, (int) $rowNumber);
     $adapter = new ReportAttributeToElementAdapter($inputPrefixData, $model, $form, $treeType);
     $view = new AttributeRowForReportComponentView($adapter, (int) $rowNumber, $inputPrefixData, $attribute, (bool) $trackableStructurePosition, true, $treeType);
     $content = $view->render();
     $form->renderAddAttributeErrorSettingsScript($view::getFormId());
     Yii::app()->getClientScript()->setToAjaxMode();
     Yii::app()->getClientScript()->render($content);
     echo $content;
 }
 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');
 }
 protected function processFiltersAndStructureForMeetingsThatEndAfterRange(&$filters, &$structure, &$filtersCount, SavedCalendar $savedCalendar, Report $report)
 {
     if (count($filters) != 0) {
         $structure .= ' OR ';
     }
     $moduleClassName = $savedCalendar->moduleClassName;
     $startFilter = new FilterForReportForm($moduleClassName, $moduleClassName::getPrimaryModelName(), $report->getType());
     $startFilter->attributeIndexOrDerivedType = $savedCalendar->startAttributeName;
     $startFilter->value = $this->endDate;
     $startFilter->valueType = MixedDateTypesSearchFormAttributeMappingRules::TYPE_BEFORE;
     $filters[] = $startFilter;
     $endFilter = new FilterForReportForm($moduleClassName, $moduleClassName::getPrimaryModelName(), $report->getType());
     if ($savedCalendar->endAttributeName != null) {
         $endFilter->attributeIndexOrDerivedType = $savedCalendar->endAttributeName;
     } else {
         $endFilter->attributeIndexOrDerivedType = $savedCalendar->startAttributeName;
     }
     $endFilter->value = $this->endDate;
     $endFilter->valueType = MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER;
     $filters[] = $endFilter;
     $structure .= '(' . ($filtersCount + 1) . ' AND ' . ($filtersCount + 2) . ')';
     $filtersCount += 2;
 }
Ejemplo n.º 12
0
 /**
  * Save calendar with serialized data.
  * @param Report $report
  * @param SavedCalendar $savedCalendar
  * @param array $wizardFormPostData
  * @throws FailedToSaveModelException
  */
 public static function saveCalendarWithSerializedData(Report $report, SavedCalendar $savedCalendar, $wizardFormPostData)
 {
     $filtersData = ArrayUtil::getArrayValue($wizardFormPostData, ComponentForReportForm::TYPE_FILTERS);
     if ($filtersData != null) {
         $sanitizedFiltersData = DataToReportUtil::sanitizeFiltersData($report->getModuleClassName(), $report->getType(), $filtersData);
         $unserializedData = array(ComponentForReportForm::TYPE_FILTERS => $sanitizedFiltersData, 'filtersStructure' => $report->getFiltersStructure());
         $savedCalendar->serializedData = serialize($unserializedData);
     }
     if (!$savedCalendar->save()) {
         throw new FailedToSaveModelException();
     }
 }
 /**
  * @param array $componentFormsData
  * @param Report $report
  * @param null|string $componentPrefix
  */
 protected static function makeComponentFormAndPopulateReportFromData($componentFormsData, Report $report, $componentPrefix)
 {
     $moduleClassName = $report->getModuleClassName();
     $addMethodName = 'add' . $componentPrefix;
     $componentClassName = $componentPrefix . 'ForReportForm';
     $rowKey = 0;
     foreach ($componentFormsData as $componentFormData) {
         $component = new $componentClassName($moduleClassName, $moduleClassName::getPrimaryModelName(), $report->getType(), $rowKey);
         $component->setAttributes($componentFormData);
         $report->{$addMethodName}($component);
         $rowKey++;
     }
 }
 /**
  * @depends testIsRelation
  */
 public function testIsRelationASingularRelation()
 {
     $model = new ReportModelTestItem();
     $rules = new ReportsTestReportRules();
     $report = new Report();
     $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
     $report->setModuleClassName('ReportsTestModule');
     $adapter = new ModelRelationsAndAttributesToRowsAndColumnsReportAdapter($model, $rules, $report->getType());
     $this->assertTrue($adapter->isRelationASingularRelation('hasOne'));
     $this->assertFalse($adapter->isRelationASingularRelation('hasMany'));
     $model = new ReportModelTestItem5();
     $rules = new ReportsTestReportRules();
     $report = new Report();
     $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
     $report->setModuleClassName('ReportsTestModule');
     $adapter = new ModelRelationsAndAttributesToRowsAndColumnsReportAdapter($model, $rules, $report->getType());
     $this->assertFalse($adapter->isRelationASingularRelation('ReportModelTestItem2__reportItems__Inferred'));
     $this->assertFalse($adapter->isRelationASingularRelation('ReportModelTestItem__reportItems__Inferred'));
 }
Ejemplo n.º 15
0
 public function testRemoveRuntimeFilters()
 {
     $report = new Report();
     $report->setModuleClassName('ContactsModule');
     $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
     //A filter available at runtime
     $filter = new FilterForReportForm('AccountsModule', 'Account', $report->getType());
     $filter->availableAtRunTime = true;
     $filter->attributeIndexOrDerivedType = 'officePhone';
     $filter->value = 'aValue';
     $filter->operator = 'equals';
     $report->addFilter($filter);
     //A filter not available at runtime
     $filter2 = new FilterForReportForm('AccountsModule', 'Account', $report->getType());
     $filter2->availableAtRunTime = false;
     $filter2->attributeIndexOrDerivedType = 'contacts___lastName';
     $filter2->value = 'aValue';
     $filter2->operator = 'equals';
     $report->addFilter($filter2);
     $report->removeRuntimeFilters();
     $filters = $report->getFilters();
     $this->assertCount(1, $filters);
     $this->assertEquals($filter2, $filters[0]);
 }
 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;
 }
Ejemplo n.º 17
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 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);
 }
 /**
  * @param string $moduleClassName
  * @param string $modelClassName
  * @return ModelRelationsAndAttributesToReportAdapter based object
  */
 protected function makeModelRelationsAndAttributesToReportAdapter($moduleClassName, $modelClassName)
 {
     assert('is_string($moduleClassName)');
     assert('is_string($modelClassName)');
     return ModelRelationsAndAttributesToReportAdapter::make($moduleClassName, $modelClassName, $this->report->getType());
 }
 /**
  * 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);
 }
 /**
  * @depends testResolveRealAttributeName
  */
 public function testGetCalculationOrModifierType()
 {
     $model = new ReportModelTestItem();
     $rules = new ReportsTestReportRules();
     //ReportsTestModule rules
     $report = new Report();
     $report->setType(Report::TYPE_SUMMATION);
     $report->setModuleClassName('ReportsTestModule');
     $adapter = new ModelRelationsAndAttributesToSummationReportAdapter($model, $rules, $report->getType());
     $this->assertEquals('Maximum', $adapter->getCalculationOrModifierType('integer__Maximum'));
     $this->assertEquals('something', $adapter->getCalculationOrModifierType('something'));
 }
 /**
  * Sally cannot access notes, tasks, or contacts. User is always accessible regardless of right to access
  */
 public function testGetAllReportableRelationsAsANonElevatedUser()
 {
     Yii::app()->user->userModel = User::getByUsername('sally');
     $model = new Account();
     $rules = new AccountsReportRules();
     $report = new Report();
     $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
     $report->setModuleClassName('AccountsModule');
     $adapter = new ModelRelationsAndAttributesToReportAdapter($model, $rules, $report->getType());
     $relations = $adapter->getSelectableRelationsData();
     $relations = $adapter->getSelectableRelationsDataResolvedForUserAccess(Yii::app()->user->userModel, $relations);
     $this->assertEquals(9, count($relations));
     $compareData = array('label' => 'Billing Address');
     $this->assertEquals($compareData, $relations['billingAddress']);
     $compareData = array('label' => 'Created By User');
     $this->assertEquals($compareData, $relations['createdByUser']);
     $compareData = array('label' => 'Meetings');
     $this->assertEquals($compareData, $relations['meetings']);
     $compareData = array('label' => 'Modified By User');
     $this->assertEquals($compareData, $relations['modifiedByUser']);
     $compareData = array('label' => 'Opportunities');
     $this->assertEquals($compareData, $relations['opportunities']);
     $compareData = array('label' => 'Owner');
     $this->assertEquals($compareData, $relations['owner']);
     $compareData = array('label' => 'Primary Email');
     $this->assertEquals($compareData, $relations['primaryEmail']);
     $compareData = array('label' => 'Shipping Address');
     $this->assertEquals($compareData, $relations['shippingAddress']);
     $compareData = array('label' => 'Secondary Email');
     $this->assertEquals($compareData, $relations['secondaryEmail']);
 }
 /**
  * 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);
 }