/** * Retrieve tree slice array * * @return array */ public function getTree() { if (!$this->hasData('_tree')) { $up = $this->_getData('up'); if (!abs(intval($up))) { $up = 0; } $down = $this->_getData('down'); if (!abs(intval($down))) { $down = 0; } $tree = $this->_node->setCollectActivePagesOnly(true)->setCollectIncludedPagesOnly(true)->setTreeMaxDepth($down)->setTreeIsBrief($this->isBrief())->getTreeSlice($up, 1); $this->setData('_tree', $tree); } return $this->_getData('_tree'); }
/** * Retrieve Nodes collection array * * @return array */ public function getNodes() { if (!$this->hasData('_nodes')) { // initialize nodes $nodes = $this->_node->setCollectActivePagesOnly(true)->getParentNodeChildren(); $flags = array('previous' => false, 'next' => false); $count = count($nodes); $previous = null; $next = null; $first = null; $last = null; $current = 0; foreach ($nodes as $k => $node) { $node->setPageNumber($k + 1); $node->setIsCurrent(false); if (is_null($first)) { $first = $node; } if ($flags['next']) { $next = $node; $flags['next'] = false; } if ($node->getId() == $this->_node->getId()) { $flags['next'] = true; $flags['previous'] = true; $current = $k; $node->setIsCurrent(true); } if (!$flags['previous']) { $previous = $node; } $last = $node; } $this->setPreviousNode($previous); $this->setFirstNode($first); $this->setLastNode($last); $this->setNextNode($next); $this->setCanShowNext($next !== null); // calculate pages frame range if ($this->getFrame() > 0) { $middleFrame = ceil($this->getFrame() / 2); if ($count > $this->getFrame() && $current < $middleFrame) { $start = 0; } else { $start = $current - $middleFrame + 1; if ($start + 1 + $this->getFrame() > $count) { $start = $count - $this->getFrame(); } } if ($start > 0) { $this->setCanShowFirst(true); } else { $this->setCanShowFirst(false); } $end = $start + $this->getFrame(); if ($end < $count) { $this->setCanShowLast(true); } else { $this->setCanShowLast(false); } } else { $this->setCanShowFirst(false); $this->setCanShowLast(false); $start = 0; $end = $count; } $this->setCanShowPreviousJump(false); $this->setCanShowNextJump(false); if ($start > 1) { $this->setCanShowPreviousJump(true); if ($start - 1 > $this->getJump() * 2) { $jump = $start - $this->getJump(); } else { $jump = ceil(($start - 1) / 2); } $this->setPreviousJump($nodes[$jump]); } if ($count - 1 > $end) { $this->setCanShowNextJump(true); $difference = $count - $end - 1; if ($difference < $this->getJump() * 2) { $jump = $end + ceil($difference / 2) - 1; } else { $jump = $end + $this->getJump() - 1; } $this->setNextJump($nodes[$jump]); } $this->setRangeStart($start); $this->setRangeEnd($end); $this->setData('_nodes', $nodes); } return $this->_getData('_nodes'); }