/**
  * Check the constraint and execute the query
  *
  * @param QueryInterface $query
  * @param array $constraints
  * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
  */
 public function matchAndExecute(QueryInterface $query, array $constraints = [])
 {
     if ($constraints) {
         $query->matching($query->logicalAnd($constraints));
     }
     return $query->execute();
 }
Ejemplo n.º 2
0
 /**
  * Builds the query
  * @return void
  */
 protected function buildQuery()
 {
     if ($this->categoryConstraintsLength > 0 && $this->categoryIsAll === FALSE && $this->searchConstraintsLength > 0) {
         $this->query->matching($this->query->logicalAnd($this->query->logicalOr($this->categoryConstraints), $this->query->logicalAnd($this->searchConstraints)));
     } elseif ($this->categoryConstraintsLength > 0 && $this->categoryIsAll === FALSE) {
         $this->query->matching($this->query->logicalOr($this->categoryConstraints));
     } elseif ($this->searchConstraintsLength > 0) {
         $this->query->matching($this->query->logicalAnd($this->searchConstraints));
     }
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }
Ejemplo n.º 4
0
 /**
  * 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);
 }