Esempio n. 1
0
 /**
  * Prepare the statement for selecting the records which will be returned to the selector. May also return some
  * other records (e.g. from a mm-table) which will be used later on to select the real records
  *
  * @return void
  */
 protected function prepareSelectStatement()
 {
     $expressionBuilder = $this->queryBuilder->expr();
     $searchWholePhrase = !isset($this->config['searchWholePhrase']) || $this->config['searchWholePhrase'];
     $searchString = $this->params['value'];
     $searchUid = (int) $searchString;
     if ($searchString !== '') {
         $likeCondition = ($searchWholePhrase ? '%' : '') . $searchString . '%';
         // Search in all fields given by label or label_alt
         $selectFieldsList = $GLOBALS['TCA'][$this->table]['ctrl']['label'] . ',' . $GLOBALS['TCA'][$this->table]['ctrl']['label_alt'] . ',' . $this->config['additionalSearchFields'];
         $selectFields = GeneralUtility::trimExplode(',', $selectFieldsList, true);
         $selectFields = array_unique($selectFields);
         $selectParts = $expressionBuilder->orX();
         foreach ($selectFields as $field) {
             $selectParts->add($expressionBuilder->like($field, $this->queryBuilder->createPositionalParameter($likeCondition)));
         }
         $searchClause = $expressionBuilder->orX($selectParts);
         if ($searchUid > 0 && $searchUid == $searchString) {
             $searchClause->add($expressionBuilder->eq('uid', $searchUid));
         }
         $this->queryBuilder->andWhere($expressionBuilder->orX($searchClause));
     }
     if (!empty($this->allowedPages)) {
         $pidList = array_map('intval', $this->allowedPages);
         if (!empty($pidList)) {
             $this->queryBuilder->andWhere($expressionBuilder->in('pid', $pidList));
         }
     }
     // add an additional search condition comment
     if (isset($this->config['searchCondition']) && $this->config['searchCondition'] !== '') {
         $this->queryBuilder->andWhere(QueryHelper::stripLogicalOperatorPrefix($this->config['searchCondition']));
     }
 }
 /**
  * @test
  */
 public function createPositionalParameterDelegatesToConcreteQueryBuilder()
 {
     $this->concreteQueryBuilder->createPositionalParameter(5, Argument::cetera())->shouldBeCalled()->willReturn('?');
     $this->subject->createPositionalParameter(5);
 }