/** * 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; }
/** * @param Query $query * @param ConstraintInterface|NULL $constraints * @return array */ protected function respectFileMounts(Query $query, $constraints) { $tableName = 'sys_filemounts'; // Get the file mount identifiers for the current Backend User. $fileMounts = GeneralUtility::trimExplode(',', $this->getCurrentBackendUser()->dataLists['filemount_list']); $fileMountUids = implode(',', array_filter($fileMounts)); // Compute the clause. $clause = sprintf('uid IN (%s) %s %s', $fileMountUids, BackendUtility::BEenableFields($tableName), BackendUtility::deleteClause($tableName)); // Fetch the records. $fileMountRecords = $this->getDatabaseConnection()->exec_SELECTgetRows('path', $tableName, $clause); $constraintsRespectingFileMounts = array(); foreach ($fileMountRecords as $fileMountRecord) { if ($fileMountRecord['path']) { $constraintsRespectingFileMounts[] = $query->like('identifier', $fileMountRecord['path'] . '%'); } } $constraintsRespectingFileMounts = $query->logicalOr($constraintsRespectingFileMounts); $constraints = $query->logicalAnd($constraints, $constraintsRespectingFileMounts); return array($query, $constraints); }