public static function prepareTableSection(AbstractSQLDataSourceQueryHandler $datasourceHandler, DataControllerCallContext $callcontext, array &$requestedColumnNames = NULL)
 {
     $metamodel = data_controller_get_metamodel();
     $tableQuarters = new DatasetSection($metamodel->getDataset(DateDimensionDatasetNames::QUARTERS), self::$TABLE_ALIAS_SUFFIX__QUARTERS);
     self::selectColumn($tableQuarters, $requestedColumnNames, FALSE, 'quarter_def_id', FALSE);
     self::selectColumn($tableQuarters, $requestedColumnNames, FALSE, 'year_id', FALSE);
     // calculated field: first day of quarter
     $expressionFirstDayOfQuarter = $datasourceHandler->concatenateValues(array('(' . ColumnStatementCompositeEntityParser::assembleColumnName(self::$TABLE_ALIAS_SUFFIX__QUARTER_DEF . '.series') . ' - 1) * 3 + 1', "'/1/'", ColumnStatementCompositeEntityParser::assembleColumnName(DateDimensionYearDatasetAssembler::$TABLE_ALIAS_SUFFIX__YEARS . '.entry_year')));
     $expressionFirstDayOfQuarter = $datasourceHandler->formatDateValue($expressionFirstDayOfQuarter, 'm/d/Y');
     $columnFirstDayOfQuarter = self::selectColumn($tableQuarters, $requestedColumnNames, FALSE, $expressionFirstDayOfQuarter, TRUE, 'quarter_first_date');
     if (isset($columnFirstDayOfQuarter)) {
         // registering required column for this functionality to work. This will indirectly force joining with required tables
         self::registerDependentColumnName($requestedColumnNames, 'quarter_series');
         self::registerDependentColumnName($requestedColumnNames, 'entry_year');
     }
     $columnQuarterId = self::selectColumn($tableQuarters, $requestedColumnNames, isset($tableQuarters->columns), 'quarter_id', FALSE);
     if (isset($columnQuarterId)) {
         $columnQuarterId->key = TRUE;
     }
     return $tableQuarters;
 }
Beispiel #2
0
 public function assembleColumnName($tableAlias)
 {
     $callback = new ColumnStatementCompositeEntityParser__TableAliasUpdater(NULL, $tableAlias, TRUE);
     $parser = new ColumnStatementCompositeEntityParser();
     return $parser->parse($this->function, array($callback, 'updateTableAlias'));
 }
 protected static function prepareStatement_Nnn2Dec(AbstractSQLDataSourceQueryHandler $datasourceHandler, DataControllerCallContext $callcontext, $fromMonthNumber, array &$requestedColumnNames = NULL, $alwaysJoin = FALSE)
 {
     $statement = new Statement();
     $tableMonth = self::prepareTableSection($datasourceHandler, $callcontext, $requestedColumnNames);
     $isMonthRequired = isset($tableMonth->columns);
     $tableMonthDef = self::prepareDefTableSection($datasourceHandler, $callcontext, $requestedColumnNames);
     $isMonthDefRequired = isset($tableMonthDef->columns);
     $tableQuarters = DateDimensionQuarterDatasetAssembler::prepareTableSection($datasourceHandler, $callcontext, $requestedColumnNames);
     $isQuarterRequired = isset($tableQuarters->columns);
     $tableQuarterDef = DateDimensionQuarterDatasetAssembler::prepareDefTableSection($datasourceHandler, $callcontext, $requestedColumnNames);
     $isQuarterDefRequired = isset($tableQuarterDef->columns);
     // fiscal year
     $fiscalYearTableSections = DateDimensionYearDatasetAssembler::prepareTableSections4Statement($datasourceHandler, $callcontext, $requestedColumnNames, $isQuarterRequired);
     $isFiscalYearRequired = isset($fiscalYearTableSections);
     // calendar year
     $calendarYearTableSections = DateDimensionYearDatasetAssembler::prepareTableSections4Statement($datasourceHandler, $callcontext, $requestedColumnNames, $isQuarterRequired || $isFiscalYearRequired);
     $isCalendarYearRequired = isset($calendarYearTableSections);
     // we cannot link with quarters without querter def
     $isQuarterDefRequired = $isQuarterDefRequired || $isQuarterRequired;
     // we do not check for ($alwaysJoin || $isMonthRequired || $isMonthDefRequired) because if only those flags are true
     // all the work was done in prepareStatement_Jan2Nnn() and this function does not have to do anything in addition
     if ($isQuarterRequired || $isQuarterDefRequired || $isCalendarYearRequired || $isFiscalYearRequired) {
         // linking with quarter def is done through month def
         // Also we need month def for fiscal quarter
         // Also we need month def to select required months for BETWEEN
         $isMonthDefRequired = TRUE;
         if ($isCalendarYearRequired) {
             $tableMonth->event_updateTableAlias(DateDimensionYearDatasetAssembler::$TABLE_ALIAS_SUFFIX__YEARS, DateDimensionYearDatasetAssembler::$TABLE_ALIAS_PREFIX__CALENDAR . DateDimensionYearDatasetAssembler::$TABLE_ALIAS_SUFFIX__YEARS);
         }
         $statement->tables[] = $tableMonth;
         if ($isMonthDefRequired) {
             $tableMonthDef->conditions[] = new JoinConditionSection('month_def_id', new TableColumnConditionSectionValue(self::$TABLE_ALIAS_SUFFIX__MONTHS, 'month_def_id'));
             $statement->tables[] = $tableMonthDef;
         }
         if ($isQuarterDefRequired) {
             $tableQuarterDef->conditions[] = new JoinConditionSection('series', new ExactConditionSectionValue(' = ((' . ColumnStatementCompositeEntityParser::assembleColumnName(self::$TABLE_ALIAS_SUFFIX__MONTH_DEF . '.series') . " - {$fromMonthNumber}) DIV 3) + 1"));
             $statement->tables[] = $tableQuarterDef;
         }
         if ($isCalendarYearRequired) {
             $tableYears = $calendarYearTableSections[0];
             $tableYears->conditions[] = new JoinConditionSection('year_id', new TableColumnConditionSectionValue(self::$TABLE_ALIAS_SUFFIX__MONTHS, 'year_id'));
             foreach ($calendarYearTableSections as $table) {
                 $table->event_updateTableAlias($table->alias, DateDimensionYearDatasetAssembler::$TABLE_ALIAS_PREFIX__CALENDAR . $table->alias);
             }
             ArrayHelper::mergeArrays($statement->tables, $calendarYearTableSections);
         }
         if ($isFiscalYearRequired) {
             // adjusting alias for all year table sections
             foreach ($fiscalYearTableSections as $table) {
                 $table->event_updateTableAlias($table->alias, DateDimensionYearDatasetAssembler::$TABLE_ALIAS_PREFIX__FISCAL . $table->alias);
             }
             $tableYears = $fiscalYearTableSections[0];
             $tableYears->conditions[] = new JoinConditionSection('entry_year', new ExactConditionSectionValue(' = ' . ColumnStatementCompositeEntityParser::assembleColumnName(DateDimensionYearDatasetAssembler::$TABLE_ALIAS_PREFIX__CALENDAR . DateDimensionYearDatasetAssembler::$TABLE_ALIAS_SUFFIX__YEARS . '.entry_year') . ' + 1'));
             ArrayHelper::mergeArrays($statement->tables, $fiscalYearTableSections);
         }
         if ($isQuarterRequired) {
             $tableQuarters->conditions[] = new JoinConditionSection('quarter_def_id', new TableColumnConditionSectionValue(DateDimensionQuarterDatasetAssembler::$TABLE_ALIAS_SUFFIX__QUARTER_DEF, 'quarter_def_id'));
             $tableQuarters->conditions[] = new JoinConditionSection('year_id', new TableColumnConditionSectionValue(DateDimensionYearDatasetAssembler::$TABLE_ALIAS_SUFFIX__YEARS, 'year_id'));
             $tableQuarters->event_updateTableAlias(DateDimensionYearDatasetAssembler::$TABLE_ALIAS_SUFFIX__YEARS, DateDimensionYearDatasetAssembler::$TABLE_ALIAS_PREFIX__FISCAL . DateDimensionYearDatasetAssembler::$TABLE_ALIAS_SUFFIX__YEARS);
             $statement->tables[] = $tableQuarters;
         }
         $statement->conditions[] = new WhereConditionSection(self::$TABLE_ALIAS_SUFFIX__MONTH_DEF, 'series', new ExactConditionSectionValue(" BETWEEN {$fromMonthNumber} AND 12"));
     }
     return $statement;
 }
 public static function assembleColumnName($columnName)
 {
     $parser = new ColumnStatementCompositeEntityParser();
     return $parser->assemble($columnName);
 }
Beispiel #5
0
 public function assemble(Statement $statement, $useTableNameAsAlias)
 {
     $callback = new ColumnStatementCompositeEntityParser__ColumnNameAdjuster(TRUE);
     $parser = new ColumnStatementCompositeEntityParser();
     return $parser->parse($this->value, array($callback, 'adjustCallbackObject'));
 }