コード例 #1
0
 /**
  * @dataProvider provideWalkQOMQuery
  */
 public function testWalkQOMQuery($description, $queryCallback, $expected)
 {
     $qb = new QueryBuilder($this->qomf);
     $this->nodeTypeManager->hasNodeType('foobar')->willReturn(true);
     $this->nodeTypeManager->hasNodeType('nt:foobar')->willReturn(true);
     $qb->from($this->qomf->selector('a', 'foobar'));
     $queryCallback($qb, $this->qomf);
     $res = $this->qomWalker->walkQOMQuery($qb->getQuery());
     $this->assertEquals($expected, $res, $description);
 }
コード例 #2
0
ファイル: ContentRepository.php プロジェクト: Silwereth/sulu
 /**
  * Resolve property has-children with given node.
  *
  * @param Row $row
  *
  * @return bool
  */
 private function resolveHasChildren(Row $row)
 {
     $queryBuilder = new QueryBuilder($this->qomFactory);
     $queryBuilder->select('node', 'jcr:uuid', 'uuid')->from($this->qomFactory->selector('node', 'nt:unstructured'))->where($this->qomFactory->childNode('node', $row->getPath()))->setMaxResults(1);
     $result = $queryBuilder->execute();
     return count(iterator_to_array($result->getRows())) > 0;
 }
コード例 #3
0
 public function testExecute()
 {
     $source = $this->getMock('PHPCR\\Query\\QOM\\SourceInterface', array(), array());
     $constraint = $this->getMock('PHPCR\\Query\\QOM\\ConstraintInterface', array(), array());
     $query = $this->getMock('PHPCR\\Query\\QueryInterface', array(), array());
     $query->expects($this->once())->method('execute');
     $query->expects($this->once())->method('bindValue');
     $this->qf->expects($this->once())->method('createQuery')->with($source, $constraint, array(), array())->will($this->returnValue($query));
     $qb = new QueryBuilder($this->qf);
     $qb->from($source)->where($constraint)->setFirstResult(10)->setMaxResults(10)->setParameter('Key', 'value')->execute();
 }
コード例 #4
0
 /**
  * @param QueryBuilder $qb
  * @param string       $query
  * @param int          $page
  * @param string       $lang
  */
 protected function buildQuery(QueryBuilder $qb, $query, $page, $lang)
 {
     $factory = $qb->getQOMFactory();
     $qb->select('a', 'jcr:uuid', 'uuid')->addSelect('a', 'phpcr:class', 'class')->from($factory->selector('a', 'nt:unstructured'))->where($factory->descendantNode('a', $this->searchPath))->setFirstResult(($page - 1) * $this->perPage)->setMaxResults($this->perPage);
     $constraint = null;
     foreach ($this->searchFields as $field) {
         $column = $field;
         if (2 === strlen($lang) && 'attribute' === $this->translationStrategy) {
             $field = "phpcr_locale:{$lang}-{$field}";
         }
         $qb->addSelect('a', $field, $column);
         $newConstraint = $factory->fullTextSearch('a', $field, $query);
         if (empty($constraint)) {
             $constraint = $newConstraint;
         } else {
             $constraint = $factory->orConstraint($constraint, $newConstraint);
         }
     }
     $qb->andWhere($constraint);
     if (2 === strlen($lang) && 'child' === $this->translationStrategy) {
         // TODO: check if we can/must validate lang to prevent evil hacking or accidental breakage
         $qb->andWhere($factory->comparison($factory->nodeName('a'), '=', $factory->literal('phpcr_locale:' . $lang)));
     }
 }
コード例 #5
0
 public function testStatements()
 {
     //simple query, should be sql
     $this->qb->from($this->qf->selector('nt:base', "nt:base"));
     $this->assertSame('sql', $this->qb->getQuery()->getLanguage());
     $this->assertSame("SELECT s FROM nt:base", $this->qb->getQuery()->getStatement());
     //localname is not supported by sql1
     $this->qb->where($this->qf->comparison($this->qf->nodeLocalName('nt:base'), Constants::JCR_OPERATOR_EQUAL_TO, $this->qf->literal('foo')));
     $this->assertSame('JCR-SQL2', $this->qb->getQuery()->getLanguage());
     $this->assertSame("SELECT * FROM [nt:base] WHERE LOCALNAME(nt:base) = 'foo'", $this->qb->getQuery()->getStatement());
     //descendantNode is supported by sql1
     $this->qb->where($this->qf->descendantNode('nt:base', "/foo"));
     //$this->assertSame('sql', $this->qb->getQuery()->getLanguage());
     $this->assertSame("SELECT s FROM nt:base WHERE jcr:path LIKE '/foo[%]/%'", $this->qb->getQuery()->getStatement());
     //joins are not supported by sql1
     $this->qb->join($this->qf->selector('nt:unstructured', "nt:unstructured"), $this->qf->equiJoinCondition("nt:base", "data", "nt:unstructured", "data"));
     $this->assertSame('JCR-SQL2', $this->qb->getQuery()->getLanguage());
     $this->assertSame("SELECT * FROM [nt:base] INNER JOIN [nt:unstructured] ON [nt:base].data=[nt:unstructured].data WHERE ISDESCENDANTNODE([nt:base], [/foo])", $this->qb->getQuery()->getStatement());
 }
コード例 #6
0
ファイル: SnippetRepository.php プロジェクト: kriswillis/sulu
 /**
  * Return snippets load query.
  *
  * If $type is given then only return the snippets of that type.
  *
  * @param string $languageCode
  * @param string $type         Optional snippet type
  * @param int    $offset       Optional offset
  * @param int    $max          Optional max
  * @param string $search
  * @param string $sortBy
  * @param string $sortOrder
  *
  * @return Query
  */
 private function getSnippetsQuery($languageCode, $type = null, $offset = null, $max = null, $search = null, $sortBy = null, $sortOrder = null)
 {
     $snippetNode = $this->sessionManager->getSnippetNode($type);
     $workspace = $this->sessionManager->getSession()->getWorkspace();
     $queryManager = $workspace->getQueryManager();
     $qf = $queryManager->getQOMFactory();
     $qb = new QueryBuilder($qf);
     $qb->from($qb->qomf()->selector('a', 'nt:unstructured'));
     if (null === $type) {
         $qb->where($qb->qomf()->descendantNode('a', $snippetNode->getPath()));
     } else {
         $qb->where($qb->qomf()->childNode('a', $snippetNode->getPath()));
     }
     $qb->andWhere($qb->qomf()->comparison($qb->qomf()->propertyValue('a', 'jcr:mixinTypes'), QueryObjectModelConstantsInterface::JCR_OPERATOR_EQUAL_TO, $qb->qomf()->literal('sulu:snippet')));
     if (null !== $offset) {
         $qb->setFirstResult($offset);
         if (null === $max) {
             // we get zero results if no max specified
             throw new \InvalidArgumentException('If you specify an offset then you must also specify $max');
         }
         $qb->setMaxResults($max);
     }
     if (null !== $search) {
         $searchConstraint = $qf->orConstraint($qf->comparison($qf->propertyValue('a', 'i18n:' . $languageCode . '-title'), QueryObjectModelConstantsInterface::JCR_OPERATOR_LIKE, $qf->literal('%' . $search . '%')), $qf->comparison($qf->propertyValue('a', 'template'), QueryObjectModelConstantsInterface::JCR_OPERATOR_LIKE, $qf->literal('%' . $search . '%')));
         $qb->andWhere($searchConstraint);
     }
     // Title is a mandatory property for snippets
     // NOTE: Prefixing the language code and namespace here is bad. But the solution is
     //       refactoring (i.e. a node property name translator service).
     $sortOrder = $sortOrder !== null ? strtoupper($sortOrder) : 'ASC';
     $sortBy = $sortBy !== null ? $sortBy : 'title';
     $qb->orderBy($qb->qomf()->propertyValue('a', 'i18n:' . $languageCode . '-' . $sortBy), $sortOrder !== null ? strtoupper($sortOrder) : 'ASC');
     return $qb->getQuery();
 }
コード例 #7
0
 /**
  * Adds a constraint to the query
  *
  * @param ConstraintInterface $constraint
  * @return void
  */
 public function andWhere(ConstraintInterface $constraint)
 {
     $this->qb->andWhere($constraint);
 }
コード例 #8
0
ファイル: CustomUrlRepository.php プロジェクト: sulu/sulu
 /**
  * Returns list of custom-url data-arrays.
  *
  * @param string $path
  *
  * @return \Iterator
  */
 public function findUrls($path)
 {
     $session = $this->sessionManager->getSession();
     $queryManager = $session->getWorkspace()->getQueryManager();
     $qomFactory = $queryManager->getQOMFactory();
     $queryBuilder = new QueryBuilder($qomFactory);
     $queryBuilder->addSelect('a', 'domainParts', 'domainParts')->addSelect('a', 'baseDomain', 'baseDomain');
     $queryBuilder->from($queryBuilder->qomf()->selector('a', 'nt:unstructured'));
     $queryBuilder->where($queryBuilder->qomf()->comparison($queryBuilder->qomf()->propertyValue('a', 'jcr:mixinTypes'), QueryObjectModelConstantsInterface::JCR_OPERATOR_EQUAL_TO, $queryBuilder->qomf()->literal('sulu:custom_url')));
     $queryBuilder->andWhere($queryBuilder->qomf()->descendantNode('a', $path));
     $query = $queryBuilder->getQuery();
     $result = $query->execute();
     return array_map(function (Row $item) {
         return $this->generator->generate($item->getValue('a.baseDomain'), json_decode($item->getValue('a.domainParts'), true));
     }, iterator_to_array($result->getRows()));
 }