Example #1
0
 /**
  * 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');
 }
Example #2
0
 /**
  * Check if passed node available for store in case this node representation of page.
  * If node does not represent page then method will return true.
  *
  * @param Enterprise_Cms_Model_Hierarchy_Node $node
  * @param null|int $store
  * @return bool
  */
 public function isNodeAvailableForStore($node, $store)
 {
     if (!$node->getPageId()) {
         return true;
     }
     if (!$store) {
         return true;
     }
     if ($node->getPageInStores() == '0') {
         return true;
     }
     $stores = explode(',', $node->getPageInStores());
     if (in_array($store, $stores)) {
         return true;
     }
     return false;
 }
 /**
  * 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');
 }
Example #4
0
 /**
  * Checks whether node belongs to currently active node's path
  *
  * @param Enterprise_Cms_Model_Hierarchy_Node $cmsNode
  * @return bool
  */
 protected function _isCmsNodeActive($cmsNode)
 {
     $currentNode = Mage::registry('current_cms_hierarchy_node');
     if (!$currentNode) {
         return false;
     }
     $nodePathIds = explode('/', $currentNode->getXpath());
     return in_array($cmsNode->getId(), $nodePathIds);
 }
Example #5
0
 /**
  * Retrieve tree meta data flags from secondary table.
  * Filtering by root node of passed node.
  *
  * @param Enterprise_Cms_Model_Hierarchy_Node $object
  * @return array
  */
 public function getTreeMetaData(Enterprise_Cms_Model_Hierarchy_Node $object)
 {
     $read = $this->_getReadAdapter();
     $select = $read->select();
     $xpath = explode('/', $object->getXpath());
     $select->from($this->_metadataTable)->where('node_id = ?', $xpath[0]);
     return $read->fetchRow($select);
 }
Example #6
0
 /**
  * Retrieve Node URL
  *
  * @return string
  */
 public function getHref()
 {
     return $this->_node->getUrl();
 }