public function resolveJoinsAndBuildWhere($operatorType, $value, &$clausePosition, &$where, $onTableAliasName = null, $resolveAsSubquery = false) { assert('$operatorType == null'); assert('$value == null'); assert('is_array($where)'); assert('is_string($onTableAliasName) || $onTableAliasName == null'); $tableAliasName = $this->resolveJoins($onTableAliasName, ModelDataProviderUtil::resolveCanUseFromJoins($onTableAliasName)); $this->addReadOptimizationWhereClause($where, $clausePosition, $tableAliasName); }
/** * @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 ModelJoinBuilder $builder * @param $modelAttributeToDataProviderAdapter * @param null | string $onTableAliasName * @throws NotSupportedException if the display attribute is made via select like SUM(integer) but the * adapter being used is not a summation adapter */ protected function resolveDisplayAttributeForProcessingAllJoins(ModelJoinBuilder $builder, $modelAttributeToDataProviderAdapter, $onTableAliasName = null) { assert('$modelAttributeToDataProviderAdapter instanceof RedBeanModelAttributeToDataProviderAdapter'); assert('is_string($onTableAliasName) || $onTableAliasName == null'); $tableAliasName = $builder->resolveJoins($onTableAliasName, ModelDataProviderUtil::resolveCanUseFromJoins($onTableAliasName)); if ($this->isDisplayAttributeMadeViaSelect()) { if (!$this->modelToReportAdapter instanceof ModelRelationsAndAttributesToSummableReportAdapter) { throw new NotSupportedException(); } $this->modelToReportAdapter->resolveDisplayAttributeTypeAndAddSelectClause($this->selectQueryAdapter, $this->componentForm->getResolvedAttribute(), $tableAliasName, $this->resolveColumnName($modelAttributeToDataProviderAdapter), $this->componentForm->columnAliasName, $this->getAttributeClauseQueryStringExtraPart($tableAliasName)); } else { $tableAliasName = $this->resolvedTableAliasName($modelAttributeToDataProviderAdapter, $builder); $this->selectQueryAdapter->resolveIdClause($this->resolvedModelClassName($modelAttributeToDataProviderAdapter), $tableAliasName); $this->componentForm->setModelAliasUsingTableAliasName($tableAliasName); } }
/** * @param RedBeanModelAttributeToDataProviderAdapter $modelAttributeToDataProviderAdapter * @param null | string $onTableAliasName * @return string */ protected function resolveSortAttributeContent(RedBeanModelAttributeToDataProviderAdapter $modelAttributeToDataProviderAdapter, $onTableAliasName = null) { assert('is_string($onTableAliasName) || $onTableAliasName == null'); $builder = new ModelJoinBuilder($modelAttributeToDataProviderAdapter, $this->joinTablesAdapter); $tableAliasName = $builder->resolveJoins($onTableAliasName, ModelDataProviderUtil::resolveCanUseFromJoins($onTableAliasName)); $resolvedSortColumnName = self::resolveSortColumnName($modelAttributeToDataProviderAdapter); $queryStringExtraPart = $this->getAttributeClauseQueryStringExtraPart($tableAliasName); return $this->resolveOrderByString($tableAliasName, $resolvedSortColumnName, $queryStringExtraPart); }
protected function resolveRelationAttributeTableAliasNameForResolveSubquery($onTableAliasName, $resolveAsSubquery = false) { assert('is_string($onTableAliasName) || $onTableAliasName == null'); assert('is_bool($resolveAsSubquery)'); if ($resolveAsSubquery) { return $this->resolveRelationAttributeTableAliasNameForResolveSubqueryAsTrue($onTableAliasName); } else { return $this->resolveOnlyAttributeJoins($onTableAliasName, ModelDataProviderUtil::resolveCanUseFromJoins($onTableAliasName)); } }