Ejemplo n.º 1
0
 /**
  * Computes the search constraint and returns it.
  *
  * @param Query $query
  * @param Matcher $matcher
  * @return ConstraintInterface|NULL
  */
 protected function computeSearchTermConstraint(Query $query, Matcher $matcher)
 {
     $result = NULL;
     // Search term case
     if ($matcher->getSearchTerm()) {
         $fields = GeneralUtility::trimExplode(',', Tca::table($this->dataType)->getSearchFields(), TRUE);
         $constraints = array();
         $likeClause = sprintf('%%%s%%', $matcher->getSearchTerm());
         foreach ($fields as $fieldNameAndPath) {
             if ($this->isSuitableForLike($fieldNameAndPath, $matcher->getSearchTerm())) {
                 $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->dataType);
                 $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->dataType);
                 if (Tca::table($dataType)->hasField($fieldName) && Tca::table($dataType)->field($fieldName)->hasRelation()) {
                     $foreignTable = Tca::table($dataType)->field($fieldName)->getForeignTable();
                     $fieldNameAndPath = $fieldNameAndPath . '.' . Tca::table($foreignTable)->getLabelField();
                 }
                 $constraints[] = $query->like($fieldNameAndPath, $likeClause);
             }
         }
         $logical = $matcher->getLogicalSeparatorForSearchTerm();
         $result = $query->{$logical}($constraints);
     }
     return $result;
 }