/**
  * @param $savedCalendar
  * @return Report
  */
 public static function makeReportBySavedCalendar(SavedCalendar $savedCalendar)
 {
     $report = new Report();
     if ($savedCalendar->id > 0) {
         $report->setId((int) $savedCalendar->id);
     }
     $report->setDescription($savedCalendar->description);
     if ($savedCalendar->moduleClassName != null) {
         $report->setModuleClassName($savedCalendar->moduleClassName);
     }
     if ($savedCalendar->name != null) {
         $report->setName($savedCalendar->name);
     }
     $report->setOwner($savedCalendar->owner);
     $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
     $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($savedCalendar);
     $report->setExplicitReadWriteModelPermissions($explicitReadWriteModelPermissions);
     if ($savedCalendar->serializedData != null) {
         $unserializedData = unserialize($savedCalendar->serializedData);
         if (isset($unserializedData['filtersStructure'])) {
             $report->setFiltersStructure($unserializedData['filtersStructure']);
         }
         CalendarUtil::makeComponentFormAndPopulateReportFromData($unserializedData[ComponentForReportForm::TYPE_FILTERS], $report, 'Filter');
     }
     return $report;
 }
Exemple #2
0
 /**
  * @param Report $report
  * @param array $postData
  * @param string $wizardFormClassName
  */
 public static function resolveReportByWizardPostData(Report $report, $postData, $wizardFormClassName)
 {
     assert('is_array($postData)');
     assert('is_string($wizardFormClassName)');
     $data = ArrayUtil::getArrayValue($postData, $wizardFormClassName);
     if (isset($data['description'])) {
         $report->setDescription($data['description']);
     }
     if (isset($data['moduleClassName'])) {
         $report->setModuleClassName($data['moduleClassName']);
     }
     if (isset($data['name'])) {
         $report->setName($data['name']);
     }
     if (isset($data['filtersStructure'])) {
         $report->setFiltersStructure($data['filtersStructure']);
     }
     if (null != ArrayUtil::getArrayValue($data, 'ownerId')) {
         $owner = User::getById((int) $data['ownerId']);
         $report->setOwner($owner);
     } else {
         $report->setOwner(new User());
     }
     if (isset($data['currencyConversionType'])) {
         $report->setCurrencyConversionType((int) $data['currencyConversionType']);
     }
     if (isset($data['spotConversionCurrencyCode'])) {
         $report->setSpotConversionCurrencyCode($data['spotConversionCurrencyCode']);
     }
     self::resolveFilters($data, $report);
     self::resolveOrderBys($data, $report);
     self::resolveDisplayAttributes($data, $report);
     self::resolveDrillDownDisplayAttributes($data, $report);
     self::resolveGroupBys($data, $report);
     self::resolveChart($data, $report);
 }
 /**
  * @param $savedReport
  * @return Report
  */
 public static function makeReportBySavedReport($savedReport)
 {
     $report = new Report();
     if ($savedReport->id > 0) {
         $report->setId((int) $savedReport->id);
     }
     $report->setDescription($savedReport->description);
     $report->setModuleClassName($savedReport->moduleClassName);
     $report->setName($savedReport->name);
     $report->setOwner($savedReport->owner);
     $report->setType($savedReport->type);
     $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($savedReport);
     $report->setExplicitReadWriteModelPermissions($explicitReadWriteModelPermissions);
     if ($savedReport->serializedData != null) {
         $unserializedData = unserialize($savedReport->serializedData);
         if (isset($unserializedData['filtersStructure'])) {
             $report->setFiltersStructure($unserializedData['filtersStructure']);
         }
         if (isset($unserializedData['currencyConversionType'])) {
             $report->setCurrencyConversionType((int) $unserializedData['currencyConversionType']);
         }
         if (isset($unserializedData['spotConversionCurrencyCode'])) {
             $report->setSpotConversionCurrencyCode($unserializedData['spotConversionCurrencyCode']);
         }
         self::makeComponentFormAndPopulateReportFromData($unserializedData[ComponentForReportForm::TYPE_FILTERS], $report, 'Filter');
         self::makeComponentFormAndPopulateReportFromData($unserializedData[ComponentForReportForm::TYPE_ORDER_BYS], $report, 'OrderBy');
         self::makeComponentFormAndPopulateReportFromData($unserializedData[ComponentForReportForm::TYPE_GROUP_BYS], $report, 'GroupBy');
         self::makeComponentFormAndPopulateReportFromData($unserializedData[ComponentForReportForm::TYPE_DISPLAY_ATTRIBUTES], $report, 'DisplayAttribute');
         self::makeComponentFormAndPopulateReportFromData($unserializedData[ComponentForReportForm::TYPE_DRILL_DOWN_DISPLAY_ATTRIBUTES], $report, 'DrillDownDisplayAttribute');
         if (isset($unserializedData['chart'])) {
             $moduleClassName = $report->getModuleClassName();
             $modelClassName = $moduleClassName::getPrimaryModelName();
             $adapter = ModelRelationsAndAttributesToSummationReportAdapter::make($moduleClassName, $modelClassName, $report->getType());
             $chart = new ChartForReportForm(ReportUtil::makeDataAndLabelsForSeriesOrRange($adapter->getAttributesForChartSeries($report->getGroupBys(), $report->getDisplayAttributes())), ReportUtil::makeDataAndLabelsForSeriesOrRange($adapter->getAttributesForChartRange($report->getDisplayAttributes())));
             $chart->setAttributes($unserializedData['chart']);
             $report->setChart($chart);
         }
     }
     return $report;
 }
 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');
 }
 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);
 }
 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;
 }