/**
  * @see resolveAttributeIndexesByComponents
  * @param ComponentForReportForm $componentForm
  * @return array
  */
 protected static function resolveAttributeIndexesByComponent(ComponentForReportForm $componentForm)
 {
     $attributeIndexes = array();
     $modelClassName = $componentForm->getModelClassName();
     $moduleClassName = $componentForm->getModuleClassName();
     if (!$componentForm->hasRelatedData()) {
         static::resolveAttributeIndexes($modelClassName, $attributeIndexes);
     } else {
         $attributeIndexPrefix = null;
         foreach ($componentForm->attributeAndRelationData as $relationOrAttribute) {
             static::resolveAttributeIndexes($modelClassName, $attributeIndexes, $attributeIndexPrefix);
             $modelToReportAdapter = ModelRelationsAndAttributesToReportAdapter::make($moduleClassName, $modelClassName, $componentForm->getReportType());
             if ($modelToReportAdapter->isReportedOnAsARelation($relationOrAttribute)) {
                 $modelClassName = $modelToReportAdapter->getRelationModelClassName($relationOrAttribute);
                 $moduleClassName = $modelToReportAdapter->getRelationModuleClassName($relationOrAttribute);
                 $attributeIndexPrefix = $attributeIndexPrefix . $relationOrAttribute . FormModelUtil::RELATION_DELIMITER;
             }
         }
     }
     return $attributeIndexes;
 }
 /**
  * @return ModelRelationsAndAttributesToReportAdapter
  */
 protected function makeModelRelationsAndAttributesToReportAdapter()
 {
     return ModelRelationsAndAttributesToReportAdapter::make($this->filter->getResolvedAttributeModuleClassName(), $this->filter->getResolvedAttributeModelClassName(), $this->filter->getReportType());
 }
Esempio n. 3
0
 /**
  * @return string
  * @throws NotSupportedException
  */
 protected function resolveComponentAttributeStringContentForNestedAttribute()
 {
     $attributeAndRelationData = $this->componentForm->getAttributeAndRelationData();
     $count = 0;
     $moduleClassName = $this->componentForm->getModuleClassName();
     $modelClassName = $this->componentForm->getModelClassName();
     $onTableAliasName = null;
     $startingModelClassName = null;
     foreach ($attributeAndRelationData as $key => $relationOrAttribute) {
         $modelToReportAdapter = ModelRelationsAndAttributesToReportAdapter::make($moduleClassName, $modelClassName, $this->componentForm->getReportType());
         $modelAttributeToDataProviderAdapter = $this->makeModelAttributeToDataProviderAdapter($modelToReportAdapter, $relationOrAttribute);
         if ($this->shouldPrematurelyStopBuildingJoinsForAttribute($modelToReportAdapter, $modelAttributeToDataProviderAdapter)) {
             $attribute = 'id';
             $modelAttributeToDataProviderAdapter = $this->makeModelAttributeToDataProviderAdapter($modelToReportAdapter, $attribute);
             break;
         } elseif ($modelToReportAdapter->isReportedOnAsARelation($relationOrAttribute)) {
             $modelClassName = $modelToReportAdapter->getRelationModelClassName($relationOrAttribute);
             $moduleClassName = $modelToReportAdapter->getRelationModuleClassName($relationOrAttribute);
             if ($modelToReportAdapter->isInferredRelation($relationOrAttribute) || $modelToReportAdapter->isDerivedRelationsViaCastedUpModelRelation($relationOrAttribute)) {
                 static::resolveCastingHintForAttribute($modelToReportAdapter, $modelAttributeToDataProviderAdapter, $modelClassName, $modelToReportAdapter->resolveRealAttributeName($attributeAndRelationData[$key + 1]));
             }
             $modelAttributeToDataProviderAdapter->setCastingHintStartingModelClassName($startingModelClassName);
             $builder = new ModelJoinBuilder($modelAttributeToDataProviderAdapter, $this->joinTablesAdapter);
             $onTableAliasName = $builder->resolveJoins($onTableAliasName, ModelDataProviderUtil::resolveCanUseFromJoins($onTableAliasName));
             $startingModelClassName = $modelAttributeToDataProviderAdapter->getCastingHintModelClassNameForAttribute();
         } else {
             if ($count + 1 != count($attributeAndRelationData)) {
                 throw new NotSupportedException('The final element in array must be an attribute, not a relation');
             }
         }
         $count++;
     }
     $modelAttributeToDataProviderAdapter->setCastingHintStartingModelClassName($startingModelClassName);
     return $this->resolveFinalContent($modelAttributeToDataProviderAdapter, $onTableAliasName);
 }
 /**
  * @param array $attributeAndRelationData
  * @param $modelClassName
  * @return string $lastModelClassName
  */
 protected function resolvePenultimateModelClassNameFromData(array $attributeAndRelationData, $modelClassName)
 {
     assert(count($attributeAndRelationData) > 0);
     // Not Coding Standard
     array_pop($attributeAndRelationData);
     foreach ($attributeAndRelationData as $relationOrAttribute) {
         $lastModelClassName = $modelClassName;
         $modelToReportAdapter = ModelRelationsAndAttributesToReportAdapter::make($modelClassName::getModuleClassName(), $modelClassName, $this->reportType);
         if ($modelToReportAdapter->isReportedOnAsARelation($relationOrAttribute)) {
             $modelClassName = $modelToReportAdapter->getRelationModelClassName($relationOrAttribute);
         }
     }
     return $lastModelClassName;
 }
 public function actionGetAvailableSeriesAndRangesForChart($type, $id = null, $isBeingCopied = false)
 {
     $postData = PostUtil::getData();
     $savedReport = null;
     $report = null;
     $this->resolveSavedReportAndReportByPostData($postData, $savedReport, $report, $type, $id, (bool) $isBeingCopied);
     $moduleClassName = $report->getModuleClassName();
     $modelClassName = $moduleClassName::getPrimaryModelName();
     $modelToReportAdapter = ModelRelationsAndAttributesToReportAdapter::make($moduleClassName, $modelClassName, $report->getType());
     if (!$modelToReportAdapter instanceof ModelRelationsAndAttributesToSummationReportAdapter) {
         throw new NotSupportedException();
     }
     $seriesAttributesData = $modelToReportAdapter->getAttributesForChartSeries($report->getGroupBys(), $report->getDisplayAttributes());
     $rangeAttributesData = $modelToReportAdapter->getAttributesForChartRange($report->getDisplayAttributes());
     $dataAndLabels = array();
     $dataAndLabels['firstSeriesDataAndLabels'] = array('' => Zurmo::t('Core', '(None)'));
     $dataAndLabels['firstSeriesDataAndLabels'] = array_merge($dataAndLabels['firstSeriesDataAndLabels'], ReportUtil::makeDataAndLabelsForSeriesOrRange($seriesAttributesData));
     $dataAndLabels['firstRangeDataAndLabels'] = array('' => Zurmo::t('Core', '(None)'));
     $dataAndLabels['firstRangeDataAndLabels'] = array_merge($dataAndLabels['firstRangeDataAndLabels'], ReportUtil::makeDataAndLabelsForSeriesOrRange($rangeAttributesData));
     $dataAndLabels['secondSeriesDataAndLabels'] = array('' => Zurmo::t('Core', '(None)'));
     $dataAndLabels['secondSeriesDataAndLabels'] = array_merge($dataAndLabels['secondSeriesDataAndLabels'], ReportUtil::makeDataAndLabelsForSeriesOrRange($seriesAttributesData));
     $dataAndLabels['secondRangeDataAndLabels'] = array('' => Zurmo::t('Core', '(None)'));
     $dataAndLabels['secondRangeDataAndLabels'] = array_merge($dataAndLabels['secondRangeDataAndLabels'], ReportUtil::makeDataAndLabelsForSeriesOrRange($rangeAttributesData));
     echo CJSON::encode($dataAndLabels);
 }
 /**
  * @param ComponentForReportForm $componentForm
  * @return ModelRelationsAndAttributesToReportAdapter
  */
 protected static function makeModelToReportAdapterByComponentForm(ComponentForReportForm $componentForm)
 {
     return ModelRelationsAndAttributesToReportAdapter::make($componentForm->getResolvedAttributeModuleClassName(), $componentForm->getResolvedAttributeModelClassName(), $componentForm->getReportType());
 }
 /**
  * @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());
 }
 /**
  * Resolves for a given component whether the user has necessary rights to access the component information.
  * An example is if a component is account's opportunities and the current user cannot access the opportunities
  * module.
  * @param ComponentForReportForm $componentForm
  * @return bool
  */
 protected static function canCurrentUserAccessComponent(ComponentForReportForm $componentForm)
 {
     $modelClassName = $componentForm->getModelClassName();
     $moduleClassName = $componentForm->getModuleClassName();
     if (!$componentForm->hasRelatedData()) {
         return self::canCurrentUserCanAccessModule($moduleClassName);
     } else {
         foreach ($componentForm->attributeAndRelationData as $relationOrAttribute) {
             if (!self::canCurrentUserCanAccessModule($moduleClassName)) {
                 return false;
             }
             $modelToReportAdapter = ModelRelationsAndAttributesToReportAdapter::make($moduleClassName, $modelClassName, $componentForm->getReportType());
             if ($modelToReportAdapter->isReportedOnAsARelation($relationOrAttribute)) {
                 $modelClassName = $modelToReportAdapter->getRelationModelClassName($relationOrAttribute);
                 $moduleClassName = $modelToReportAdapter->getRelationModuleClassName($relationOrAttribute);
             }
         }
         return true;
     }
 }