Dotclear

Changeset 804:f10e7e0dffe0 for inc


Ignore:
Timestamp:
03/16/12 09:13:56 (13 years ago)
Author:
Dsls <dsls@…>
Branch:
formfilters
Message:

Tuned formfilters. Added sortby and order to filter form

Location:
inc/admin
Files:
2 edited

Legend:

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

    r783 r804  
    236236                         if ($this->eextra != null) { 
    237237                              $this->eextra->save(); 
    238                               $this->eextra->updateRequestParams($data); 
    239238                         } 
    240239                         http::redirect($this->action.'?'.http_build_query($data,'','&')); 
     
    260259               } 
    261260               if ($load_from_settings) { 
    262                     $get = new ArrayObject($this->loadFilters()); 
    263                     if ($this->eextra != null) { 
    264                          $this->eextra->load(); 
    265                          $this->eextra->updateRequestParams($get); 
    266                     } 
     261                    $get = new ArrayObject(array_merge($this->loadFilters(),$get)); 
    267262               } 
    268263               $this->initializeFromData($this->efilters, $this->eextra, $get); 
    269264               $this->initializeFromData($this->lfilters, $this->lextra, $get); 
     265 
    270266          } 
    271267     } 
  • inc/admin/class.dc.list.php

    r782 r804  
    319319     { 
    320320          if (!is_null($this->sortby) && !is_null($this->order)) { 
    321                foreach ($this->columns as $k => $c) { 
    322                     if ( 
    323                          $this->sortby === $c->getInfo('alias') && 
    324                          in_array($this->order,array('asc','desc')) 
    325                     ) { 
    326                          $params['order'] = $this->sortby.' '.$this->order; 
    327                          break; 
    328                     } 
     321               if ( 
     322                    isset($this->columns[$this->sortby]) && 
     323                    in_array($this->order,array('asc','desc')) 
     324               ) { 
     325                    $params['order'] = $this->columns[$this->sortby]->getInfo('alias').' '.$this->order; 
    329326               } 
    330327          } 
     
    359356           
    360357          $list = array(); 
    361            
     358          $sortby_combo = array(); 
    362359          foreach ($this->columns as $k => $v) { 
    363360               $col_id = $this->form_prefix.$k; 
     
    368365                    array_push($list,$col_html); 
    369366               } 
    370           } 
     367               $sortby_combo[$v->getInfo('title')] = $k; 
     368          } 
     369          $order_combo = array( 
     370                    __('Descending') => 'desc', 
     371                    __('Ascending') => 'asc' 
     372          ); 
    371373           
    372374          $nb_per_page = !is_null($this->nb_per_page) ? $this->nb_per_page : 10; 
     
    376378          '<p><label for="nb_per_page">'.__('Items per page:'). 
    377379          '</label>&nbsp;'.form::field('nb_per_page',3,3,$nb_per_page). 
     380          '</p>'. 
     381          '<p><label for="sortby">'.__('Sort by:'). 
     382          '</label>&nbsp;'.form::combo('sortby',$sortby_combo,$this->sortby). 
     383          '</p>'. 
     384          '<p><label for="order">'.__('Order:'). 
     385          '</label>&nbsp;'.form::combo('order',$order_combo,$this->order). 
    378386          '</p>'; 
    379387     } 
    380388      
    381389     public function updateRequestParams($params) { 
    382           if (!is_null($this->sortby)) { 
    383                $params['sortby'] = $this->sortby; 
     390          if (!is_null($this->sortby) && isset($this->columns[$this->sortby])) { 
     391               $params['sortby'] = $this->columns[$this->sortby]->getInfo('alias'); 
    384392          } 
    385393          if (!is_null($this->order)) { 
     
    562570               $v->setVisibility($visibility); 
    563571          } 
     572          if (!isset($this->columns[$this->sortby])) { 
     573               // No alias found 
     574               $this->sortby=''; 
     575          } 
     576 
    564577     } 
    565578      
     
    604617          $this->sortby = array_key_exists('sortby',$data) ? $data['sortby'] : $this->sortby; 
    605618          $this->order = array_key_exists('order',$data) ? $data['order'] : $this->order; 
    606           $this->nb_per_page = array_key_exists('nb_per_page',$data) ? $data['nb_per_page'] : $this->nb_per_page; 
     619          $this->nb_per_page = array_key_exists('nb_per_page',$data) ? (integer) $data['nb_per_page'] : $this->nb_per_page; 
    607620          # Page 
    608           $this->page = array_key_exists('page',$data) ? $data['page'] : 1; 
     621          $this->page = array_key_exists('page',$data) ? (integer) $data['page'] : 1; 
    609622          if ($load_from_settings) 
    610623               return; 
    611  
    612624          foreach ($this->columns as $k => $v) { 
    613625               $key = $this->form_prefix.$k; 
     
    667679     { 
    668680          $order = 'desc'; 
    669           if (!is_null($this->sortby) && $this->sortby === $c->getInfo('alias')) { 
     681          if (!is_null($this->sortby) && $this->sortby === $c->getInfo('id')) { 
    670682               if (!is_null($this->order) && $this->order === $order) { 
    671683                    $order = 'asc'; 
     
    674686           
    675687          $args = $_GET; 
    676           $args['sortby'] = $c->getInfo('alias'); 
     688          $args['sortby'] = $c->getInfo('id'); 
    677689          $args['order'] = $order; 
    678690           
Note: See TracChangeset for help on using the changeset viewer.

Sites map