Changeset 1008

Show
Ignore:
Timestamp:
07/09/08 10:40:21 (2 months ago)
Author:
bibo
Message:

#561 : make history behaves like a FIFO

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/jelix/plugins/coord/history/history.coord.php

    r902 r1008  
    11<?php 
    22/** 
    3 * @package    jelix 
    4 * @subpackage coord_plugin 
    5 * @author     Lepeltier Kévin 
    6 * @copyright  2008 Lepeltier Kévin 
     3* @package      jelix 
     4* @subpackage   coord_plugin 
     5* @author       Lepeltier Kévin 
     6* @contributor  Dominique Papin 
     7* @copyright  2008 Lepeltier Kévin, 2008 Dominique Papin 
    78* 
    89* The plugin History is a plugin coord, 
     
    1213*/ 
    1314class historyCoordPlugin implements jICoordPlugin { 
    14      
     15 
    1516    public $config; 
    16      
     17 
    1718    function __construct( $conf ){ 
    1819        $this->config = $conf; 
    19          
     20 
    2021        if( $this->config['time'] && !isset($_SESSION[$this->config['session_time_name']]) ) 
    2122            $_SESSION[$this->config['session_time_name']] = microtime(true); 
    22          
     23 
    2324    } 
    24      
     25 
    2526    public function beforeAction ($params) { 
    26          
     27 
    2728        if( !empty($params['history.add']) && $params['history.add'] ) { 
    2829            if( !isset($_SESSION[$this->config['session_name']]) ) 
    2930                $_SESSION[$this->config['session_name']] = array(); 
    30              
     31 
    3132            global $gJCoord; 
    3233            $page['params'] = $gJCoord->request->params; 
    3334            unset( $page['params']['module'] ); 
    3435            unset( $page['params']['action'] ); 
    35              
     36 
    3637            $page['action'] = $gJCoord->action->toString(); 
    3738            $page['label'] = ( !empty($params['history.label']) )? $params['history.label']:''; 
    3839            $page['title'] = ( !empty($params['history.title']) )? $params['history.title']:''; 
    39              
     40 
    4041            if( !count($_SESSION[$this->config['session_name']]) ) { 
    4142                $_SESSION[$this->config['session_name']][] = $page; 
    42             } else if( count($_SESSION[$this->config['session_name']]) < $this->config['maxsize'] && ( $this->config['double'] || end($_SESSION[$this->config['session_name']]) != $page ) ) { 
    43                 if( $this->config['single'] ) 
     43            } else if ( $this->config['double'] || !$this->isLast( $page['action'], $page['params'] ) ) { 
     44                if( $this->config['single'] ) { 
    4445                    foreach( $_SESSION[$this->config['session_name']] as $key=>$valu ) if( $valu == $page ) 
    4546                        array_splice( $_SESSION[$this->config['session_name']], $key, 1 ); 
     47                } 
    4648                $_SESSION[$this->config['session_name']][] = $page; 
    4749            } 
    48              
     50 
     51            if( count($_SESSION[$this->config['session_name']]) > $this->config['maxsize'] ) { 
     52                array_shift( $_SESSION[$this->config['session_name']] ); 
     53            } 
    4954        } 
    50          
     55 
    5156    } 
    52      
     57 
     58    public function isLast($action, $params = NULL) { 
     59 
     60        if (!isset($_SESSION[$this->config['session_name']])) 
     61            return false ; 
     62 
     63        $lastPage = end($_SESSION[$this->config['session_name']]); 
     64        $isLast = $action == $lastPage['action']; 
     65        if ( $params !== NULL ) { 
     66            $isLast = $isLast && $params == $lastPage['params']; 
     67        } 
     68        return $isLast; 
     69    } 
     70 
     71 
    5372    public function change( $key, $val ) { 
    54          
     73 
    5574        $page = array_pop($_SESSION[$this->config['session_name']]); 
    5675        $page[$key] = $val; 
    57          
     76 
    5877        if( $this->config['double'] || end($_SESSION[$this->config['session_name']]) != $page ) { 
    5978            if( $this->config['single'] ) 
    60                 foreach( $_SESSION[$this->config['session_name']] as $key=>$valu ) if( $valu == $page ) 
     79                foreach( $_SESSION[$this->config['session_name']] as $key=>$value ) if( $value == $page ) 
    6180                    array_splice( $_SESSION[$this->config['session_name']], $key, 1 ); 
    6281            $_SESSION[$this->config['session_name']][] = $page; 
    6382        } 
    64          
     83 
    6584    } 
    66      
     85 
    6786    public function beforeOutput(){} 
    68      
     87 
    6988    public function afterProcess (){} 
    70      
     89 
    7190    public function reload( $rep ) { 
    7291        $last = end($_SESSION[$this->config['session_name']]); 
     
    7594        return $rep; 
    7695    } 
    77      
     96 
    7897    public function back( $rep ) { 
    7998        array_pop($_SESSION[$this->config['session_name']]); 
     
    83102        return $rep; 
    84103    } 
    85      
     104 
    86105    public function time() { 
    87106        if( $this->config['time'] && isset($_SESSION[$this->config['session_time_name']]) ) 
     
    89108        return 0; 
    90109    } 
    91      
     110 
    92111} 
    93112 
Download in other formats: Unified Diff Zip Archive