Changeset 764:1f013109b32f
- Timestamp:
- 11/14/11 16:09:59 (14 years ago)
- Branch:
- formfilters
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/comments.php
r756 r764 47 47 48 48 # - Limit, sortby and order filter 49 $params = $comment_list->applyFilters($params);50 49 51 50 # Actions combo box … … 80 79 81 80 $core->callBehavior('adminCommentsFilters',$filterSet); 81 $filterSet->setExtra($comment_list); 82 82 83 83 $filterSet->setup($_GET,$_POST); … … 105 105 $core->error->add($e->getMessage()); 106 106 } 107 $filterSet->setExtraData($comment_list->getColumnsForm());108 107 109 108 /* DISPLAY … … 150 149 form::hidden(array('status'),$status). 151 150 form::hidden(array('ip'),preg_replace('/%/','%%',$ip)). 152 $comment_list->getFormFieldsAsHidden().153 151 '</div>'. 154 152 -
admin/posts.php
r756 r764 123 123 $params = new ArrayObject(); 124 124 $params['no_content'] = true; 125 126 # - Limit, sortby and order filter127 $params = $post_list->applyFilters($params);128 125 129 126 $filterSet = new dcFilterSet('posts','posts.php'); … … 152 149 153 150 $core->callBehavior('adminPostsFilters',$filterSet); 151 $filterSet->setExtra($post_list); 154 152 155 153 $filterSet->setup($_GET,$_POST); … … 174 172 } 175 173 176 $filterSet->setExtraData($post_list->getColumnsForm());177 174 178 175 /* DISPLAY … … 191 188 192 189 $filterSet->display(); 193 194 190 # Show posts 195 191 $post_list->display('<form action="posts_actions.php" method="post" id="form-entries">'. … … 204 200 '<input type="submit" value="'.__('ok').'" /></p>'. 205 201 $filterSet->getFormFieldsAsHidden(). 206 $post_list->getFormFieldsAsHidden().207 202 $core->formNonce(). 208 203 '</div>'. 209 204 '</form>' 210 205 ); 211 } 206 207 208 } 209 212 210 213 211 dcPage::helpBlock('core_posts'); -
inc/admin/class.dc.filter.php
r757 r764 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 12 13 14 /** 15 @ingroup DC_CORE 16 @nosubgrouping 17 @brief Interface to add extra data to filterset. 18 19 Note : the instance will be cloned to ensure dual filter edit fields / displayed fields 20 Be sure to enable correct object cloning then, using the __clone method 21 */ 22 interface 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 13 65 /** 14 66 @ingroup DC_CORE … … 20 72 class dcFilterSet { 21 73 22 protected $lfilters; 23 protected $efilters; 74 protected $lfilters; /// <b>array</b> lists of defined filters 75 protected $efilters; /// <b>array</b> lists of defined filters 24 76 protected $form_prefix; /// <b>string</b> displayed form prefix 25 77 protected $action; /// <b>string</b> form action page 26 78 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 28 81 protected $name; /// <b>string</b> fieldset name 29 82 … … 40 93 $this->efilters = new ArrayObject(); 41 94 $this->action = $action; 42 $this->extra_data = ''; 95 $this->lextra = null; 96 $this->eextra = null; 43 97 $this->filtered = false; 44 98 } … … 63 117 $ser = array(); 64 118 $ws = $GLOBALS['core']->auth->user_prefs->addWorkspace('filters'); 65 $data = array();119 $data = new ArrayObject(); 66 120 $data= $this->getFiltersAsParams($this->efilters); 67 121 $ws->put($this->name,serialize($data->getArrayCopy()),'string'); … … 87 141 @param form_data <b>array</b> form values (usually $_GET or $_POST) 88 142 */ 89 protected function initializeFromData ($filters, $ form_data) {143 protected function initializeFromData ($filters, $extra, $form_data) { 90 144 $this->hideform = true; 91 145 foreach ($filters as $filter) { 92 146 $filter->initializeFromData ($form_data); 93 147 } 148 if ($extra != null) { 149 $extra-> initializeFromData ($form_data); 150 } 94 151 } 95 152 … … 99 156 @param html <b>string</b> the code to add 100 157 */ 101 public function setExtra Data($html)158 public function setExtra($extra) 102 159 { 103 $this->extra_data = $html; 160 $this->lextra = $extra; 161 $this->eextra = clone $extra; 162 104 163 } 105 164 … … 111 170 public function getFormFieldsAsHidden() { 112 171 $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); 115 182 } 116 183 return $ret; … … 149 216 // Use case (1) 150 217 if ($action != 'clear_filters' && $action != 'reset') { 151 $this->initializeFromData($this->efilters,$ post);218 $this->initializeFromData($this->efilters,$this->eextra, $post); 152 219 if ($action == 'add'){ 153 220 if (isset($post['add_filter']) … … 156 223 } 157 224 } elseif (strpos($action,'del_') === 0) { 158 159 225 $count = preg_match('#del_(.+)_([0-9]+)#',$action,$match); 160 226 if (($count == 1) && isset($this->efilters[$match[1]])) { … … 163 229 } elseif ($action=="apply") { 164 230 $data = $this->saveFilters(); 231 if ($this->eextra != null) { 232 $this->eextra->save(); 233 $this->eextra->updateRequestParams($data); 234 } 165 235 http::redirect($this->action.'?'.http_build_query($data,'','&')); 166 236 exit; … … 169 239 if (isset($post[$this->form_prefix."query"])) { 170 240 parse_str($post[$this->form_prefix."query"],$out); 171 $this->initializeFromData($this->lfilters,$ out);241 $this->initializeFromData($this->lfilters,$this->lextra, $out); 172 242 if ($action == 'reset') { 173 $this->initializeFromData($this->efilters,$ out);243 $this->initializeFromData($this->efilters,$this->eextra, $out); 174 244 } 175 245 } … … 178 248 // Use case (2) 179 249 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 } 181 255 } 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); 184 258 } 185 259 } … … 231 305 $this->form_prefix.'reset" /></p>'. 232 306 '</div>'; 233 if ($this->e xtra_data != '') {307 if ($this->eextra != '') { 234 308 $ret .= 235 309 '<div class="col30">'. 236 $this->e xtra_data.310 $this->eextra->getFormContent(). 237 311 '</div>'; 238 312 } 313 $queryParams = $this->getFiltersAsParams($this->lfilters); 314 if ($this->lextra != null) { 315 $this->lextra->updateRequestParams($queryParams); 316 } 317 239 318 $ret .= 240 319 '<p class="clear margintop">'. 241 320 '<input type="submit" value="'.__('Apply filters and display options'). 242 321 '" 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)). 244 323 $GLOBALS['core']->formNonce(). 245 324 '</form>'. … … 260 339 foreach ($filters as $f) { 261 340 if ($f->isEnabled()) 262 $f-> fillQS($arr);341 $f->updateRequestParams($arr); 263 342 } 264 343 return $arr; … … 308 387 $this->filtered = true; 309 388 } 389 } 390 if ($this->lextra != null) { 391 $this->lextra->applyFilters($params); 310 392 } 311 393 return $this->filtered; … … 461 543 } 462 544 463 public function fillQS($arr) {545 public function updateRequestParams($arr) { 464 546 for ($cur=0; $cur < count($this->values); $cur++) { 465 547 $arr[$this->getFieldId($cur)]=$this->values[$cur]; 466 }467 }468 469 /**470 Returns form fields as hidden fields471 472 @return <b>string</b> the corresponding html code473 */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]);478 548 } 479 549 } … … 586 656 return $ret; 587 657 } 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); 595 661 596 662 $arr[$this->field_id.'_v']=$this->verb; … … 712 778 713 779 } 780 781 714 782 ?> -
inc/admin/class.dc.list.php
r521 r764 259 259 Dotclear items list handles administration lists 260 260 */ 261 abstract class adminItemsList 261 abstract class adminItemsList implements dcFilterExtraInterface 262 262 { 263 263 protected $core; … … 285 285 $this->core = $core; 286 286 $this->context = get_class($this); 287 $this->columns = array();287 $this->columns = new ArrayObject(); 288 288 $this->form_prefix = 'col_%s'; 289 $this->form_trigger = 'add_filter';290 289 291 290 $this->html_prev = __('prev'); … … 294 293 $this->html_end = __('end'); 295 294 296 $this-> setOptions();295 $this->nb_per_page = 10; 297 296 298 297 $this->setColumns(); … … 301 300 $core->callBehavior('adminItemsListConstruct',$this); 302 301 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 } 306 311 /** 307 312 Apply limit, sortby and order filters to items parameters … … 347 352 @return <b>string</b> HTML code form 348 353 */ 349 public function get ColumnsForm()354 public function getFormContent() 350 355 { 351 356 $block = … … 372 377 '</label> '.form::field('nb_per_page',3,3,$nb_per_page). 373 378 '</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 374 399 } 375 400 … … 514 539 515 540 /** 516 Returns default HTM lcode line541 Returns default HTML code line 517 542 518 543 @return <b>string</b> Default HTMl code line … … 524 549 525 550 /** 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() { 532 554 $ws = $this->core->auth->user_prefs->addWorkspace('lists'); 533 534 555 $user_pref = !is_null($ws->{$this->context.'_opts'}) ? unserialize($ws->{$this->context.'_opts'}) : array(); 535 # Sortby536 556 $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 # Order540 557 $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 page544 558 $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 # Page553 $this->page = array_key_exists('page',$opts) ? $opts['page'] : 1;554 }555 556 /**557 Sets columns visibility of defined list558 */559 private function setColumnsVisibility()560 {561 $opts = $_GET;562 563 # Visibility564 $ws = $this->core->auth->user_prefs->addWorkspace('lists');565 566 559 $user_pref = !is_null($ws->{$this->context.'_col'}) ? unserialize($ws->{$this->context.'_col'}) : array(); 567 568 560 foreach ($this->columns as $k => $v) { 569 561 $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 }574 562 $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); 580 605 } 581 606 } -
inc/core/class.dc.blog.php
r756 r764 1463 1463 if (preg_match('/^null$/i',$id)) { 1464 1464 $queries[$id] = 'P.cat_id IS NULL'; 1465 if ( $not[$id]) {1465 if (isset($not[$id]) && ($not[$id] == 1)) { 1466 1466 $nullExcluded = true; 1467 1467 } -
inc/prepend.php
r756 r764 77 77 $__autoload['textFilter'] = dirname(__FILE__).'/admin/class.dc.filter.php'; 78 78 $__autoload['comboFilter'] = dirname(__FILE__).'/admin/class.dc.filter.php'; 79 $__autoload['dcFilterExtraInterface'] = dirname(__FILE__).'/admin/class.dc.filter.php'; 79 80 80 81 $__autoload['dcTemplate'] = dirname(__FILE__).'/public/class.dc.template.php';
Note: See TracChangeset
for help on using the changeset viewer.