/**
  * @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();
 }
 /**
  * @param ModelRelationsAndAttributesToReportAdapter $modelToReportAdapter
  * @param RedBeanModel $precedingModel
  * @param null|string $precedingRelation
  * @throws NotSupportedException if the treeType is invalid or null
  */
 protected function getAttributesData(ModelRelationsAndAttributesToReportAdapter $modelToReportAdapter, RedBeanModel $precedingModel = null, $precedingRelation = null)
 {
     if ($this->treeType == ComponentForReportForm::TYPE_FILTERS) {
         return $modelToReportAdapter->getAttributesForFilters();
     } elseif ($this->treeType == ComponentForReportForm::TYPE_DISPLAY_ATTRIBUTES) {
         return $modelToReportAdapter->getAttributesForDisplayAttributes($this->report->getGroupBys(), $precedingModel, $precedingRelation);
     } elseif ($this->treeType == ComponentForReportForm::TYPE_ORDER_BYS) {
         return $modelToReportAdapter->getAttributesForOrderBys($this->report->getGroupBys(), $this->report->getDisplayAttributes(), $precedingModel, $precedingRelation);
     } elseif ($this->treeType == ComponentForReportForm::TYPE_GROUP_BYS) {
         return $modelToReportAdapter->getAttributesForGroupBys($precedingModel, $precedingRelation);
     } elseif ($this->treeType == ComponentForReportForm::TYPE_DRILL_DOWN_DISPLAY_ATTRIBUTES) {
         return $modelToReportAdapter->getForDrillDownAttributes($precedingModel, $precedingRelation);
     } else {
         throw new NotSupportedException();
     }
 }
 /**
  * @return array
  */
 public function resolveDisplayAttributes()
 {
     return $this->report->getDisplayAttributes();
 }
 /**
  * @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 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']));
 }
 /**
  * @param Report $report
  * @param SavedReport$savedReport
  */
 public static function resolveReportToSavedReport(Report $report, SavedReport $savedReport)
 {
     $savedReport->description = $report->getDescription();
     $savedReport->moduleClassName = $report->getModuleClassName();
     $savedReport->name = $report->getName();
     $savedReport->owner = $report->getOwner();
     $savedReport->type = $report->getType();
     $data = array();
     $data['filtersStructure'] = $report->getFiltersStructure();
     $data['currencyConversionType'] = $report->getCurrencyConversionType();
     $data['spotConversionCurrencyCode'] = $report->getSpotConversionCurrencyCode();
     $data[ComponentForReportForm::TYPE_FILTERS] = self::makeArrayFromComponentFormsAttributesData($report->getFilters());
     $data[ComponentForReportForm::TYPE_ORDER_BYS] = self::makeArrayFromComponentFormsAttributesData($report->getOrderBys());
     $data[ComponentForReportForm::TYPE_GROUP_BYS] = self::makeArrayFromComponentFormsAttributesData($report->getGroupBys());
     $data[ComponentForReportForm::TYPE_DISPLAY_ATTRIBUTES] = self::makeArrayFromComponentFormsAttributesData($report->getDisplayAttributes());
     $data[ComponentForReportForm::TYPE_DRILL_DOWN_DISPLAY_ATTRIBUTES] = self::makeArrayFromComponentFormsAttributesData($report->getDrillDownDisplayAttributes());
     if ($report->getChart()->type != null) {
         $data['chart'] = self::makeArrayFromChartForReportFormAttributesData($report->getChart());
     }
     $savedReport->serializedData = serialize($data);
 }
 /**
  * @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']);
 }