Changeset 12995

Show
Ignore:
Timestamp:
10/22/07 19:55:16 (1 year ago)
Author:
w_i
Message:

Added parameter listening functionality

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/fi.protie.navigation/config/manifest.inc

    r11082 r12995  
    11'name' => 'fi.protie.navigation', 
    2 'version' => '1.1.1beta1', 
     2'version' => '1.1.2beta1', 
    33'state' => 'beta', 
    44'purecode' => true, 
     
    2727            'role' => 'lead', 
    2828        ), 
     29        'w_i' => Array 
     30        ( 
     31            'name' => 'Jerry Jalava', 
     32            'email' => 'jerry.jalava@gmail.com', 
     33            'role' => 'developer', 
     34        ), 
    2935    ), 
    3036    'dependencies' => Array 
  • trunk/midcom/fi.protie.navigation/main.php

    r11094 r12995  
    167167    var $component_name_to_class = false; 
    168168     
    169     /** 
     169    /** 
    170170     * Add first and last-class names to list item ul class name 
    171171     *  
     
    246246     */ 
    247247    var $css_active = 'active'; 
     248     
     249    /** 
     250     * parameter listening enabled 
     251     *  
     252     * @access private 
     253     * @var boolean 
     254     */ 
     255    var $_listen_params = false; 
     256     
     257    /** 
     258     * Registered get -parameters for listening 
     259     *  
     260     * @access private 
     261     * @var array 
     262     */ 
     263    var $_get_params = array(); 
     264 
     265    /** 
     266     * Registered post -parameters for listening 
     267     * Not supported yet. 
     268     *  
     269     * @access private 
     270     * @var array 
     271     */ 
     272    var $_post_params = array(); 
     273     
     274    /** 
     275     * Cache for parameters to be listened 
     276     *  
     277     * @access private 
     278     * @var string 
     279     */ 
     280    var $_params_cache = false; 
    248281     
    249282    /** 
     
    262295            $this->root_id = $id; 
    263296        } 
     297    } 
     298     
     299    function listen_parameter($name, $value=false, $type='get') 
     300    { 
     301        if (empty($name)) 
     302        { 
     303            return; 
     304        } 
     305         
     306        $type = strtolower($type); 
     307         
     308        switch($type) 
     309        { 
     310            case 'post': 
     311                if (   isset($this->_post_params[$name]) 
     312                    && $this->_post_params[$name] == $value) 
     313                { 
     314                    return; 
     315                } 
     316                $this->_post_params[$name] = $value; 
     317            break; 
     318            case 'get':             
     319            default: 
     320                if (   isset($this->_get_params[$name]) 
     321                    && $this->_get_params[$name] == $value) 
     322                { 
     323                    return; 
     324                } 
     325                $this->_get_params[$name] = $value; 
     326        } 
     327         
     328        $this->_listen_params = true; 
     329    } 
     330     
     331    function _collect_parameters() 
     332    { 
     333        if (empty($this->_get_params)) 
     334        { 
     335            $this->_params_cache = ''; 
     336            return; 
     337        } 
     338         
     339        $_prefix = '?'; 
     340        $this->_params_cache = ''; 
     341         
     342        foreach ($this->_get_params as $key => $value) 
     343        { 
     344            if (isset($_GET[$key])) 
     345            { 
     346                if ($value) 
     347                { 
     348                    if ($_GET[$key] == $value) 
     349                    { 
     350                        $this->_params_cache .= "{$_prefix}{$key}={$value}"; 
     351                        $_prefix = '&';                         
     352                    } 
     353                } 
     354                elseif (! $_GET[$key]) 
     355                { 
     356                    $this->_params_cache .= "{$_prefix}{$key}"; 
     357                    $_prefix = '&';                     
     358                } 
     359            } 
     360        } 
     361    } 
     362     
     363    function _get_parameter_string() 
     364    { 
     365        if (! $this->_params_cache) 
     366        { 
     367            $this->_collect_parameters(); 
     368        } 
     369         
     370        return $this->_params_cache; 
    264371    } 
    265372     
     
    357464         
    358465        echo "{$indent}<ul class=\"{$this->css_list_style} node-{$id}\"{$element_id}>\n"; 
    359  
     466         
    360467        $item_count = count($children); 
    361468        $item_counter = 0; 
    362  
     469         
    363470        // Draw each child element 
    364471        foreach ($children as $child) 
     
    372479            $first_last = ''; 
    373480            $has_childs = ''; 
    374  
     481             
    375482            if($item_counter == 1 && $item_counter == $item_count) 
    376483            { 
     
    385492                $first_last = $this->css_last; 
    386493            } 
    387  
     494             
    388495            $item = $this->_nap->get_node($child); 
    389496             
     
    495602                    continue; 
    496603                } 
    497                  
     604 
    498605                $item = $this->_nap->get_node($child[MIDCOM_NAV_ID]); 
    499606                 
     
    517624            { 
    518625                $item = $this->_nap->get_leaf($child[MIDCOM_NAV_ID]); 
    519                  
     626 
    520627                // Place the corresponding css class for the currently active leaf) 
    521628                if ($item[MIDCOM_NAV_ID] === $this->_nap->get_current_leaf()) 
     
    539646            $url_name_to_class = ereg_replace('\.|/', '', $item[MIDCOM_NAV_URL]); 
    540647        } 
    541          
    542          
     648 
    543649        $css_class = $selected; 
    544          
     650 
    545651        // Check if the class is active 
    546652        if ($active !== '') 
     
    561667        } 
    562668         
    563         // Check if the first or last is supposed to be drawn 
     669        // Check if the first or last is supposed to be drawn 
    564670        if ($this->first_and_last_to_class && $first_last !== '') 
    565671        { 
     
    573679        } 
    574680         
    575         // Add information about the object's translation status 
    576         if (   isset($item[MIDCOM_NAV_OBJECT]->lang) 
    577             && $item[MIDCOM_NAV_OBJECT]->lang != $_MIDCOM->i18n->get_midgard_language()) 
    578         { 
    579             $css_class .= ' untranslated'; 
    580         } 
    581          
    582681        $css_class = trim($css_class); 
    583682         
     
    592691        } 
    593692         
     693        $get_params = $this->_get_parameter_string(); 
     694         
    594695        echo "{$indent}  <li{$class}>\n"; 
    595         echo "{$indent}    <a href=\"{$item[MIDCOM_NAV_FULLURL]}\">{$item[MIDCOM_NAV_NAME]}</a>\n"; 
     696        echo "{$indent}    <a href=\"{$item[MIDCOM_NAV_FULLURL]}{$get_params}\">{$item[MIDCOM_NAV_NAME]}</a>\n"; 
    596697         
    597698        // If either of the follow nodes switches is on, follow all the nodes