/** * @param mixed $query * @param string $lang * @param string $type * * @return mixed|void */ public function defineSearch($query, $lang, $type) { $query = \Elastica\Util::escapeTerm($query); $elasticaQueryLang = new \Elastica\Query\Term(); $elasticaQueryLang->setTerm('lang', $lang); $elasticaQueryString = new \Elastica\Query\Match(); $elasticaQueryString->setFieldQuery('content', $query)->setFieldMinimumShouldMatch('content', '80%'); $elasticaQueryTitle = new \Elastica\Query\QueryString(); $elasticaQueryTitle->setDefaultField('title')->setBoost(2.0)->setQuery($query); $elasticaQueryBool = new \Elastica\Query\BoolQuery(); $elasticaQueryBool->addMust($elasticaQueryLang)->addShould($elasticaQueryTitle)->addShould($elasticaQueryString)->setMinimumNumberShouldMatch(1); $this->applySecurityContext($elasticaQueryBool); if (!is_null($type)) { $elasticaQueryType = new \Elastica\Query\Term(); $elasticaQueryType->setTerm('type', $type); $elasticaQueryBool->addMust($elasticaQueryType); } $rootNode = $this->domainConfiguration->getRootNode(); if (!is_null($rootNode)) { $elasticaQueryRoot = new \Elastica\Query\Term(); $elasticaQueryRoot->setTerm('root_id', $rootNode->getId()); $elasticaQueryBool->addMust($elasticaQueryRoot); } $this->query->setQuery($elasticaQueryBool); $this->query->setHighlight(array('pre_tags' => array('<strong>'), 'post_tags' => array('</strong>'), 'fields' => array('content' => array('fragment_size' => 150, 'number_of_fragments' => 3)))); }
public function getPageChildren($page = null, $ofType = null, array $options = []) { if (null === $page) { $page = $this->domainConfiguration->getRootNode(); } return $this->siteTree->getChildren($page, $options + ['depth' => 0, 'refName' => $this->getRefNames($ofType)]); }
/** * @param RelationDefinition $query * @param string $lang * @param string $type * * @return void */ public function defineSearch($query, $lang, $type) { $category = $query->getCategory(); $tags = $query->getTags(); $exclude = $query->getExclude(); $rootNode = $this->domainConfiguration->getRootNode(); $bool = (new Query\BoolQuery())->setMinimumNumberShouldMatch(1); $bool->addMust((new Term())->setTerm('lang', $this->language)); $bool->addMust((new Term())->setTerm('type', $type)); $bool->addMust((new Term())->setTerm('view_roles', 'IS_AUTHENTICATED_ANONYMOUSLY')); if ($rootNode instanceof Node) { $root = new Term(); $root->setTerm('root_id', $rootNode->getId()); $bool->addMust($root); } // check if slug is non-empty: avoid filtering for home page if ($category && $category->getSlug()) { $bool->addShould((new Term())->setTerm('ancestors', $category->getNodeId())); } if ($tags) { $tagLogic = $this->tagsLogic instanceof TagLogic ?: new TagLogic(TagLogic::LOGIC_FEW); $minimum = $tagLogic->getMinMatch($tags); $bool->addShould((new Terms())->setMinimumMatch($minimum)->setTerms('tags', $tags)); } if (0 !== sizeof($exclude)) { $bool->addMustNot((new Terms())->setTerms('node_id', $exclude)); } $this->query = new Query(); $queryDefinition = new QueryDefinition($this->query, $bool); $this->feed->modifyQuery($queryDefinition); $queryDefinition->getQuery()->setQuery($queryDefinition->getFilterQuery()); }
/** * @param QueryBuilder $queryBuilder The query builder */ public function adaptQueryBuilder(QueryBuilder $queryBuilder) { parent::adaptQueryBuilder($queryBuilder); $queryBuilder->select('b,n')->innerJoin('b.node', 'n', 'WITH', 'b.node = n.id')->andWhere('b.lang = :lang')->andWhere('n.deleted = 0')->addOrderBy('b.updated', 'DESC')->setParameter('lang', $this->locale); if (!$this->domainConfiguration) { return; } $rootNode = $this->domainConfiguration->getRootNode(); if (!is_null($rootNode)) { $queryBuilder->andWhere('n.lft >= :left')->andWhere('n.rgt <= :right')->setParameter('left', $rootNode->getLeft())->setParameter('right', $rootNode->getRight()); } }
/** * Returns the current root node menu item */ public function getRootNodeMenuItem() { if (is_null($this->rootNodeMenuItem)) { $rootNode = $this->domainConfiguration->getRootNode(); if (!is_null($rootNode)) { $nodeTranslation = $rootNode->getNodeTranslation($this->locale, $this->includeOffline); $this->rootNodeMenuItem = new NodeMenuItem($rootNode, $nodeTranslation, false, $this); } else { $this->rootNodeMenuItem = $this->breadCrumb[0]; } } return $this->rootNodeMenuItem; }
public function configureOptions(OptionsResolver $resolver) { parent::configureOptions($resolver); $resolver->setDefaults(['advanced_select' => true, 'root_node' => function (Options $options) { return $this->domainConfiguration->getRootNode(); }, 'lang' => function (Options $options) { return $this->currentLocale->getCurrentLocale(); }, 'class' => function (Options $options) { return $this->contentTypeService->getContentTypeClass($options['page_name']); }, 'query_builder' => function (Options $options) { /** @var QueryBuilder $qb */ $qb = $options['em']->getRepository($options['class'])->createQueryBuilder('e'); $node = $options['root_node']; if ($node instanceof Node) { $qb->setParameters(['left' => $node->getLeft(), 'right' => $node->getRight()]); } $qb->setParameter('lang', $options['lang']); return $qb; }, 'empty_value' => ' ', 'required' => false]); $resolver->setAllowedTypes('root_node', ['null', Node::class]); $resolver->setRequired('page_name'); }
/** * Get the list of nodes that is used in the admin menu. * * @param string $lang * @param string $permission * @param AclNativeHelper $aclNativeHelper * @param bool $includeHiddenFromNav * * @return array */ private function getTreeNodes($lang, $permission, AclNativeHelper $aclNativeHelper, $includeHiddenFromNav) { if (is_null($this->treeNodes)) { $repo = $this->em->getRepository('KunstmaanNodeBundle:Node'); $this->treeNodes = array(); $rootNode = $this->domainConfiguration->getRootNode(); // Get all nodes that should be shown in the menu $allNodes = $repo->getAllMenuNodes($lang, $permission, $aclNativeHelper, $includeHiddenFromNav, $rootNode); /** @var Node $nodeInfo */ foreach ($allNodes as $nodeInfo) { $refEntityName = $nodeInfo['ref_entity_name']; if ($this->pagesConfiguration->isHiddenFromTree($refEntityName)) { continue; } $parent_id = is_null($nodeInfo['parent']) ? 0 : $nodeInfo['parent']; unset($nodeInfo['parent']); $this->treeNodes[$parent_id][] = $nodeInfo; } unset($allNodes); } return $this->treeNodes; }
/** * @param NodeTranslation $translation The node translation * @param EntityManager $em The entity manager * @param array $flashes Flashes * * A function that checks the URL and sees if it's unique. * It's allowed to be the same when the node is a StructureNode. * When a node is deleted it needs to be ignored in the check. * Offline nodes need to be included as well. * * It sluggifies the slug, updates the URL * and checks all existing NodeTranslations ([1]), excluding itself. If a * URL existsthat has the same url. If an existing one is found the slug is * modified, the URL is updated and the check is repeated until no prior * urls exist. * * NOTE: We need a way to tell if the slug has been modified or not. * NOTE: Would be cool if we could increment a number after the slug. Like * check if it matches -v# and increment the number. * * [1] For all languages for now. The issue is that we need a way to know * if a node's URL is prepended with the language or not. For now both * scenarios are possible so we check for all languages. * * @param NodeTranslation &$translation Reference to the NodeTranslation. * This is modified in place. * @param EntityManager $em The entity manager * @param array $flashes The flash messages array * * @return bool * * @return boolean */ private function ensureUniqueUrl(NodeTranslation &$translation, EntityManager $em, $flashes = array()) { // Can't use GetRef here yet since the NodeVersions aren't loaded yet for some reason. $nodeVersion = $translation->getPublicNodeVersion(); $page = $em->getRepository($nodeVersion->getRefEntityName())->find($nodeVersion->getRefId()); $isStructureNode = $page->isStructureNode(); // If it's a StructureNode the slug and url should be empty. if ($isStructureNode) { $translation->setSlug(''); $translation->setUrl($translation->getFullSlug()); return true; } /* @var NodeTranslationRepository $nodeTranslationRepository */ $nodeTranslationRepository = $em->getRepository('KunstmaanNodeBundle:NodeTranslation'); if ($translation->getUrl() == $translation->getFullSlug()) { $this->logger->addDebug('Evaluating URL for NT ' . $translation->getId() . ' getUrl: \'' . $translation->getUrl() . '\' getFullSlug: \'' . $translation->getFullSlug() . '\''); return false; } // Adjust the URL. $translation->setUrl($translation->getFullSlug()); // Find all translations with this new URL, whose nodes are not deleted. $translations = $nodeTranslationRepository->getNodeTranslationForUrl($translation->getUrl(), $translation->getLang(), false, $translation, $this->domainConfiguration->getRootNode()); $this->logger->addDebug('Found ' . count($translations) . ' node(s) that match url \'' . $translation->getUrl() . '\''); if (count($translations) > 0) { $oldUrl = $translation->getFullSlug(); $translation->setSlug($this->slugifier->slugify($this->incrementString($translation->getSlug()))); $newUrl = $translation->getFullSlug(); $message = 'The URL of the page has been changed from ' . $oldUrl . ' to ' . $newUrl . ' since another page already uses this URL.'; $this->logger->addInfo($message); $flashes[] = $message; $this->ensureUniqueUrl($translation, $em, $flashes); } elseif (count($flashes) > 0 && $this->isInRequestScope()) { // No translations found so we're certain we can show this message. $flash = current(array_slice($flashes, -1)); $this->session->getFlashBag()->add(FlashTypes::WARNING, $flash); } return true; }