Changeset 764:1f013109b32f for inc/admin/class.dc.list.php
- Timestamp:
- 11/14/11 16:09:59 (14 years ago)
- Branch:
- formfilters
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.