Dotclear

Changeset 764:1f013109b32f


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...

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • admin/comments.php

    r756 r764  
    4747 
    4848# - Limit, sortby and order filter 
    49 $params = $comment_list->applyFilters($params); 
    5049 
    5150# Actions combo box 
     
    8079           
    8180$core->callBehavior('adminCommentsFilters',$filterSet); 
     81$filterSet->setExtra($comment_list); 
    8282 
    8383$filterSet->setup($_GET,$_POST); 
     
    105105     $core->error->add($e->getMessage()); 
    106106} 
    107 $filterSet->setExtraData($comment_list->getColumnsForm()); 
    108107 
    109108/* DISPLAY 
     
    150149     form::hidden(array('status'),$status). 
    151150     form::hidden(array('ip'),preg_replace('/%/','%%',$ip)). 
    152      $comment_list->getFormFieldsAsHidden(). 
    153151     '</div>'. 
    154152      
  • admin/posts.php

    r756 r764  
    123123$params = new ArrayObject(); 
    124124$params['no_content'] = true; 
    125  
    126 # - Limit, sortby and order filter 
    127 $params = $post_list->applyFilters($params); 
    128125 
    129126$filterSet = new dcFilterSet('posts','posts.php'); 
     
    152149 
    153150$core->callBehavior('adminPostsFilters',$filterSet); 
     151$filterSet->setExtra($post_list); 
    154152 
    155153$filterSet->setup($_GET,$_POST); 
     
    174172} 
    175173 
    176 $filterSet->setExtraData($post_list->getColumnsForm()); 
    177174 
    178175/* DISPLAY 
     
    191188 
    192189     $filterSet->display(); 
    193  
    194190     # Show posts 
    195191     $post_list->display('<form action="posts_actions.php" method="post" id="form-entries">'. 
     
    204200     '<input type="submit" value="'.__('ok').'" /></p>'. 
    205201     $filterSet->getFormFieldsAsHidden(). 
    206      $post_list->getFormFieldsAsHidden(). 
    207202     $core->formNonce(). 
    208203     '</div>'. 
    209204     '</form>' 
    210205     ); 
    211 } 
     206 
     207      
     208     } 
     209 
    212210 
    213211dcPage::helpBlock('core_posts'); 
  • inc/admin/class.dc.filter.php

    r757 r764  
    1111# -- END LICENSE BLOCK ----------------------------------------- 
    1212 
     13 
     14/** 
     15@ingroup DC_CORE 
     16@nosubgrouping 
     17@brief Interface to add extra data to filterset. 
     18 
     19Note : the instance will be cloned to ensure dual filter edit fields / displayed fields 
     20Be sure to enable correct object cloning then, using the __clone method 
     21*/ 
     22interface dcFilterExtraInterface { 
     23     /** 
     24     Return extra data to display in right column 
     25      
     26     @param    core      <b>dcCore</b>       Dotclear core reference 
     27     @param    form_prefix    <b>string</b>       form prefix to use for parameters 
     28     */ 
     29     public function getFormContent(); 
     30 
     31     /** 
     32     Set dedicated data from form submission  
     33     (either $_GET or $_POST depending on the context 
     34      
     35     @param    data      <b>array</b>        Data to retrieve information from 
     36     */ 
     37     public function initializeFromData($data); 
     38      
     39     /** 
     40     Save data to configuration 
     41     */ 
     42     public function save(); 
     43      
     44     /** 
     45     Load data from configuration 
     46     */ 
     47     public function load(); 
     48           
     49     /** 
     50     Update query parameters with given settings 
     51     @param    params         <b>ArrayObject</b>       Params being sent to query 
     52     */ 
     53     public function applyFilters($params); 
     54      
     55      
     56     /** 
     57     Update parameters that will be used for inter-forms communications 
     58     (either query string or hidden fields). 
     59     The associative has to be updated with $param['key']='value' 
     60     @param    params         <b>ArrayObject</b>       Params to update 
     61     */ 
     62     public function updateRequestParams($params); 
     63} 
     64 
    1365/** 
    1466@ingroup DC_CORE 
     
    2072class dcFilterSet { 
    2173 
    22      protected $lfilters;               /// <b>array</b> lists of defined filters 
    23      protected $efilters;               /// <b>array</b> lists of defined filters 
     74     protected $lfilters;          /// <b>array</b> lists of defined filters 
     75     protected $efilters;          /// <b>array</b> lists of defined filters 
    2476     protected $form_prefix;       /// <b>string</b> displayed form prefix 
    2577     protected $action;            /// <b>string</b> form action page 
    2678     protected $hideform;          /// <b>boolean</b> start form display hidden by default or not 
    27      protected $extra_data;   /// <b>string</b> columns form 
     79     protected $lextra;            /// <b>string</b> columns form 
     80     protected $eextra;            /// <b>string</b> columns form 
    2881     protected $name;              /// <b>string</b> fieldset name 
    2982      
     
    4093          $this->efilters = new ArrayObject(); 
    4194          $this->action = $action; 
    42           $this->extra_data = ''; 
     95          $this->lextra = null; 
     96          $this->eextra = null; 
    4397          $this->filtered = false; 
    4498     } 
     
    63117          $ser = array(); 
    64118          $ws = $GLOBALS['core']->auth->user_prefs->addWorkspace('filters'); 
    65           $data = array(); 
     119          $data = new ArrayObject(); 
    66120          $data= $this->getFiltersAsParams($this->efilters); 
    67121          $ws->put($this->name,serialize($data->getArrayCopy()),'string'); 
     
    87141     @param    form_data <b>array</b>   form values (usually $_GET or $_POST) 
    88142     */ 
    89      protected function initializeFromData ($filters, $form_data) { 
     143     protected function initializeFromData ($filters, $extra, $form_data) { 
    90144          $this->hideform = true; 
    91145          foreach ($filters as $filter) { 
    92146               $filter->initializeFromData ($form_data); 
    93147          } 
     148          if ($extra != null) { 
     149               $extra-> initializeFromData ($form_data); 
     150          } 
    94151     } 
    95152      
     
    99156     @param    html <b>string</b>       the code to add 
    100157     */ 
    101      public function setExtraData($html) 
     158     public function setExtra($extra) 
    102159     { 
    103           $this->extra_data = $html; 
     160          $this->lextra = $extra; 
     161          $this->eextra = clone $extra; 
     162           
    104163     } 
    105164      
     
    111170     public function getFormFieldsAsHidden() { 
    112171          $ret=''; 
    113           foreach ($this->lfilters as $filter) { 
    114                $ret.= $filter->getFormFieldAsHidden(); 
     172          $arr = new ArrayObject(); 
     173          foreach ($this->lfilters as $f) { 
     174               if ($f->isEnabled()) 
     175                    $f->updateRequestParams($arr); 
     176          } 
     177          if ($this->lextra != null) { 
     178               $this->lextra->updateRequestParams($arr); 
     179          } 
     180          foreach ($arr as $k=>$v) { 
     181               $ret.= form::hidden($k,$v); 
    115182          } 
    116183          return $ret; 
     
    149216               // Use case (1) 
    150217               if ($action != 'clear_filters' && $action != 'reset')  { 
    151                     $this->initializeFromData($this->efilters,$post); 
     218                    $this->initializeFromData($this->efilters,$this->eextra, $post); 
    152219                    if ($action == 'add'){ 
    153220                         if (isset($post['add_filter'])  
     
    156223                         } 
    157224                    } elseif (strpos($action,'del_') === 0) { 
    158  
    159225                         $count = preg_match('#del_(.+)_([0-9]+)#',$action,$match); 
    160226                         if (($count == 1) && isset($this->efilters[$match[1]])) { 
     
    163229                    } elseif ($action=="apply") { 
    164230                         $data = $this->saveFilters(); 
     231                         if ($this->eextra != null) { 
     232                              $this->eextra->save(); 
     233                              $this->eextra->updateRequestParams($data); 
     234                         } 
    165235                         http::redirect($this->action.'?'.http_build_query($data,'','&')); 
    166236                         exit; 
     
    169239               if (isset($post[$this->form_prefix."query"])) { 
    170240                    parse_str($post[$this->form_prefix."query"],$out); 
    171                     $this->initializeFromData($this->lfilters,$out); 
     241                    $this->initializeFromData($this->lfilters,$this->lextra, $out); 
    172242                    if ($action == 'reset') { 
    173                          $this->initializeFromData($this->efilters,$out); 
     243                         $this->initializeFromData($this->efilters,$this->eextra, $out); 
    174244                    } 
    175245               } 
     
    178248               // Use case (2) 
    179249               if (count($get)==0) { 
    180                     $get = $this->loadFilters(); 
     250                    $get = new ArrayObject($this->loadFilters()); 
     251                    if ($this->eextra != null) { 
     252                         $this->eextra->load(); 
     253                         $this->eextra->updateRequestParams($get); 
     254                    } 
    181255               } 
    182                $this->initializeFromData($this->efilters, $get); 
    183                $this->initializeFromData($this->lfilters, $get); 
     256               $this->initializeFromData($this->efilters, $this->eextra, $get); 
     257               $this->initializeFromData($this->lfilters, $this->lextra, $get); 
    184258          } 
    185259     } 
     
    231305               $this->form_prefix.'reset" /></p>'. 
    232306               '</div>'; 
    233           if ($this->extra_data != '') { 
     307          if ($this->eextra != '') { 
    234308               $ret .= 
    235309                    '<div class="col30">'. 
    236                     $this->extra_data. 
     310                    $this->eextra->getFormContent(). 
    237311                    '</div>'; 
    238312          } 
     313          $queryParams = $this->getFiltersAsParams($this->lfilters); 
     314          if ($this->lextra != null) { 
     315               $this->lextra->updateRequestParams($queryParams); 
     316          } 
     317           
    239318          $ret .= 
    240319               '<p class="clear margintop">'. 
    241320               '<input type="submit" value="'.__('Apply filters and display options'). 
    242321               '" name="'.$this->form_prefix.'apply" /></p>'. 
    243                form::hidden($this->form_prefix."query",http_build_query($this->getFiltersAsParams($this->lfilters))). 
     322               form::hidden($this->form_prefix."query",http_build_query($queryParams)). 
    244323               $GLOBALS['core']->formNonce(). 
    245324               '</form>'. 
     
    260339          foreach ($filters as $f) { 
    261340               if ($f->isEnabled()) 
    262                     $f->fillQS($arr); 
     341                    $f->updateRequestParams($arr); 
    263342          } 
    264343          return $arr; 
     
    308387                    $this->filtered = true; 
    309388               } 
     389          } 
     390          if ($this->lextra != null) { 
     391               $this->lextra->applyFilters($params); 
    310392          } 
    311393          return $this->filtered; 
     
    461543     } 
    462544      
    463      public function fillQS($arr) { 
     545     public function updateRequestParams($arr) { 
    464546          for ($cur=0; $cur < count($this->values); $cur++) { 
    465547               $arr[$this->getFieldId($cur)]=$this->values[$cur]; 
    466           } 
    467      } 
    468       
    469      /** 
    470      Returns form fields as hidden fields 
    471       
    472      @return   <b>string</b>  the corresponding html code 
    473      */    
    474      public function getFormFieldAsHidden () { 
    475           $ret=''; 
    476           for ($cur=0; $cur < count($this->values); $cur++) { 
    477                $ret .= form::hidden($this->getFieldId($cur), $this->values[$cur]); 
    478548          } 
    479549     } 
     
    586656          return $ret; 
    587657     } 
    588  
    589      public function getFormFieldAsHidden () { 
    590           return parent::getFormFieldAsHidden().form::hidden($this->field_id."_v",$this->verb); 
    591      } 
    592       
    593      public function fillQS($arr) { 
    594           parent::fillQS($arr); 
     658      
     659     public function updateRequestParams($arr) { 
     660          parent::updateRequestParams($arr); 
    595661           
    596662          $arr[$this->field_id.'_v']=$this->verb; 
     
    712778      
    713779} 
     780 
     781 
    714782?> 
  • 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     } 
  • inc/core/class.dc.blog.php

    r756 r764  
    14631463                    if (preg_match('/^null$/i',$id)) { 
    14641464                         $queries[$id] = 'P.cat_id IS NULL'; 
    1465                          if ($not[$id]) { 
     1465                         if (isset($not[$id]) && ($not[$id] == 1)) { 
    14661466                              $nullExcluded = true; 
    14671467                         } 
  • inc/prepend.php

    r756 r764  
    7777$__autoload['textFilter']                    = dirname(__FILE__).'/admin/class.dc.filter.php'; 
    7878$__autoload['comboFilter']                   = dirname(__FILE__).'/admin/class.dc.filter.php'; 
     79$__autoload['dcFilterExtraInterface']                  = dirname(__FILE__).'/admin/class.dc.filter.php'; 
    7980 
    8081$__autoload['dcTemplate']               = dirname(__FILE__).'/public/class.dc.template.php'; 
Note: See TracChangeset for help on using the changeset viewer.

Sites map