Example #1
0
 private function _get_css_classes($child, $item, $item_counter, $item_count)
 {
     $classes = array();
     if ($child[MIDCOM_NAV_TYPE] === 'node') {
         // If the listing of nodes is set to false, skip this item and proceed to the next
         if ($this->list_nodes === false) {
             continue;
         }
         if ($item[MIDCOM_NAV_ID] === $this->_nap->get_current_node() && (!$this->_nap->get_current_leaf() || !$this->_nap->get_leaf($this->_nap->get_current_leaf()))) {
             $classes[] = $this->css_active;
         }
         if (in_array($item[MIDCOM_NAV_ID], $this->node_path, true)) {
             $classes[] = $this->css_selected;
         }
         if ($this->component_name_to_class) {
             $classes[] = str_replace('.', '_', $item[MIDCOM_NAV_COMPONENT]);
         }
     } else {
         // Place the corresponding css class for the currently active leaf)
         if ($item[MIDCOM_NAV_ID] === $this->_nap->get_current_leaf()) {
             $classes[] = $this->css_active;
             $classes[] = $this->css_selected;
         }
     }
     // Check if the URL name is supposed to be drawn
     if ($this->url_name_to_class) {
         $classes[] = str_replace('/', '', $item[MIDCOM_NAV_URL]);
     }
     if ($this->first_and_last_to_class) {
         if ($item_count == 1) {
             $classes[] = $this->css_first_last;
         } else {
             if ($item_counter == 1) {
                 $classes[] = $this->css_first;
             } else {
                 if ($item_counter == $item_count) {
                     $classes[] = $this->css_last;
                 }
             }
         }
     }
     if ($this->has_children_to_class) {
         if (!$this->list_leaves) {
             $children = $this->_nap->list_nodes($child[MIDCOM_NAV_ID]);
         } else {
             $children = $this->_nap->list_child_elements($child[MIDCOM_NAV_ID]);
         }
         if (is_array($children) && count($children) > 0) {
             $classes[] = $this->css_has_children;
         }
     }
     // Add information about the object's status
     if ($this->object_status_to_class && isset($item[MIDCOM_NAV_OBJECT]) && ($css_status_class = midcom::get('metadata')->get_object_classes($item[MIDCOM_NAV_OBJECT]))) {
         $classes[] = $css_status_class;
     }
     return implode(' ', $classes);
 }
Example #2
0
 private function _get_navigation_data()
 {
     $ret = array();
     // Initialize the midcom_helper_nav or navigation access point
     $nap = new midcom_helper_nav();
     switch ((int) $this->_topic->get_parameter('midcom.helper.nav', 'navorder')) {
         case MIDCOM_NAVORDER_DEFAULT:
             $ret['nodes'] = array();
             $nodes = $nap->list_nodes($nap->get_current_node());
             foreach ($nodes as $id => $node_id) {
                 $node = $nap->get_node($node_id);
                 $node[MIDCOM_NAV_TYPE] = 'node';
                 $ret['nodes'][$id] = $node;
             }
             break;
         case MIDCOM_NAVORDER_TOPICSFIRST:
             // Sort the array to have the nodes first
             $ret = array('nodes' => array(), 'leaves' => array());
             // Fall through
         // Fall through
         case MIDCOM_NAVORDER_ARTICLESFIRST:
             // Sort the array to have the leaves first
             if (!isset($ret['leaves'])) {
                 $ret = array('leaves' => array(), 'nodes' => array());
             }
             // Get the nodes
             $nodes = $nap->list_nodes($nap->get_current_node());
             foreach ($nodes as $id => $node_id) {
                 $node = $nap->get_node($node_id);
                 $node[MIDCOM_NAV_TYPE] = 'node';
                 $ret['nodes'][$id] = $node;
             }
             // Get the leafs
             $leaves = $nap->list_leaves($nap->get_current_node());
             foreach ($leaves as $id => $leaf_id) {
                 $leaf = $nap->get_leaf($leaf_id);
                 $leaf[MIDCOM_NAV_TYPE] = 'leaf';
                 $ret['leaves'][$id] = $leaf;
             }
             break;
         case MIDCOM_NAVORDER_SCORE:
         default:
             $ret['mixed'] = array();
             // Get the navigation items
             $items = $nap->list_child_elements($nap->get_current_node());
             foreach ($items as $id => $item) {
                 if ($item[MIDCOM_NAV_TYPE] === 'node') {
                     $element = $nap->get_node($item[MIDCOM_NAV_ID]);
                 } else {
                     $element = $nap->get_leaf($item[MIDCOM_NAV_ID]);
                 }
                 // Store the type information
                 $element[MIDCOM_NAV_TYPE] = $item[MIDCOM_NAV_TYPE];
                 $ret['mixed'][] = $element;
             }
             break;
     }
     return $ret;
 }