Development

Changeset 20509

You must first sign up to be able to contribute.

Changeset 20509

Show
Ignore:
Timestamp:
07/26/09 23:30:50 (4 years ago)
Author:
henrik
Message:

Added the new matching system removed some comments, just need to write some new documentation and then post a new pear release

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfTabMenuPeytzPlugin/lib/sfTabMenuPeytz.class.php

    r20508 r20509  
    4545        'security' => array( 
    4646            'is_secure' => false, 
    47             'credentials' => array() 
    48             /* 
    49                 This is run before anything else, and will determaine if the user got access to this, if u set a permission the 
    50                 is_secure it not needed since the user will be check for authenticated before checking for is_secure. 
    51             */ 
     47            'credentials' => array(), 
    5248        ), 
    53         'matches' => array( //Must match one of these 
    54             'module/action?get=asdad&get=sadasd', 
    55             /* 
    56                 Written in the same syntax as routes, if a parameter has a value specified, that value will be check 
    57                 else it will just verify that the parameter is availible by sfWebRequest. 
    58                 This makes a tab able to match different things. the match with highest score for that tab 
    59                 will be used in the overall score matching. 
    60             */ 
    61         ), 
     49        'matches' => array(), 
    6250        'match' => array( 
    6351            'module' => null, 
     
    163151        //Render the active tab 
    164152        $this->renderTab($this->_ActiveTabIndex, true); 
    165          
    166         //Now we have the items renderer lets find the active one, if none found the $default wins 
    167          
    168153         
    169154        //Render the ul and decorator 
     
    177162     
    178163    /** 
     164     * Handles parsing of our Route like matchings 
     165     * 
     166     * @param string $match  
     167     * @return array 
     168     */ 
     169    private function parseMatch($match) 
     170    { 
     171        $parseArray = array( 
     172            'module' => null, 
     173            'action' => null, 
     174            'parameters' => array(), 
     175        ); 
     176         
     177        $parse = parse_url($match); 
     178        $query = array(); 
     179        if (isset($parse['query'])) { 
     180            parse_str($parse['query'], $parseArray['parameters']); 
     181        } 
     182         
     183        $moduleAction = array_filter(explode('/', $parse['path'])); 
     184        if (isset($moduleAction[0])) { 
     185            $parseArray['module'] = $moduleAction[0]; 
     186             
     187            $parseArray['action'] = 'index'; 
     188            if (isset($moduleAction[1])) { 
     189                $parseArray['action'] = $moduleAction[1]; 
     190            } 
     191        } 
     192         
     193        return $parseArray; 
     194    } 
     195     
     196    /** 
    179197     * Calculates the scores 
    180198     */ 
     
    196214            $scores[$key] = 0; 
    197215            $tab = self::merge($this->_DefaultTabConfig, $tab); 
    198             $match = $tab['match']; 
     216            $matches = $tab['matches']; 
    199217             
    200             //Lets make score 
    201             $modules = is_array($match['module']) ? $match['module'] : array($match['module']); 
    202             $actions = is_array($match['action']) ? $match['action'] : array($match['action']); 
    203              
    204             if (in_array($module, $modules)) { 
    205                 $scores[$key]++; 
     218            foreach ($matches as $match) { 
     219                $score = 0; 
     220                $match = $this->parseMatch($match);; 
    206221                 
    207                 if (in_array($action, $actions)) { 
    208                     $scores[$key]++; 
     222                if ($module == $match['module']) { 
     223                    $score++; 
    209224                     
    210                     foreach ($match['params'] as $param) { 
    211                         if (isset($parameters[$param])) { 
    212                             $scores[$key]++; 
     225                    if ($action == $match['action']) { 
     226                        $score++; 
     227                         
     228                        foreach ($match['parameters'] as $name => $value) { 
     229                            if (!empty($value)) { 
     230                                if ($request->getParameter($name) == $value) { 
     231                                    $score++; 
     232                                } elseif ($request->hasParameter($name)) { 
     233                                    $score++; 
     234                                } 
     235                            } 
    213236                        } 
    214237                    } 
     238                } 
     239                 
     240                if ($score > $scores[$key]) { 
     241                    $scores[$key] = $score; 
    215242                } 
    216243            }