/** * Generates the necessary search settings. * * @param \SKYFILLERS\SfSimpleFaq\Domain\Model\Dto\FaqDemand $demand A demand object * * @return void */ protected function generateSearchConstraints(\SKYFILLERS\SfSimpleFaq\Domain\Model\Dto\FaqDemand $demand) { if ($demand->getSearchtext()) { $searchtextConstraints = array(); $searchWords = GeneralUtility::trimExplode(' ', $demand->getSearchtext(), TRUE); foreach ($searchWords as $searchWord) { $searchtextConstraints[] = $this->query->logicalOr($this->query->like('question', '%' . $searchWord . '%'), $this->query->like('answer', '%' . $searchWord . '%'), $this->query->like('keywords', '%' . $searchWord . '%')); } if (count($searchtextConstraints) > 0) { $this->searchConstraints[] = $this->query->logicalOr($searchtextConstraints); } } $this->searchConstraintsLength = count($this->searchConstraints); }
/** * Pagination array gets build up * * @return array */ protected function buildPagination() { $pages = array(); $numberOfCharacters = count($this->characters); /* * Generates the pages and also checks if * the page has no objects */ for ($i = 0; $i < $numberOfCharacters; $i++) { $pages[] = array('linkCharacter' => str_replace(array('Ä', 'Ö', 'Ü'), array('AE', 'OE', 'UE'), $this->characters[$i]), 'character' => $this->characters[$i], 'isCurrent' => $this->characters[$i] === $this->currentCharacter, 'isEmpty' => 0 === $this->query->matching($this->query->like($this->field, $this->characters[$i] . '%'))->execute()->count()); } $pagination = array('pages' => $pages, 'current' => $this->currentCharacter, 'numberOfPages' => $numberOfCharacters, 'startCharacter' => $this->characters[0], 'endCharacter' => $this->characters[count($this->characters) + 1]); return $pagination; }
/** * @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); } }
/** * This function builds the matchings. * It enables matchings like: * - single character: 'B' * - multiple characters: 'BDEFG' * - range of characters: 'B-G' * * @param string $characters * @return QueryInterface */ protected function getMatchings($characters = NULL) { $matching = array(); if ($characters === NULL) { $characters = $this->currentCharacter; } $characterLength = strlen($characters); if ($characterLength === 1) { // single character B $matching = $this->query->like($this->field, $characters . '%'); } else { if ($characterLength === 3 && $characters[1] === '-') { // range B-G // Build the characters like multiple characters B-G => BCDEFG // Fix orderings $firstCharacter = ord($characters[0]); $lastCharacter = ord($characters[2]); if ($firstCharacter - $lastCharacter > 0) { $tmp = $firstCharacter; $firstCharacter = $lastCharacter; $lastCharacter = $tmp; } // Build the new String $characters = ''; for ($char = $firstCharacter; $char <= $lastCharacter; ++$char) { $characters .= chr($char); } } // multiple characters BDEFG $characters = str_split($characters); foreach ($characters as $char) { $matching[] = $this->query->like($this->field, $char . '%'); } $matching = $this->query->logicalOr($matching); } return $this->query->matching($matching); }
/** * Get the search constraints * * @param QueryInterface $query * @param DemandInterface $demand * @return array * @throws \UnexpectedValueException */ protected function getSearchConstraints(QueryInterface $query, DemandInterface $demand) { $constraints = []; if ($demand->getSearch() === null) { return $constraints; } /* @var $searchObject \GeorgRinger\News\Domain\Model\Dto\Search */ $searchObject = $demand->getSearch(); $searchSubject = $searchObject->getSubject(); if (!empty($searchSubject)) { $searchFields = GeneralUtility::trimExplode(',', $searchObject->getFields(), true); $searchConstraints = []; if (count($searchFields) === 0) { throw new \UnexpectedValueException('No search fields defined', 1318497755); } foreach ($searchFields as $field) { if (!empty($searchSubject)) { $searchConstraints[] = $query->like($field, '%' . $searchSubject . '%'); } } if (count($searchConstraints)) { $constraints[] = $query->logicalOr($searchConstraints); } } $minimumDate = strtotime($searchObject->getMinimumDate()); if ($minimumDate) { $field = $searchObject->getDateField(); if (empty($field)) { throw new \UnexpectedValueException('No date field is defined', 1396348732); } $constraints[] = $query->greaterThanOrEqual($field, $minimumDate); } $maximumDate = strtotime($searchObject->getMaximumDate()); if ($maximumDate) { $field = $searchObject->getDateField(); if (empty($field)) { throw new \UnexpectedValueException('No date field is defined', 1396348733); } $constraints[] = $query->lessThanOrEqual($field, $maximumDate); } return $constraints; }
/** * 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 title 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 setTitleConstraint($query, $eventDemand, &$constraints) { if ($eventDemand->getTitle() !== '') { $constraints[] = $query->like('title', '%' . $eventDemand->getTitle() . '%', FALSE); } }
/** * Sets the search 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 setSearchConstraint($query, $eventDemand, &$constraints) { if ($eventDemand->getSearchDemand() && $eventDemand->getSearchDemand()->getSearch() !== null && $eventDemand->getSearchDemand()->getSearch() !== '') { $searchFields = GeneralUtility::trimExplode(',', $eventDemand->getSearchDemand()->getFields(), true); $searchConstraints = []; if (count($searchFields) === 0) { throw new \UnexpectedValueException('No search fields defined', 1318497755); } $searchSubject = $eventDemand->getSearchDemand()->getSearch(); foreach ($searchFields as $field) { if (!empty($searchSubject)) { $searchConstraints[] = $query->like($field, '%' . $searchSubject . '%', false); } } if (count($searchConstraints)) { $constraints[] = $query->logicalOr($searchConstraints); } } }
/** * Get the search constraints * * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query * @param Tx_News_Domain_Model_DemandInterface $demand * @return array * @throws UnexpectedValueException */ protected function getSearchConstraints(\TYPO3\CMS\Extbase\Persistence\QueryInterface $query, Tx_News_Domain_Model_DemandInterface $demand) { $constraints = array(); if ($demand->getSearch() === NULL) { return $constraints; } /* @var $searchObject Tx_News_Domain_Model_Dto_Search */ $searchObject = $demand->getSearch(); $searchSubject = $searchObject->getSubject(); if (!empty($searchSubject)) { $searchFields = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $searchObject->getFields(), TRUE); $searchConstraints = array(); if (count($searchFields) === 0) { throw new UnexpectedValueException('No search fields defined', 1318497755); } foreach ($searchFields as $field) { if (!empty($searchSubject)) { $searchConstraints[] = $query->like($field, '%' . $searchSubject . '%'); } } if (count($searchConstraints)) { $constraints[] = $query->logicalOr($searchConstraints); } } $minimumDate = strtotime($searchObject->getMinimumDate()); if ($minimumDate) { $field = $searchObject->getDateField(); if (empty($field)) { throw new UnexpectedValueException('No date field is defined', 1396348732); } $constraints[] = $query->greaterThanOrEqual($field, $minimumDate); } $maximumDate = strtotime($searchObject->getMaximumDate()); if ($maximumDate) { $field = $searchObject->getDateField(); if (empty($field)) { throw new UnexpectedValueException('No date field is defined', 1396348733); } $constraints[] = $query->lessThanOrEqual($field, $maximumDate); } return $constraints; }