private function calculatePrevNext(Branch $siblings, HasNodeInterface $page, $loop)
 {
     $result = ['prev' => null, 'next' => null];
     // zero or one results (current page) means there is nowhere to navigate to
     if (1 >= sizeof($siblings->getChildren())) {
         return $result;
     }
     $current = null;
     foreach ($siblings->getChildren() as $item) {
         if ((string) $item->getRefId() === (string) $page->getId()) {
             $current = $item;
             break;
         }
     }
     if (null !== $current) {
         $result = ['prev' => $this->utility->getPreviousSibling($siblings, $current), 'next' => $this->utility->getNextSibling($siblings, $current)];
     }
     if ($loop) {
         $result['prev'] = $result['prev'] ?: $this->utility->getLastChild($siblings);
         $result['next'] = $result['next'] ?: $this->utility->getFirstChild($siblings);
     }
     return $result;
 }
 /**
  * Add custom data to index document (you can override to add custom fields
  * to the search index)
  *
  * @param HasNodeInterface $page
  * @param array            $doc
  */
 protected function addCustomData(HasNodeInterface $page, &$doc)
 {
     $event = new IndexNodeEvent($page, $doc);
     $this->container->get('event_dispatcher')->dispatch(IndexNodeEvent::EVENT_INDEX_NODE, $event);
     $doc = $event->doc;
     if ($page instanceof HasCustomSearchDataInterface) {
         $doc += $page->getCustomSearchData($doc);
     }
 }
Exemplo n.º 3
0
 private function createTranslationNode(Node $rootNode, $language, HasNodeInterface $page)
 {
     $translationNode = new NodeTranslation();
     $translationNode->setNode($rootNode)->setLang($language)->setTitle($page->getTitle())->setOnline(false)->setWeight(0);
     return $translationNode;
 }
 /**
  * @param HasNodeInterface $entity
  *
  * @return NodeVersion
  */
 public function setRef(HasNodeInterface $entity)
 {
     $this->setRefId($entity->getId());
     $this->setRefEntityName(ClassLookup::getClass($entity));
     return $this;
 }
 /**
  * Add boost to the index document
  *
  * @param Node             $node
  * @param HasNodeInterface $page
  * @param array            $doc
  */
 protected function addBoost($node, HasNodeInterface $page, &$doc)
 {
     // Check page type boost
     $doc['_boost'] = 1.0;
     if ($page instanceof SearchBoostInterface) {
         $doc['_boost'] += $page->getSearchBoost();
     }
     // Check if page is boosted
     $nodeSearch = $this->em->getRepository('KunstmaanNodeSearchBundle:NodeSearch')->findOneByNode($node);
     if ($nodeSearch !== null) {
         $doc['_boost'] += $nodeSearch->getBoost();
     }
 }
 /**
  * @param HasNodeInterface $hasNode
  *
  * @return NodeVersion
  */
 public function getNodeVersionFor(HasNodeInterface $hasNode)
 {
     return $this->findOneBy(array('refId' => $hasNode->getId(), 'refEntityName' => ClassLookup::getClass($hasNode)));
 }