Esempio n. 1
0
 /**
  * Returns list of custom-url data-arrays.
  *
  * @param string $path
  * @param string $locale
  *
  * @return \Iterator
  */
 public function findList($path, $locale)
 {
     // TODO pagination
     $session = $this->sessionManager->getSession();
     $queryManager = $session->getWorkspace()->getQueryManager();
     $qomFactory = $queryManager->getQOMFactory();
     $queryBuilder = new QueryBuilder($qomFactory);
     $queryBuilder->select('a', 'jcr:uuid', 'uuid');
     $queryBuilder->addSelect('a', 'title', 'title');
     $queryBuilder->addSelect('a', 'published', 'published');
     $queryBuilder->addSelect('a', 'domainParts', 'domainParts');
     $queryBuilder->addSelect('a', 'baseDomain', 'baseDomain');
     $queryBuilder->addSelect('a', 'sulu:content', 'targetDocument');
     $queryBuilder->addSelect('a', 'sulu:created', 'created');
     $queryBuilder->addSelect('a', 'sulu:creator', 'creator');
     $queryBuilder->addSelect('a', 'sulu:changed', 'changed');
     $queryBuilder->addSelect('a', 'sulu:changer', 'changer');
     $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();
     $uuids = array_map(function (Row $item) {
         return $item->getValue('a.targetDocument');
     }, iterator_to_array($result->getRows()));
     $targets = $this->contentRepository->findByUuids(array_unique($uuids), $locale, MappingBuilder::create()->addProperties(['title'])->getMapping());
     return new RowsIterator($result->getRows(), $result->getColumnNames(), $targets, $this->generator, $this->userManager);
 }
Esempio n. 2
0
 /**
  * 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;
 }
 public function testSelect()
 {
     $qb = new QueryBuilder($this->qf);
     $this->assertCount(0, $qb->getColumns());
     $qb->select('selectorName', 'propertyName', 'columnName');
     $this->assertCount(1, $qb->getColumns());
     $qb->select('selectorName', 'propertyName', 'columnName');
     $this->assertCount(1, $qb->getColumns());
 }
 /**
  * @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)));
     }
 }