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; }
/** * @param HasNodeInterface $entity * * @return NodeVersion */ public function setRef(HasNodeInterface $entity) { $this->setRefId($entity->getId()); $this->setRefEntityName(ClassLookup::getClass($entity)); return $this; }
/** * @param HasNodeInterface $hasNode * * @return NodeVersion */ public function getNodeVersionFor(HasNodeInterface $hasNode) { return $this->findOneBy(array('refId' => $hasNode->getId(), 'refEntityName' => ClassLookup::getClass($hasNode))); }