Exemplo n.º 1
0
 /**
  * Returns a like criterion used for matching objects against a query.
  * Matches if the property named $propertyName is like the $operand, using
  * standard SQL wildcards.
  *
  * @param string $propertyName The name of the property to compare against
  * @param string $operand The value to compare with
  * @param boolean $caseSensitive Whether the matching should be done case-sensitive
  * @return object
  * @throws \TYPO3\Flow\Persistence\Exception\InvalidQueryException if used on a non-string property
  * @api
  */
 public function like($propertyName, $operand, $caseSensitive = TRUE)
 {
     $aliasedPropertyName = $this->getPropertyNameWithAlias($propertyName);
     if ($caseSensitive === TRUE) {
         return $this->queryBuilder->expr()->like($aliasedPropertyName, $this->getParamNeedle($operand));
     }
     return $this->queryBuilder->expr()->like($this->queryBuilder->expr()->lower($aliasedPropertyName), $this->getParamNeedle(UnicodeFunctions::strtolower($operand)));
 }
 /**
  * Find nodes by a value in properties
  *
  * This method is internal and will be replaced with better search capabilities.
  *
  * @param string $term Search term
  * @param string $nodeTypeFilter Node type filter
  * @param Workspace $workspace
  * @param array $dimensions
  * @param string $pathStartingPoint
  * @return array<\TYPO3\TYPO3CR\Domain\Model\NodeData>
  */
 public function findByProperties($term, $nodeTypeFilter, $workspace, $dimensions, $pathStartingPoint = null)
 {
     $pathStartingPoint = strtolower($pathStartingPoint);
     if (strlen($term) === 0) {
         throw new \InvalidArgumentException('"term" cannot be empty: provide a term to search for.', 1421329285);
     }
     $workspaces = array();
     while ($workspace !== null) {
         $workspaces[] = $workspace;
         $workspace = $workspace->getBaseWorkspace();
     }
     $queryBuilder = $this->createQueryBuilder($workspaces);
     $this->addDimensionJoinConstraintsToQueryBuilder($queryBuilder, $dimensions);
     $this->addNodeTypeFilterConstraintsToQueryBuilder($queryBuilder, $nodeTypeFilter);
     // Convert to lowercase, then to json, and then trim quotes from json to have valid JSON escaping.
     $likeParameter = '%' . trim(json_encode(UnicodeFunctions::strtolower($term), JSON_UNESCAPED_UNICODE), '"') . '%';
     $queryBuilder->andWhere("LOWER(CONCAT('', n.properties)) LIKE :term")->setParameter('term', $likeParameter);
     if (strlen($pathStartingPoint) > 0) {
         $pathConstraint = $queryBuilder->expr()->orx()->add($queryBuilder->expr()->like('n.parentPath', ':parentPath'))->add($queryBuilder->expr()->eq('n.pathHash', ':pathHash'));
         $queryBuilder->setParameter('parentPath', $pathStartingPoint . '%')->setParameter('pathHash', md5($pathStartingPoint));
         $queryBuilder->getDQLPart('where')->add($pathConstraint);
     }
     $query = $queryBuilder->getQuery();
     $foundNodes = $query->getResult();
     $foundNodes = $this->reduceNodeVariantsByWorkspacesAndDimensions($foundNodes, $workspaces, $dimensions);
     $foundNodes = $this->filterRemovedNodes($foundNodes, false);
     return $foundNodes;
 }
 /**
  * Checks if our version of strtolower can at least handle some common special chars
  *
  * @test
  */
 public function strtolowerWorksWithCertainSpecialChars()
 {
     $testString = 'HERE ARE SOME CHARACTERS: ÄÖÜÄÖÜßÉÈÊÅÅØØÆÆŒŒ ...';
     $expectedResult = 'here are some characters: äöüäöüßéèêååøøæ朜 ...';
     $result = Functions::strtolower($testString);
     $this->assertEquals($expectedResult, $result, 'strtolower() could not convert our selection of special characters.');
 }
 /**
  * Find nodes by a value in properties
  *
  * This method is internal and will be replaced with better search capabilities.
  *
  * @param string|array $term Search term
  * @param string $nodeTypeFilter Node type filter
  * @param Workspace $workspace
  * @param array $dimensions
  * @param string $pathStartingPoint
  * @return array<\TYPO3\TYPO3CR\Domain\Model\NodeData>
  */
 public function findByProperties($term, $nodeTypeFilter, $workspace, $dimensions, $pathStartingPoint = null)
 {
     if (empty($term)) {
         throw new \InvalidArgumentException('"term" cannot be empty: provide a term to search for.', 1421329285);
     }
     $workspaces = $this->collectWorkspaceAndAllBaseWorkspaces($workspace);
     $queryBuilder = $this->createQueryBuilder($workspaces);
     $this->addDimensionJoinConstraintsToQueryBuilder($queryBuilder, $dimensions);
     $this->addNodeTypeFilterConstraintsToQueryBuilder($queryBuilder, $nodeTypeFilter);
     if (is_array($term)) {
         if (count($term) !== 1) {
             throw new \InvalidArgumentException('Currently only a 1-dimensional key => value array term is supported.', 1460437584);
         }
         // Build the like parameter as "key": "value" to search by a specific key and value
         $likeParameter = '%' . UnicodeFunctions::strtolower(trim(json_encode($term, JSON_PRETTY_PRINT | JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE), "{}\n\t ")) . '%';
     } else {
         // Convert to lowercase, then to json, and then trim quotes from json to have valid JSON escaping.
         $likeParameter = '%' . trim(json_encode(UnicodeFunctions::strtolower($term), JSON_UNESCAPED_UNICODE), '"') . '%';
     }
     $queryBuilder->andWhere("LOWER(NEOSCR_TOSTRING(n.properties)) LIKE :term")->setParameter('term', $likeParameter);
     if (strlen($pathStartingPoint) > 0) {
         $pathStartingPoint = strtolower($pathStartingPoint);
         $queryBuilder->andWhere($queryBuilder->expr()->orx()->add($queryBuilder->expr()->eq('n.parentPathHash', ':parentPathHash'))->add($queryBuilder->expr()->eq('n.pathHash', ':pathHash'))->add($queryBuilder->expr()->like('n.parentPath', ':parentPath')))->setParameter('parentPathHash', md5($pathStartingPoint))->setParameter('pathHash', md5($pathStartingPoint))->setParameter('parentPath', rtrim($pathStartingPoint, '/') . '/%');
     }
     $query = $queryBuilder->getQuery();
     $foundNodes = $query->getResult();
     $foundNodes = $this->reduceNodeVariantsByWorkspacesAndDimensions($foundNodes, $workspaces, $dimensions);
     $foundNodes = $this->filterRemovedNodes($foundNodes, false);
     return $foundNodes;
 }
 /**
  * Order current job list, order by name by default
  *
  * @param array $jobConfigurations
  * @param string $orderBy
  * @return array
  */
 protected function orderJobs(array $jobConfigurations, $orderBy = 'name')
 {
     usort($jobConfigurations, function ($a, $b) use($orderBy) {
         $a = Functions::strtolower(trim($a[$orderBy]));
         $b = Functions::strtolower(trim($b[$orderBy]));
         if ($a == $b) {
             return 0;
         }
         return $a < $b ? -1 : 1;
     });
     $result = [];
     foreach ($jobConfigurations as $jobConfiguration) {
         $result[] = $jobConfiguration['implementation'];
     }
     return $result;
 }
 /**
  * @return string
  */
 protected function getNormalizedIdentifier()
 {
     return str_replace("\\", ".", Functions::strtolower($this->getIdentifier()));
 }