/** * Build the criteria for a single field * * @param Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig $fieldIdentifier * @return Tx_PtExtlist_Domain_QueryObject_SimpleCriteria */ protected function buildFilterCriteria(Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig $fieldIdentifier) { $fieldName = Tx_PtExtlist_Utility_DbUtils::getSelectPartByFieldConfig($fieldIdentifier); $singleCriteria = NULL; $selectedPid = $this->yagContext->getSelectedPid(); $singleCriteria = Tx_PtExtlist_Domain_QueryObject_Criteria::equals($fieldName, $selectedPid); return $singleCriteria; }
/** * Creates filter query from filter value and settings * * @param Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig $fieldIdentifier * @return Tx_PtExtlist_Domain_QueryObject_Criteria Criteria for current filter value (null, if empty) */ protected function buildFilterCriteria(Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig $fieldIdentifier) { $timestampBoundaries = $this->getCalculatedTimestampBoundaries(); $fieldName = Tx_PtExtlist_Utility_DbUtils::getSelectPartByFieldConfig($fieldIdentifier); $criteria1 = Tx_PtExtlist_Domain_QueryObject_Criteria::greaterThanEquals($fieldName, $timestampBoundaries['filterValueFromTimestamp']); $criteria2 = Tx_PtExtlist_Domain_QueryObject_Criteria::lessThanEquals($fieldName, $timestampBoundaries['filterValueToTimestamp']); $criteria = Tx_PtExtlist_Domain_QueryObject_Criteria::andOp($criteria1, $criteria2); return $criteria; }
/** * @test */ public function getAliasedSelectPartByFieldConfigCollection() { $fieldConfig1 = new Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig($this->configurationBuilderMock, 'test1', array('field' => 'field', 'table' => 'table')); $fieldConfig2 = new Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig($this->configurationBuilderMock, 'test2', array('field' => 'field', 'table' => 'table', 'special' => 'special')); $fieldConfigCollection = new Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfigCollection(); $fieldConfigCollection->addFieldConfig($fieldConfig1); $fieldConfigCollection->addFieldConfig($fieldConfig2); $return = Tx_PtExtlist_Utility_DbUtils::getSelectPartByFieldConfigCollection($fieldConfigCollection); $this->assertEquals('table.field, (special)', $return); }
/** * (non-PHPdoc) * @see Classes/Domain/Model/Filter/Tx_PtExtlist_Domain_Model_Filter_AbstractFilter::buildFilterCriteria() */ protected function buildFilterCriteria(Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig $fieldIdentifier) { $criteria = NULL; if ($this->isActive) { $fieldName = Tx_PtExtlist_Utility_DbUtils::getSelectPartByFieldConfig($fieldIdentifier); $filterValue = intval($this->filterValue); $criteria = Tx_PtExtlist_Domain_QueryObject_Criteria::lessThanEquals($fieldName, $filterValue); } return $criteria; }
/** * @param Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig $fieldStart * @param Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig $fieldEnd * @return Tx_PtExtlist_Domain_QueryObject_Criteria * * TODO: Optimize this for a 1-field query */ protected function buildTimeSpanFilterCriteria(Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig $fieldStart, Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig $fieldEnd) { $fieldStartName = Tx_PtExtlist_Utility_DbUtils::getSelectPartByFieldConfig($fieldStart); $fieldEndName = Tx_PtExtlist_Utility_DbUtils::getSelectPartByFieldConfig($fieldEnd); $startValueCriteria = Tx_PtExtlist_Domain_QueryObject_Criteria::andOp(Tx_PtExtlist_Domain_QueryObject_Criteria::lessThanEquals($fieldStartName, $this->getFilterValueStartInDBFormat()), Tx_PtExtlist_Domain_QueryObject_Criteria::greaterThanEquals($fieldEndName, $this->getFilterValueStartInDBFormat())); $endValueCriteria = Tx_PtExtlist_Domain_QueryObject_Criteria::andOp(Tx_PtExtlist_Domain_QueryObject_Criteria::lessThanEquals($fieldStartName, $this->getFilterValueEndInDBFormat()), Tx_PtExtlist_Domain_QueryObject_Criteria::greaterThanEquals($fieldEndName, $this->getFilterValueEndInDBFormat())); $betweenValuesCriteria = Tx_PtExtlist_Domain_QueryObject_Criteria::andOp(Tx_PtExtlist_Domain_QueryObject_Criteria::greaterThanEquals($fieldStartName, $this->getFilterValueStartInDBFormat()), Tx_PtExtlist_Domain_QueryObject_Criteria::lessThanEquals($fieldEndName, $this->getFilterValueEndInDBFormat())); $criteria = Tx_PtExtlist_Domain_QueryObject_Criteria::orOp(Tx_PtExtlist_Domain_QueryObject_Criteria::orOp($startValueCriteria, $endValueCriteria), $betweenValuesCriteria); return $criteria; }
/** * @param Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig $fieldIdentifier * @return null|Tx_PtExtlist_Domain_QueryObject_SimpleCriteria */ protected function buildFilterCriteria(Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig $fieldIdentifier) { if ($this->filterValue == '') { return null; } $fieldName = Tx_PtExtlist_Utility_DbUtils::getSelectPartByFieldConfig($fieldIdentifier); if ($this->orToken || $this->andToken) { $filterValueArray = $this->prepareFilterValue($this->filterValue); $criteria = $this->buildOrCriteria($fieldName, $filterValueArray); } else { $criteria = $this->buildFilterCriteriaForSingleValue($fieldName, $this->filterValue); } return $criteria; }
/** * Build the group data query to retrieve the group data * * @param array Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig $fields * @return \Tx_PtExtlist_Domain_QueryObject_Query */ protected function buildGroupDataQuery($fields) { $groupDataQuery = new Tx_PtExtlist_Domain_QueryObject_Query(); foreach ($fields as $selectField) { $groupDataQuery->addField(Tx_PtExtlist_Utility_DbUtils::getAliasedSelectPartByFieldConfig($selectField)); } if ($this->additionalTables != '') { $groupDataQuery->addFrom($this->additionalTables); } $groupDataQuery->addSorting('elementCount', Tx_PtExtlist_Domain_QueryObject_Query::SORTINGSTATE_DESC); if ($this->elementCountField !== NULL) { $groupDataQuery->addField(sprintf('%s as elementCount', $this->elementCountField->getTableFieldCombined())); } else { // TODO only works with SQL! $groupDataQuery->addField(sprintf('count("%s") as elementCount', $this->filterField->getTableFieldCombined())); } $groupDataQuery->addGroupBy($this->filterConfig->getFieldIdentifier()->getItemByIndex(0)->getIdentifier()); return $groupDataQuery; }
/** * translate fullText criteria * * @param Tx_PtExtlist_Domain_QueryObject_Criteria $criteria * @return string */ public static function translateCriteria(Tx_PtExtlist_Domain_QueryObject_Criteria $criteria) { $connection = $GLOBALS['TYPO3_DB']; /** @var TYPO3\CMS\Core\Database\DatabaseConnection $connection */ $searchString = $criteria->getSearchString(); if ($criteria->getSearchParameter('booleanMode')) { $booleanMode = $criteria->getSearchParameter('booleanMode') ? ' IN BOOLEAN MODE' : ''; if ($criteria->getSearchParameter('booleanModeWrapWithStars')) { if (substr($searchString, 0, 1) != '*') { $searchString = '*' . $searchString; } if (substr($searchString, -1, 1) != '*') { $searchString .= '*'; } } } $searchString = $connection->fullQuoteStr($searchString, ''); return sprintf('MATCH (%s) AGAINST (%s%s)', Tx_PtExtlist_Utility_DbUtils::getSelectPartByFieldConfigCollection($criteria->getFields()), $searchString, $booleanMode); }
/** * @param Tx_PtExtlist_Domain_Model_Filter_FilterInterface $filter * @param string $filterField * @param string $notActiveQuery * * @return string */ public function render(Tx_PtExtlist_Domain_Model_Filter_FilterInterface $filter, $filterField = '', $notActiveQuery = '1=1') { if (!$filter->isActive()) { return $notActiveQuery; } if ($filter instanceof Tx_PtExtlist_Domain_Model_Filter_DateRangeFilter) { $calculatedTimestampBoundaries = $filter->getCalculatedTimestampBoundaries(); if (is_array($filterField)) { return sprintf('%s >= %s AND %s <= %s', $filterField[0], $calculatedTimestampBoundaries['filterValueFromTimestamp'], $filterField[1], $calculatedTimestampBoundaries['filterValueToTimestamp']); } else { return sprintf('%s >= %s AND %1$s <= %s', $filterField, $calculatedTimestampBoundaries['filterValueFromTimestamp'], $calculatedTimestampBoundaries['filterValueToTimestamp']); } } $filterValue = $filter->getValue(); $filterField = $filterField ? $filterField : Tx_PtExtlist_Utility_DbUtils::getSelectPartByFieldConfigCollection($filter->getFilterConfig()->getFieldIdentifier()); if (is_array($filterValue)) { return sprintf('%s in (%s)', $filterField, implode(', ', $filterValue)); } else { return sprintf('%s = %s', $filterField, $filterValue); } }
/** * Build the criteria for a single field * * @param Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig $fieldIdentifier * @return Tx_PtExtlist_Domain_QueryObject_SimpleCriteria */ protected function buildFilterCriteria(Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig $fieldIdentifier) { $fieldName = Tx_PtExtlist_Utility_DbUtils::getSelectPartByFieldConfig($fieldIdentifier); $singleCriteria = NULL; $singleCriteria = Tx_PtExtlist_Domain_QueryObject_Criteria::in($fieldName, $this->getFilterNodeUIds()); return $singleCriteria; }
/** * Build the filterCriteria for filter * * @return Tx_PtExtlist_Domain_QueryObject_Criteria */ protected function buildFilterCriteriaForAllFields() { $albumField = $this->fieldIdentifierCollection->getFieldConfigByIdentifier('album'); $fieldName = Tx_PtExtlist_Utility_DbUtils::getSelectPartByFieldConfig($albumField); $criteria = Tx_PtExtlist_Domain_QueryObject_Criteria::equals($fieldName, $this->albumUid); return $criteria; }
/** * Builds select part from all parts of plugin * * @return string SELECT part of query without 'SELECT' */ public function buildSelectPart() { $selectParts = array(); foreach ($this->fieldConfigurationCollection as $fieldConfiguration) { /* @var $fieldConfiguration Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig */ if ($fieldConfiguration->getExpandGroupRows() && $this->baseGroupByClause) { $selectParts[] = 'group_concat(' . Tx_PtExtlist_Utility_DbUtils::getSelectPartByFieldConfig($fieldConfiguration) . ' SEPARATOR "' . $fieldConfiguration->getExpandGroupRowsSeparator() . '") AS ' . $fieldConfiguration->getIdentifier(); } else { $selectParts[] = Tx_PtExtlist_Utility_DbUtils::getAliasedSelectPartByFieldConfig($fieldConfiguration); } } return implode(', ', $selectParts); }
/** * Build the group data query to retrieve the group data * * @param array Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig $fields * @return Tx_PtExtlist_Domain_QueryObject_Query */ protected function buildGroupDataQuery($fields) { $groupDataQuery = new Tx_PtExtlist_Domain_QueryObject_Query(); foreach ($fields as $selectField) { $groupDataQuery->addField(Tx_PtExtlist_Utility_DbUtils::getAliasedSelectPartByFieldConfig($selectField)); } if ($this->additionalTables != '') { $groupDataQuery->addFrom($this->additionalTables); } foreach ($this->displayFields as $displayField) { /* @var $displayField Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig */ $groupDataQuery->addSorting($displayField->getIdentifier(), Tx_PtExtlist_Domain_QueryObject_Query::SORTINGSTATE_ASC); } if ($this->showRowCount) { // TODO only works with SQL! $groupDataQuery->addField(sprintf('count("%s") as rowCount', $this->filterField->getTableFieldCombined())); } $groupFields = array(); foreach ($this->getFieldsRequiredToBeSelected() as $field) { /* @var $field Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig */ $groupFields[] = $field->getIdentifier(); } $groupDataQuery->addGroupBy(implode(',', $groupFields)); return $groupDataQuery; }
/** * @param Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig $fieldIdentifier * @return Tx_PtExtlist_Domain_QueryObject_AndCriteria|Tx_PtExtlist_Domain_QueryObject_SimpleCriteria */ protected function buildFilterCriteria(Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig $fieldIdentifier) { if ($this->galleryUid) { $fieldName = Tx_PtExtlist_Utility_DbUtils::getSelectPartByFieldConfig($fieldIdentifier); if ($fieldIdentifier->getField() === 'album') { return $this->buildFilterCriteriaForAlbumField($fieldName); } else { return $this->buildFilterCriteriaForGalleryField($fieldName); } } }
/** @test */ public function buildSelectPartWithTableAndFieldReturnsExpectedString() { $pagerCollectionMock = $this->getMock('Tx_PtExtlist_Domain_Model_Pager_PagerCollection', array('setItemCount'), array(), '', false, false); $dataBackend = new Tx_PtExtlist_Domain_DataBackend_MySqlDataBackend_MySqlDataBackend($this->configurationBuilder); $dataBackend->_injectPagerCollection($pagerCollectionMock); $dataBackend->_injectQueryInterpreter(new Tx_PtExtlist_Domain_DataBackend_MySqlDataBackend_MySqlInterpreter_MySqlInterpreter()); $fieldConfigurationCollection = new Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfigCollection(); $fieldConfigurationCollection->addItem($this->getFieldConfigMockForTableAndFieldAndIdentifier('table1', 'field1', 'test1')); $fieldConfigurationCollection->addItem($this->getFieldConfigMockForTableAndFieldAndIdentifier('table1', 'field2', 'test2')); $dataBackend->_injectFieldConfigurationCollection($fieldConfigurationCollection); $selectPartForFieldConfigurationCollection = $dataBackend->buildSelectPart(); $expectedSelectPart = Tx_PtExtlist_Utility_DbUtils::getAliasedSelectPartByFieldConfig($fieldConfigurationCollection[0]) . ', ' . Tx_PtExtlist_Utility_DbUtils::getAliasedSelectPartByFieldConfig($fieldConfigurationCollection[1]); $this->assertTrue($selectPartForFieldConfigurationCollection == $expectedSelectPart, 'Select part for field configuration collection should be "' . $expectedSelectPart . '" but was ' . $selectPartForFieldConfigurationCollection); }
/** * @param Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig $fieldIdentifier * @return Tx_PtExtlist_Domain_QueryObject_SimpleCriteria */ protected function buildFilterCriteria(Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig $fieldIdentifier) { $fieldName = Tx_PtExtlist_Utility_DbUtils::getSelectPartByFieldConfig($fieldIdentifier); $criteria = Tx_PtExtlist_Domain_QueryObject_Criteria::equals($fieldName, $this->filterValue); return $criteria; }
/** * Build the criteria for a single field * * @param Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig $fieldIdentifier * @return Tx_PtExtlist_Domain_QueryObject_SimpleCriteria */ protected function buildFilterCriteria(Tx_PtExtlist_Domain_Configuration_Data_Fields_FieldConfig $fieldIdentifier) { $fieldName = Tx_PtExtlist_Utility_DbUtils::getSelectPartByFieldConfig($fieldIdentifier); $singleCriteria = null; if ($fieldIdentifier->getIsRelation()) { $singleCriteria = Tx_PtExtlist_Domain_QueryObject_Criteria::relation($fieldName, current($this->filterValues)); } elseif (is_array($this->filterValues) && count($this->filterValues) == 1) { $singleCriteria = Tx_PtExtlist_Domain_QueryObject_Criteria::equals($fieldName, current($this->filterValues)); } elseif (is_array($this->filterValues) && count($this->filterValues) > 1) { $singleCriteria = Tx_PtExtlist_Domain_QueryObject_Criteria::in($fieldName, $this->filterValues); } return $singleCriteria; }
/** * Build the filterCriteria for filter * * @return Tx_PtExtlist_Domain_QueryObject_Criteria */ protected function buildFilterCriteriaForAllFields() { $uidField = $this->fieldIdentifierCollection->getFieldConfigByIdentifier('uid'); $fieldName = Tx_PtExtlist_Utility_DbUtils::getSelectPartByFieldConfig($uidField); $criteria = Tx_PtExtlist_Domain_QueryObject_Criteria::in($fieldName, $this->getRandomUIDs()); return $criteria; }
/** * Build the group data query to retrieve the group data * * @return Tx_PtExtlist_Domain_QueryObject_Query */ protected function buildQuery() { $query = new Tx_PtExtlist_Domain_QueryObject_Query(); foreach ($this->dateFieldConfigs as $key => $selectField) { if ($selectField['start'] == $selectField['end']) { $aliasedSelectPart = Tx_PtExtlist_Utility_DbUtils::getSelectPartByFieldConfig($selectField['start']) . ' AS ' . $selectField['start']->getIdentifier(); $query->addField($aliasedSelectPart); } else { $aliasedSelectPartStart = Tx_PtExtlist_Utility_DbUtils::getSelectPartByFieldConfig($selectField['start']) . ' AS ' . $this->buildFieldAlias($key, 'start'); $aliasedSelectPartEnd = Tx_PtExtlist_Utility_DbUtils::getSelectPartByFieldConfig($selectField['end']) . ' AS ' . $this->buildFieldAlias($key, 'end'); $query->addField($aliasedSelectPartStart); $query->addField($aliasedSelectPartEnd); } } return $query; }