/** * Returns a category constraint created by * a given list of categories and a junction string * * @param QueryInterface $query * @param array $categories * @param string $conjunction * @param boolean $includeSubCategories * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface|null */ protected function createCategoryConstraint(QueryInterface $query, $categories, $conjunction, $includeSubCategories = false) { $constraint = null; $categoryConstraints = []; // If "ignore category selection" is used, nothing needs to be done if (empty($conjunction)) { return $constraint; } if (!is_array($categories)) { $categories = GeneralUtility::intExplode(',', $categories, true); } foreach ($categories as $category) { if ($includeSubCategories) { $subCategories = GeneralUtility::trimExplode(',', CategoryService::getChildrenCategories($category, 0, '', true), true); $subCategoryConstraint = []; $subCategoryConstraint[] = $query->contains('categories', $category); if (count($subCategories) > 0) { foreach ($subCategories as $subCategory) { $subCategoryConstraint[] = $query->contains('categories', $subCategory); } } if ($subCategoryConstraint) { $categoryConstraints[] = $query->logicalOr($subCategoryConstraint); } } else { $categoryConstraints[] = $query->contains('categories', $category); } } if ($categoryConstraints) { switch (strtolower($conjunction)) { case 'or': $constraint = $query->logicalOr($categoryConstraints); break; case 'notor': $constraint = $query->logicalNot($query->logicalOr($categoryConstraints)); break; case 'notand': $constraint = $query->logicalNot($query->logicalAnd($categoryConstraints)); break; case 'and': default: $constraint = $query->logicalAnd($categoryConstraints); } } return $constraint; }
/** * Returns a category constraint created by * a given list of categories and a junction string * * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query * @param array $categories * @param string $conjunction * @param boolean $includeSubCategories * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface|null */ protected function createCategoryConstraint(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query, $categories, $conjunction, $includeSubCategories = FALSE) { $constraint = NULL; $categoryConstraints = array(); // If "ignore category selection" is used, nothing needs to be done if (empty($conjunction)) { return $constraint; } if (!is_array($categories)) { $categories = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $categories, TRUE); } foreach ($categories as $category) { if ($includeSubCategories) { $subCategories = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', Tx_News_Service_CategoryService::getChildrenCategories($category, 0, '', TRUE), TRUE); $subCategoryConstraint = array(); $subCategoryConstraint[] = $query->contains('categories', $category); if (count($subCategories) > 0) { foreach ($subCategories as $subCategory) { $subCategoryConstraint[] = $query->contains('categories', $subCategory); } } if ($subCategoryConstraint) { $categoryConstraints[] = $query->logicalOr($subCategoryConstraint); } } else { $categoryConstraints[] = $query->contains('categories', $category); } } if ($categoryConstraints) { switch (strtolower($conjunction)) { case 'or': $constraint = $query->logicalOr($categoryConstraints); break; case 'notor': $constraint = $query->logicalNot($query->logicalOr($categoryConstraints)); break; case 'notand': $constraint = $query->logicalNot($query->logicalAnd($categoryConstraints)); break; case 'and': default: $constraint = $query->logicalAnd($categoryConstraints); } } return $constraint; }
/** * Build category constraint for each category (contains) * * @param array $categories * @return array */ protected function buildCategoryConstraint(array $categories) { $contraints = array(); foreach ($categories as $category) { $contraints[] = $this->query->contains('categories', $category); } return $contraints; }
/** * Generates the necessary category settings. * * @param \SKYFILLERS\SfSimpleFaq\Domain\Model\Dto\FaqDemand $demand A demand * * @return void */ protected function generateCategories(\SKYFILLERS\SfSimpleFaq\Domain\Model\Dto\FaqDemand $demand) { $categories = $demand->getCategories(); if (strlen($categories) > 1) { $categories = explode(',', $categories); } $this->categoriesLength = count($categories); if ($this->categoriesLength != 0) { for ($i = 0; $i < $this->categoriesLength; $i++) { array_push($this->categoryConstraints, $this->query->contains('category', (string) $categories[$i])); } } $this->categoryConstraintsLength = count($this->categoryConstraints); if ($categories[0] == 0 && $this->categoryConstraintsLength < 2) { $this->categoryIsAll = TRUE; } }
/** * @param \GeorgRinger\Newsadvancedsearch\Domain\Model\Dto\Demand $demand * @param bool $respectEnableFields * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query * @param array $constraints */ protected function updateConstraints(\GeorgRinger\Newsadvancedsearch\Domain\Model\Dto\Demand $demand, $respectEnableFields, \TYPO3\CMS\Extbase\Persistence\QueryInterface $query, array &$constraints) { $subject = $demand->getSubject(); if (!empty($subject)) { $constraints[] = $query->like('title', '%' . $subject . '%'); } $locations = $demand->getLocations(); if (!empty($locations)) { $locationConstraints = array(); foreach ($locations as $typeId) { $locationConstraints[] = $query->contains('locations', $typeId); } $constraints[] = $query->logicalOr($locationConstraints); } $types = $demand->getTypes(); if (!empty($types)) { $typesConstraints = array(); foreach ($types as $typeId) { $typesConstraints[] = $query->contains('eventtypes', $typeId); } $constraints[] = $query->logicalOr($typesConstraints); } }
/** * Get a QueryInterface constraint from an array definition * * @param QueryInterface $query * @param array $demands * @param string $conjunction * * @return ConstraintInterface|null */ public static function getConstraintsForDemand($query, $demands, $conjunction = 'AND') { $constraints = array(); if (!is_array($demands) || empty($demands)) { return null; } foreach ($demands as $key => $demand) { if (!isset($demand['demand'])) { continue; } $constraint = $demand['demand']; switch ($constraint['operation']) { case 'EQUALS': $constraints[] = $query->equals($constraint['property'], $constraint['value']); break; case 'LIKE': $constraints[] = $query->like($constraint['property'], $constraint['value']); break; case 'CONTAINS': $constraints[] = $query->contains($constraint['property'], $constraint['value']); break; case 'LESSTHAN': $constraints[] = $query->lessThan($constraint['property'], $constraint['value']); break; case 'LESSTHANOREQUAL': $constraints[] = $query->lessThanOrEqual($constraint['property'], $constraint['value']); break; case 'GREATERTHAN': $constraints[] = $query->greaterThan($constraint['property'], $constraint['value']); break; case 'GREATERTHANOREQUAL': $constraints[] = $query->greaterThanOrEqual($constraint['property'], $constraint['value']); break; case 'AND': $tmp = self::getConstraintsForDemand($query, $constraint['operands'], 'AND'); if ($tmp !== null) { $constraints[] = $tmp; } break; case 'OR': $tmp = self::getConstraintsForDemand($query, $constraint['operands'], 'OR'); if ($tmp !== null) { $constraints[] = $tmp; } break; default: return null; } } if (count($constraints) == 0) { return null; } $result = null; switch ($conjunction) { case 'AND': $result = $query->logicalAnd($constraints); break; case 'OR': $result = $query->logicalOr($constraints); break; } return $result; }
/** * Sets the category constraint to the given constraints array * * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand * @param array $constraints Constraints * * @return void */ protected function setCategoryConstraint($query, $eventDemand, &$constraints) { if ($eventDemand->getCategory() != '') { $categoryConstraints = array(); $categories = GeneralUtility::intExplode(',', $eventDemand->getCategory(), TRUE); foreach ($categories as $category) { $categoryConstraints[] = $query->contains('category', $category); } if (count($categoryConstraints) > 0) { $constraints[] = $query->logicalOr($categoryConstraints); } } }
/** * Sets the category constraint to the given constraints array * * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand * @param array $constraints Constraints * * @return void */ protected function setCategoryConstraint($query, $eventDemand, &$constraints) { if ($eventDemand->getCategory() != '') { $categoryConstraints = []; if ($eventDemand->getIncludeSubcategories()) { $categoryList = CategoryService::getCategoryListWithChilds($eventDemand->getCategory()); $categories = GeneralUtility::intExplode(',', $categoryList, true); } else { $categories = GeneralUtility::intExplode(',', $eventDemand->getCategory(), true); } foreach ($categories as $category) { $categoryConstraints[] = $query->contains('category', $category); } if (count($categoryConstraints) > 0) { $constraints[] = $query->logicalOr($categoryConstraints); } } }