예제 #1
0
 /**
  * Append mapping selects to given query-builder.
  *
  * @param QueryBuilder $queryBuilder
  * @param MappingInterface $mapping Includes array of property names.
  * @param string $locale
  * @param string[] $locales
  */
 private function appendMapping(QueryBuilder $queryBuilder, MappingInterface $mapping, $locale, $locales)
 {
     if ($mapping->onlyPublished()) {
         $queryBuilder->andWhere($this->qomFactory->comparison($this->qomFactory->propertyValue('node', $this->propertyEncoder->localizedSystemName('state', $locale)), '=', $this->qomFactory->literal(WorkflowStage::PUBLISHED)));
     }
     $properties = $mapping->getProperties();
     foreach ($properties as $propertyName) {
         $this->appendSingleMapping($queryBuilder, $propertyName, $locales);
     }
     if ($mapping->resolveUrl()) {
         $this->appendUrlMapping($queryBuilder, $locales);
     }
 }
예제 #2
0
 public function testAndWhere()
 {
     $dynamicOperand = $this->getMock('PHPCR\\Query\\QOM\\ConstraintInterface', array(), array());
     $this->qf = $this->getMock('PHPCR\\Query\\QOM\\QueryObjectModelFactoryInterface', array(), array());
     $this->qf->expects($this->once())->method('andConstraint');
     $constraint1 = $this->getMock('PHPCR\\Query\\QOM\\ConstraintInterface', array(), array());
     $constraint2 = $this->getMock('PHPCR\\Query\\QOM\\ConstraintInterface', array(), array());
     $qb = new QueryBuilder($this->qf);
     $qb->where($constraint1);
     $qb->andWhere($constraint2);
 }
 /**
  * @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)));
     }
 }
예제 #4
0
 /**
  * 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();
 }
 /**
  * Adds a constraint to the query
  *
  * @param ConstraintInterface $constraint
  * @return void
  */
 public function andWhere(ConstraintInterface $constraint)
 {
     $this->qb->andWhere($constraint);
 }
예제 #6
0
 /**
  * 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()));
 }