public function testAddQuarterClauseWithTimeZoneAdjustment() { $quote = DatabaseCompatibilityUtil::getQuote(); $adapter = new RedBeanModelSelectQueryAdapter(); $this->assertEquals(0, $adapter->getClausesCount()); $adapter->addQuarterClause('table', 'abc', 'c', true); $this->assertEquals(1, $adapter->getClausesCount()); $compareString = "select quarter({$quote}table{$quote}.{$quote}abc{$quote} - INTERVAL " . abs(self::$chicagoOffsetInSeconds) . " SECOND) c "; $this->assertEquals($compareString, $adapter->getSelect()); }
/** * @param RedBeanModelSelectQueryAdapter $selectQueryAdapter * @param string $attribute * @param string $tableName * @param string $columnName * @param string $columnAliasName * @param null|string $queryStringExtraPart */ public function resolveDisplayAttributeTypeAndAddSelectClause(RedBeanModelSelectQueryAdapter $selectQueryAdapter, $attribute, $tableName, $columnName, $columnAliasName, $queryStringExtraPart = null) { assert('is_string($attribute)'); assert('is_string($columnAliasName)'); assert('is_string($queryStringExtraPart) || $queryStringExtraPart == null'); $type = $this->getDisplayAttributeForMakingViaSelectType($attribute); if ($type == ModelRelationsAndAttributesToSummableReportAdapter::DISPLAY_CALCULATION_COUNT) { $selectQueryAdapter->addCountClause($tableName, $columnName, $columnAliasName); } elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::DISPLAY_CALCULATION_SUMMMATION) { $selectQueryAdapter->addSummationClause($tableName, $columnName, $columnAliasName, $queryStringExtraPart); } elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::DISPLAY_CALCULATION_AVERAGE) { $selectQueryAdapter->addAverageClause($tableName, $columnName, $columnAliasName, $queryStringExtraPart); } elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::DISPLAY_CALCULATION_MINIMUM) { $selectQueryAdapter->addMinimumClause($tableName, $columnName, $columnAliasName, $queryStringExtraPart); } elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::DISPLAY_CALCULATION_MAXIMUM) { $selectQueryAdapter->addMaximumClause($tableName, $columnName, $columnAliasName, $queryStringExtraPart); } elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::GROUP_BY_CALCULATION_DAY) { $selectQueryAdapter->addDayClause($tableName, $columnName, $columnAliasName, $this->shouldDoTimeZoneAdjustmentOnModifierClause($attribute)); } elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::GROUP_BY_CALCULATION_WEEK) { $selectQueryAdapter->addWeekClause($tableName, $columnName, $columnAliasName, $this->shouldDoTimeZoneAdjustmentOnModifierClause($attribute)); } elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::GROUP_BY_CALCULATION_MONTH) { $selectQueryAdapter->addMonthClause($tableName, $columnName, $columnAliasName, $this->shouldDoTimeZoneAdjustmentOnModifierClause($attribute)); } elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::GROUP_BY_CALCULATION_QUARTER) { $selectQueryAdapter->addQuarterClause($tableName, $columnName, $columnAliasName, $this->shouldDoTimeZoneAdjustmentOnModifierClause($attribute)); } elseif ($type == ModelRelationsAndAttributesToSummableReportAdapter::GROUP_BY_CALCULATION_YEAR) { $selectQueryAdapter->addYearClause($tableName, $columnName, $columnAliasName, $this->shouldDoTimeZoneAdjustmentOnModifierClause($attribute)); } else { $selectQueryAdapter->addClause($tableName, $columnName, $columnAliasName); } }