/** * Post-process the matcher object to respect the file storages. * * @param Matcher $matcher * @param string $dataType * @return void */ public function addFilePermissionsForFileStorages(Matcher $matcher, $dataType) { if ($dataType === 'sys_file' && $this->isPermissionNecessary()) { if ($this->isFolderConsidered()) { $folder = $this->getMediaModule()->getCurrentFolder(); if ($this->getMediaModule()->hasRecursiveSelection()) { // Only add like condition if needed. if ($folder->getStorage()->getRootLevelFolder() !== $folder) { $matcher->like('identifier', $folder->getIdentifier() . '%', $automaticallyAddWildCard = FALSE); } } else { // Browse only currently $files = $this->getFileUids($folder); $matcher->in('uid', $files); } $matcher->equals('storage', $folder->getStorage()->getUid()); } else { $storage = $this->getMediaModule()->getCurrentStorage(); // Set the storage identifier only if the storage is on-line. $identifier = -1; if ($storage->isOnline()) { $identifier = $storage->getUid(); } if ($this->getModuleLoader()->hasPlugin() && !$this->getCurrentBackendUser()->isAdmin()) { $fileMounts = $this->getCurrentBackendUser()->getFileMountRecords(); $collectedFiles = array(); foreach ($fileMounts as $fileMount) { $combinedIdentifier = $fileMount['base'] . ':' . $fileMount['path']; $folder = ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($combinedIdentifier); $files = $this->getFileUids($folder); $collectedFiles = array_merge($collectedFiles, $files); } $matcher->in('uid', $collectedFiles); } $matcher->equals('storage', $identifier); } } }
/** * Apply criteria from categories. * * @param Matcher $matcher * @return Matcher $matcher */ protected function applyCriteriaFromAdditionalConstraints(Matcher $matcher) { if (!empty($this->settings['additionalEquals'])) { $constraints = GeneralUtility::trimExplode(',', $this->settings['additionalEquals'], TRUE); foreach ($constraints as $constraint) { if (preg_match('/.+=.+/isU', $constraint, $matches)) { $constraintParts = GeneralUtility::trimExplode('=', $constraint, TRUE); if (count($constraintParts) === 2) { $matcher->equals(trim($constraintParts[0]), trim($constraintParts[1])); } } elseif (preg_match('/.+like.+/isU', $constraint, $matches)) { $constraintParts = GeneralUtility::trimExplode('like', $constraint, TRUE); if (count($constraintParts) === 2) { $matcher->like(trim($constraintParts[0]), trim($constraintParts[1])); } } } } return $matcher; }
/** * Finds all Contents given specified matches. * * @param Matcher $matcher * @param Order $order The order * @param int $limit * @param int $offset * @return Content[] */ public function findBy(Matcher $matcher, Order $order = NULL, $limit = NULL, $offset = NULL) { $query = $this->createQuery(); if ($limit) { $query->setLimit($limit); } if ($order) { $query->setOrderings($order->getOrderings()); // Loops around the orderings adding if necessary a dummy condition // to make sure the relations can be resolved when transforming the query to plain SQL. foreach ($order->getOrderings() as $ordering => $direction) { if ($this->hasForeignRelationIn($ordering)) { $relationalField = $this->getForeignRelationFrom($ordering); $matcher->like($relationalField . '.uid', ''); } } } if ($offset) { $query->setOffset($offset); } $constraints = $this->computeConstraints($query, $matcher); if ($constraints) { $query->matching($constraints); } return $query->execute(); }