当前位置: 首页>>代码示例>>PHP>>正文


PHP Statement::prepareSections方法代码示例

本文整理汇总了PHP中Statement::prepareSections方法的典型用法代码示例。如果您正苦于以下问题:PHP Statement::prepareSections方法的具体用法?PHP Statement::prepareSections怎么用?PHP Statement::prepareSections使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Statement的用法示例。


在下文中一共展示了Statement::prepareSections方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: queryCube

 public function queryCube(DataControllerCallContext $callcontext, CubeQueryRequest $request, ResultFormatter $resultFormatter)
 {
     $cubeName = $request->getCubeName();
     LogHelper::log_notice(t('Querying SQL-based cube: @cubeName', array('@cubeName' => $cubeName)));
     $environment_metamodel = data_controller_get_environment_metamodel();
     $metamodel = data_controller_get_metamodel();
     $callcontext->columnMapping = NULL;
     $cube = $metamodel->getCube($cubeName);
     LogHelper::log_debug($cube);
     $cubeDatasetName = $cube->sourceDatasetName;
     $cubeDataset = $metamodel->getDataset($cubeDatasetName);
     $datasource = $environment_metamodel->getDataSource($cubeDataset->datasourceName);
     // aliases for tables
     $TABLE_ALIAS__JOIN = 'j';
     $tableJoinIndex = 0;
     // preparing statement which aggregates data
     $aggrStatement = $this->prepareCubeQueryStatement($callcontext, $request);
     list($isSubqueryRequired, $assembledAggregationSections) = $aggrStatement->prepareSections(NULL);
     // assembling porting of SQL which is responsible for aggregation
     if (isset($request->referencedRequests)) {
         $joinStatement = $aggrStatement;
         // changing alias of first table. This new alias is expected the following code to join with lookup tables
         $joinStatement->updateTableAlias($joinStatement->tables[0]->alias, $TABLE_ALIAS__JOIN);
     } else {
         $joinStatement = new Statement();
         $aggregationTableSection = new SubquerySection(Statement::assemble($isSubqueryRequired, NULL, $assembledAggregationSections, Statement::$INDENT_SUBQUERY, FALSE), $TABLE_ALIAS__JOIN);
         $joinStatement->tables[] = $aggregationTableSection;
     }
     // adding support for dimension level properties
     if (isset($request->dimensions)) {
         foreach ($request->dimensions as $requestDimension) {
             $dimensionName = $requestDimension->dimensionName;
             $dimension = $cube->getDimension($dimensionName);
             $levelName = $requestDimension->levelName;
             // we do not need to map the column. It was done in prepareCubeQueryStatement()
             $levelDatabaseColumnName = ParameterHelper::assembleDatabaseColumnName($this->getMaximumEntityNameLength(), $dimensionName, $levelName);
             // adding support for level root column
             $levelRootColumn = new ColumnSection($levelDatabaseColumnName);
             $levelRootColumn->requestColumnIndex = $requestDimension->requestColumnIndex;
             $levelRootColumn->visible = isset($requestDimension->requestColumnIndex);
             $aggregationTableSection->columns[] = $levelRootColumn;
             if (!isset($requestDimension->properties)) {
                 continue;
             }
             $tableJoinIndex++;
             $levelTableAlias = $TABLE_ALIAS__JOIN . $tableJoinIndex;
             $level = $dimension->getLevel($levelName);
             $levelDataset = $metamodel->getDataset($level->datasetName);
             // preparing list of columns which are accessed by this dataset
             $usedColumnNames = NULL;
             $levelColumnAliasMapping = NULL;
             foreach ($requestDimension->properties as $property) {
                 $propertyName = $property->name;
                 $responseColumnName = ParameterHelper::assembleParameterName($dimensionName, $levelName, $propertyName);
                 $databaseColumnName = ParameterHelper::assembleDatabaseColumnName($this->getMaximumEntityNameLength(), $dimensionName, $levelName, $propertyName);
                 $callcontext->columnMapping[$databaseColumnName] = $responseColumnName;
                 ArrayHelper::addUniqueValue($usedColumnNames, $propertyName);
                 $levelColumnAliasMapping[$propertyName] = $databaseColumnName;
             }
             $isLevelKeyColumnAdded = ArrayHelper::addUniqueValue($usedColumnNames, $level->key);
             $levelStatement = $this->prepareDatasetSourceStatement($callcontext, $levelDataset, $usedColumnNames);
             // updating level statement table aliases
             $levelStatement->addTableAliasPrefix($levelTableAlias);
             foreach ($levelStatement->tables as $table) {
                 if (!isset($table->columns)) {
                     $table->columns = array();
                     // We do not need any columns
                 }
             }
             // updating level statement column aliases
             foreach ($requestDimension->properties as $property) {
                 $oldColumnAlias = $property->name;
                 $newColumnAlias = $levelColumnAliasMapping[$oldColumnAlias];
                 $levelTableSection = $levelStatement->getColumnTable($oldColumnAlias, TRUE);
                 $levelColumnSection = $levelTableSection->findColumnByAlias($oldColumnAlias);
                 if (isset($levelColumnSection)) {
                     $levelColumnSection->alias = $newColumnAlias;
                 } else {
                     $levelColumnSection = new ColumnSection($oldColumnAlias, $newColumnAlias);
                     $levelTableSection->columns[] = $levelColumnSection;
                 }
                 $levelColumnSection->requestColumnIndex = $property->requestColumnIndex;
             }
             // adding condition to join with 'main' statement
             $levelKeyTableSection = $levelStatement->getColumnTable($level->key);
             $levelKeyTableSection->conditions[] = new JoinConditionSection($level->key, new TableColumnConditionSectionValue($TABLE_ALIAS__JOIN, $levelDatabaseColumnName));
             // merging with 'main' statement
             $joinStatement->merge($levelStatement);
             // we do not need to return level key column
             if ($isLevelKeyColumnAdded && isset($levelKeyTableSection)) {
                 // FIXME this code does not work in the following case:
                 //   - our lookup dataset is fact dataset
                 //   - we need to work with project_id column from that dataset
                 //   - the column is present in *_facts and contains numeric value
                 //   - the column is present in *_c_project_id table and contains numeric value
                 //   - column 'value' in *_c_project_id table assigned an alias project_id
                 //   - more about implementation is in ReferenceDimensionDatasetAssembler
                 //   - the code is partially fixed by using $visibleOnly parameter
                 $tableSection = $levelStatement->getColumnTable($level->key, TRUE);
                 $keyColumn = $tableSection->findColumnByAlias($level->key);
//.........这里部分代码省略.........
开发者ID:ecs-hk,项目名称:Checkbook,代码行数:101,代码来源:AbstractSQLDataSourceQueryHandler.php

示例2: queryCube

    public function queryCube(DataControllerCallContext $callcontext, CubeQueryRequest $request) {
        $cubeName = $request->getCubeName();
        LogHelper::log_info(t('Querying SQL-based cube: @cubeName', array('@cubeName' => $cubeName)));

        $environment_metamodel = data_controller_get_environment_metamodel();
        $metamodel = data_controller_get_metamodel();

        $this->getExtension('adjustRequest')->adjustCubeQueryRequest($this, $request);

        $callcontext->columnMapping = NULL;

        $cube = $metamodel->getCube($cubeName);

        $factsDataset = $metamodel->getDataset($cube->factsDatasetName);
        $datasource = $environment_metamodel->getDataSource($factsDataset->datasourceName);

        $engine = QueryEngineFactory::getInstance()->getHandler();
        $generationContext = $engine->prepareStatementGenerationContext($request, $cube);

        // aliases for tables
        $TABLE_ALIAS__JOIN = 'j';
        $tableJoinIndex = 0;

        // preparing statement which aggregates data
        $aggrStatement = $this->prepareCubeQueryStatement($callcontext, $request);
        list($isSubqueryRequired, $assembledAggregationSections) = $aggrStatement->prepareSections(NULL);

        // assembling portion of SQL which is responsible for aggregation
        if (isset($request->referencedRequests)) {
            $joinStatement = $aggrStatement;
            // changing alias of first table. This new alias is expected the following code to join with lookup tables
            $joinStatement->updateTableAlias($joinStatement->tables[0]->alias, $TABLE_ALIAS__JOIN);
        }
        else {
            $joinStatement = new Statement();
            $aggregationTableSection = new SubquerySection(
                Statement::assemble($isSubqueryRequired, NULL, $assembledAggregationSections, SelectStatementPrint::INDENT__SUBQUERY, FALSE),
                $TABLE_ALIAS__JOIN);
            $joinStatement->tables[] = $aggregationTableSection;
        }

        // adding support for dimension columns
        if (isset($request->dimensions)) {
            foreach ($request->dimensions as $requestDimension) {
                $dimensionName = $requestDimension->name;
                $dimension = $cube->findDimension($dimensionName);

                // we do not need to map the column. It was done in prepareCubeQueryStatement()
                $dimensionDatabaseColumnName = DataSourceColumnNameHelper::generateFromParameterElements($this->getMaximumEntityNameLength(), $dimensionName);

                // adding support for dimension column
                $dimensionColumn = new ColumnSection($dimensionDatabaseColumnName);
                $dimensionColumn->requestColumnIndex = $requestDimension->requestColumnIndex;
                $dimensionColumn->visible = isset($requestDimension->requestColumnIndex);

                $aggregationTableSection->columns[] = $dimensionColumn;

                if (!isset($requestDimension->columns)) {
                    continue;
                }

                // preparing list of columns which are accessed by this dataset
                $usedColumnNames = NULL;
                $dimensionColumnAliasMapping = NULL;
                foreach ($requestDimension->columns as $requestColumn) {
                    $responseColumnName = ParameterNameHelper::assemble($dimensionName, $requestColumn->name);
                    $databaseColumnName = DataSourceColumnNameHelper::generateFromParameterElements(
                        $this->getMaximumEntityNameLength(), $dimensionName, $requestColumn->name);
                    $callcontext->columnMapping[$databaseColumnName] = $responseColumnName;

                    ArrayHelper::addUniqueValue($usedColumnNames, $requestColumn->name);
                    $dimensionColumnAliasMapping[$requestColumn->name] = $databaseColumnName;
                }

                $isJoinWithDimensionDatasetRequired = $generationContext->dimensionJoinPhase[__DefaultQueryEngine_StatementGenerationContext::DIMENSION_JOIN_PHASE__GROUPING_WITH_LOOKUP_AFTER][$dimensionName];
                if ($isJoinWithDimensionDatasetRequired) {
                    $tableJoinIndex++;
                    $dimensionTableAlias = $TABLE_ALIAS__JOIN . $tableJoinIndex;

                    $dimensionDataset = $metamodel->getDataset($dimension->datasetName);

                    $isDimensionKeyColumnAdded = ArrayHelper::addUniqueValue($usedColumnNames, $dimension->key);

                    $dimensionStatement = $this->prepareDatasetSourceStatement($callcontext, $request, $dimensionDataset, $usedColumnNames);

                    // updating dimension statement table aliases
                    $dimensionStatement->addTableAliasPrefix($dimensionTableAlias);

                    foreach ($dimensionStatement->tables as $table) {
                        if (!isset($table->columns)) {
                            $table->columns = array(); // We do not need any columns
                        }
                    }

                    // updating dimension statement column aliases
                    foreach ($requestDimension->columns as $requestColumn) {
                        $oldColumnAlias = $requestColumn->name;
                        $newColumnAlias = $dimensionColumnAliasMapping[$oldColumnAlias];

                        $dimensionTableSection = $dimensionStatement->getColumnTable($oldColumnAlias, TRUE);
//.........这里部分代码省略.........
开发者ID:reisystems-india,项目名称:GovDashboard-Community,代码行数:101,代码来源:AbstractSQLDataSourceQueryHandler.php


注:本文中的Statement::prepareSections方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。