Dotclear


Ignore:
Timestamp:
11/14/11 16:09:59 (14 years ago)
Author:
Dsls <dsls@…>
Branch:
formfilters
Message:

Next step in formfilters : columns now work, sorting still broken...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/admin/class.dc.list.php

    r521 r764  
    259259Dotclear items list handles administration lists 
    260260*/ 
    261 abstract class adminItemsList 
     261abstract class adminItemsList implements dcFilterExtraInterface 
    262262{ 
    263263     protected $core; 
     
    285285          $this->core = $core; 
    286286          $this->context = get_class($this); 
    287           $this->columns = array(); 
     287          $this->columns = new ArrayObject(); 
    288288          $this->form_prefix = 'col_%s'; 
    289           $this->form_trigger = 'add_filter'; 
    290289           
    291290          $this->html_prev = __('prev'); 
     
    294293          $this->html_end = __('end'); 
    295294           
    296           $this->setOptions(); 
     295          $this->nb_per_page = 10; 
    297296           
    298297          $this->setColumns(); 
     
    301300          $core->callBehavior('adminItemsListConstruct',$this); 
    302301           
    303           $this->setColumnsVisibility(); 
    304      } 
    305       
     302     } 
     303      
     304     public function __clone() { 
     305          $arr = new ArrayObject(); 
     306          foreach ($this->columns as $k=>$v) { 
     307               $arr[$k]= clone $v; 
     308          } 
     309          $this->columns = $arr; 
     310     } 
    306311     /** 
    307312     Apply limit, sortby and order filters to items parameters 
     
    347352     @return   <b>string</b>       HTML code form 
    348353     */ 
    349      public function getColumnsForm() 
     354     public function getFormContent() 
    350355     { 
    351356          $block =  
     
    372377          '</label>&nbsp;'.form::field('nb_per_page',3,3,$nb_per_page). 
    373378          '</p>'; 
     379     } 
     380      
     381     public function updateRequestParams($params) { 
     382          if (!is_null($this->sortby)) { 
     383               $params['sortby'] = $this->sortby; 
     384          } 
     385          if (!is_null($this->order)) { 
     386               $params['order'] = $this->order; 
     387          } 
     388          if (!is_null($this->nb_per_page)) { 
     389               $params['nb_per_page'] = $this->nb_per_page; 
     390          } 
     391          if (!is_null($this->page)) { 
     392               $params['page'] = $this->page; 
     393          } 
     394          foreach ($this->columns as $k => $v) { 
     395               if($v->isVisible()) 
     396                    $params[sprintf($this->form_prefix,$k)] = 1; 
     397          } 
     398 
    374399     } 
    375400      
     
    514539      
    515540     /** 
    516      Returns default HTMl code line 
     541     Returns default HTML code line 
    517542      
    518543     @return   <b>string</b>       Default HTMl code line 
     
    524549      
    525550     /** 
    526      Sets options of defined list 
    527      */ 
    528      private function setOptions() 
    529      { 
    530           $opts = $_GET; 
    531            
     551     Loads list from user settings 
     552     */ 
     553     public function load() { 
    532554          $ws = $this->core->auth->user_prefs->addWorkspace('lists'); 
    533            
    534555          $user_pref = !is_null($ws->{$this->context.'_opts'}) ? unserialize($ws->{$this->context.'_opts'}) : array(); 
    535           # Sortby 
    536556          $this->sortby = array_key_exists('sortby',$user_pref) ? $user_pref['sortby'] : null; 
    537           $this->sortby = array_key_exists('sortby',$opts) ? $opts['sortby'] : $this->sortby; 
    538           $user_pref['sortby'] = $this->sortby; 
    539           # Order 
    540557          $this->order = array_key_exists('order',$user_pref) ? $user_pref['order'] : null; 
    541           $this->order = array_key_exists('order',$opts) ? $opts['order'] : $this->order; 
    542           $user_pref['order'] = $this->order; 
    543           # Number per page 
    544558          $this->nb_per_page = array_key_exists('nb_per_page',$user_pref) ? $user_pref['nb_per_page'] : 10; 
    545           $this->nb_per_page = array_key_exists('nb_per_page',$opts) ? $opts['nb_per_page'] : $this->nb_per_page; 
    546           $user_pref['nb_per_page'] = $this->nb_per_page; 
    547            
    548           if (array_key_exists('sortby',$opts) || array_key_exists('order',$opts) || array_key_exists('nb_per_page',$opts)) { 
    549                $this->core->auth->user_prefs->lists->put($this->context.'_opts',serialize($user_pref),'string'); 
    550           } 
    551            
    552           # Page 
    553           $this->page = array_key_exists('page',$opts) ? $opts['page'] : 1; 
    554      } 
    555       
    556      /** 
    557      Sets columns visibility of defined list 
    558      */ 
    559      private function setColumnsVisibility() 
    560      { 
    561           $opts = $_GET; 
    562            
    563           # Visibility 
    564           $ws = $this->core->auth->user_prefs->addWorkspace('lists'); 
    565            
    566559          $user_pref = !is_null($ws->{$this->context.'_col'}) ? unserialize($ws->{$this->context.'_col'}) : array(); 
    567            
    568560          foreach ($this->columns as $k => $v) { 
    569561               $visibility =  array_key_exists($k,$user_pref) ? $user_pref[$k] : true; 
    570                if (array_key_exists($this->form_trigger,$opts)) { 
    571                     $key = sprintf($this->form_prefix,$k); 
    572                     $visibility = !array_key_exists($key,$opts) ? false : true; 
    573                } 
    574562               $v->setVisibility($visibility); 
    575                $user_pref[$k] = $visibility; 
    576           } 
    577            
    578           if (array_key_exists($this->form_trigger,$opts)) { 
    579                $this->core->auth->user_prefs->lists->put($this->context.'_col',serialize($user_pref),'string'); 
     563          } 
     564     } 
     565      
     566     /** 
     567     Saves list to user settings 
     568     */ 
     569     public function save() { 
     570          $ws = $this->core->auth->user_prefs->addWorkspace('lists'); 
     571          $user_pref = !is_null($ws->{$this->context.'_opts'}) ? unserialize($ws->{$this->context.'_opts'}) : array(); 
     572          $user_pref['order'] = $this->order; 
     573          $user_pref['nb_per_page'] = $this->nb_per_page; 
     574          $user_pref['sortby'] = $this->sortby; 
     575           
     576          $this->core->auth->user_prefs->lists->put($this->context.'_opts',serialize($user_pref),'string'); 
     577           
     578          $user_pref = !is_null($ws->{$this->context.'_col'}) ? unserialize($ws->{$this->context.'_col'}) : array(); 
     579           
     580          foreach ($this->columns as $k => $v) { 
     581               $user_pref[$k] = $v->isVisible(); 
     582          } 
     583          $this->core->auth->user_prefs->lists->put($this->context.'_col',serialize($user_pref),'string'); 
     584     } 
     585      
     586     /** 
     587     Set dedicated data from form submission  
     588     (either $_GET or $_POST depending on the context 
     589      
     590     @param    data      <b>array</b>        Data to retrieve information from 
     591     */ 
     592     public function initializeFromData ($data) 
     593     { 
     594          # Sortby 
     595          $this->sortby = array_key_exists('sortby',$data) ? $data['sortby'] : $this->sortby; 
     596          $this->order = array_key_exists('order',$data) ? $data['order'] : $this->order; 
     597          $this->nb_per_page = array_key_exists('nb_per_page',$data) ? $data['nb_per_page'] : $this->nb_per_page; 
     598           
     599          # Page 
     600          $this->page = array_key_exists('page',$data) ? $data['page'] : 1; 
     601          foreach ($this->columns as $k => $v) { 
     602               $key = sprintf($this->form_prefix,$k); 
     603               $visibility = !array_key_exists($key,$data) ? false : true; 
     604               $v->setVisibility($visibility); 
    580605          } 
    581606     } 
Note: See TracChangeset for help on using the changeset viewer.

Sites map