/** * Transforms a Resource from a database query to an array of rows. * * @param resource $result The result * @return array The result as an array of rows (tuples) */ protected function getRowsFromResult($result) { $rows = array(); while ($row = $this->databaseHandle->sql_fetch_assoc($result)) { if (is_array($row)) { // Get language uid from querySettings. // Ensure the backend handling is not broken (fallback to Get parameter 'L' if needed) $overlaidRow = $this->doLanguageAndWorkspaceOverlay($this->query->getSource(), $row, $this->query->getQuerySettings()); $contentObject = GeneralUtility::makeInstance($this->objectType, $this->query->getType(), $overlaidRow); $rows[] = $contentObject; } } return $rows; }
/** * 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); }