Changeset 519:c508ff281bad
- Timestamp:
- 07/06/11 13:19:41 (14 years ago)
- Branch:
- formfilters
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/admin/lib.pager.php
r508 r519 15 15 @ingroup DC_CORE 16 16 @nosubgrouping 17 @brief Dotclear Pager class.18 19 Dotclear Pager handles pagination for every admin list.17 @brief Dotclear items pager class. 18 19 Dotclear items pager handles pagination for every admin list. 20 20 */ 21 class dcPager extends pager21 class adminItemsPager extends pager 22 22 { 23 23 public function getLinks() … … 56 56 # End 57 57 if($this->env != $this->nb_pages) { 58 $htmlEnd = '<a href="'.sprintf($this->page_url,$this->nb_ elements).'" class="end">'.58 $htmlEnd = '<a href="'.sprintf($this->page_url,$this->nb_pages).'" class="end">'. 59 59 $htmlEnd .= $this->html_end.'</a>'; 60 60 } … … 92 92 @ingroup DC_CORE 93 93 @nosubgrouping 94 @brief Dotclear Genericcolumn class.95 96 Dotclear Generic column handles each column object use in adminGenericList class.94 @brief Dotclear items column class. 95 96 Dotclear items column handles each column object use in adminItemsList class. 97 97 */ 98 class admin GenericColumn98 class adminItemsColumn 99 99 { 100 100 protected $core; /// <b>object</b> dcCore object … … 157 157 158 158 while (!$p) { 159 if ($p->name == 'admin GenericList') {159 if ($p->name == 'adminItemsList') { 160 160 $find_parent = true; 161 161 } … … 166 166 167 167 if (!$p || !$f) { 168 throw new Exception(__('Callback class should be inherited of admin GenericList class'));168 throw new Exception(__('Callback class should be inherited of adminItemsList class')); 169 169 } 170 170 } … … 255 255 @ingroup DC_CORE 256 256 @nosubgrouping 257 @brief abstract Genericlist class.258 259 Dotclear Genericlist handles administration lists257 @brief abstract items list class. 258 259 Dotclear items list handles administration lists 260 260 */ 261 abstract class admin GenericList261 abstract class adminItemsList 262 262 { 263 263 protected $core; … … 265 265 protected $rs_count; 266 266 protected $columns; 267 protected $sortby; 268 protected $order; 269 protected $nb_per_page; 270 protected $page; 267 271 268 272 /* 269 273 Sets columns of defined list 270 274 */ 271 public function setColumns() {}275 abstract function setColumns(); 272 276 273 277 /** … … 275 279 276 280 @param core <b>dcCore</b> dcCore object 277 @param rs <b>recordSet</b> Items recordSet to display 278 @param rs_count <b>int</b> Total items number 279 */ 280 public function __construct($core,$rs,$rs_count) 281 { 282 $this->core =& $core; 283 $this->rs =& $rs; 284 $this->rs_count = $rs_count; 281 */ 282 public function __construct($core) 283 { 284 285 $this->core = $core; 285 286 $this->context = get_class($this); 286 287 $this->columns = array(); … … 293 294 $this->html_end = __('end'); 294 295 296 $this->setOptions(); 297 295 298 $this->setColumns(); 296 299 297 $core->callBehavior('adminListConstruct',$this); 300 # --BEHAVIOR-- adminItemsListConstruct 301 $core->callBehavior('adminItemsListConstruct',$this); 298 302 299 303 $this->setColumnsVisibility(); 304 } 305 306 /** 307 Apply limit, sortby and order filters to items parameters 308 309 @param params <b>array</b> Items parameters 310 311 @return <b>array</b> Items parameters 312 */ 313 public function applyFilters($params) 314 { 315 if (!is_null($this->sortby) && !is_null($this->order)) { 316 foreach ($this->columns as $k => $c) { 317 if ( 318 $this->sortby === $c->getInfo('alias') && 319 in_array($this->order,array('asc','desc')) 320 ) { 321 $params['order'] = $this->sortby.' '.$this->order; 322 break; 323 } 324 } 325 } 326 327 $params['limit'] = array((($this->page-1)*$this->nb_per_page),$this->nb_per_page); 328 329 return $params; 330 } 331 332 /** 333 Sets items and items counter 334 335 @param rs <b>recordSet</b> Items recordSet to display 336 @param rs_count <b>int</b> Total items number 337 */ 338 public function setItems($rs,$rs_count) 339 { 340 $this->rs = $rs; 341 $this->rs_count = $rs_count; 300 342 } 301 343 … … 323 365 } 324 366 325 $nb_per_page = isset($_GET['nb']) ? $_GET['nb']: 10;367 $nb_per_page = !is_null($this->nb_per_page) ? $this->nb_per_page : 10; 326 368 327 369 return 328 370 sprintf($block,implode('',$list)). 329 '<p><label for="nb ">'.__('Items per page:').330 '</label> '.form::field('nb ',3,3,$nb_per_page).371 '<p><label for="nb_per_page">'.__('Items per page:'). 372 '</label> '.form::field('nb_per_page',3,3,$nb_per_page). 331 373 '</p>'; 332 374 } 333 375 334 376 /** 377 Returns HTML hidden fields for list options 378 379 @return <b>string</b> HTML hidden fields 380 */ 381 public function getFormFieldsAsHidden() 382 { 383 $res = ''; 384 385 if (!is_null($this->sortby)) { 386 $res .= form::hidden(array('sortby'),$this->sortby); 387 } 388 if (!is_null($this->order)) { 389 $res .= form::hidden(array('order'),$this->order); 390 } 391 if (!is_null($this->nb_per_page)) { 392 $res .= form::hidden(array('nb_per_page'),$this->nb_per_page); 393 } 394 if (!is_null($this->page)) { 395 $res .= form::hidden(array('page'),$this->page); 396 } 397 398 return $res; 399 } 400 401 /** 335 402 Returns HTML code list to display 336 403 337 @param page <b>string|int</b> Current page338 @param nb_per_page <b>string|int</b> Number of items to display in each page339 404 @param enclose_block <b>string</b> HTML wrapper of defined list 340 405 341 406 @return <b>string</b> HTML code list 342 407 */ 343 public function display($ page,$nb_per_page,$enclose_block = '')408 public function display($enclose_block = '') 344 409 { 345 410 if ($this->rs->isEmpty()) … … 349 414 else 350 415 { 351 $pager = new dcPager($page,$this->rs_count,$nb_per_page,10);416 $pager = new adminItemsPager($this->page,$this->rs_count,$this->nb_per_page,10); 352 417 $pager->html_prev = $this->html_prev; 353 418 $pager->html_next = $this->html_next; … … 358 423 $html_block = 359 424 '<table class="maximal clear">'. 360 $this->getCaption($ page).425 $this->getCaption($this->page). 361 426 '<thead><tr>'; 362 427 … … 420 485 $html = array(); 421 486 } 422 if ( isset($_GET['sortby']) && $_GET['sortby'] === $alias && isset($_GET['order'])) {487 if ($this->sortby === $alias && !is_null($this->order)) { 423 488 if (array_key_exists('class',$html)) { 424 array_push($html['class'],$ _GET['order']);489 array_push($html['class'],$this->order); 425 490 } 426 491 else { 427 $html['class'] = array($ _GET['order']);492 $html['class'] = array($this->order); 428 493 } 429 494 } 430 $c = new admin GenericColumn($id,$alias,$title,$callback,$html,$sortable,$listable,$can_hide);495 $c = new adminItemsColumn($id,$alias,$title,$callback,$html,$sortable,$listable,$can_hide); 431 496 $this->columns[$id] = $c; 432 497 } 433 498 catch (Exception $e) { 434 499 if (DC_DEBUG) { 435 $this->core->error->add( $e->getMessage());500 $this->core->error->add(sprintf('[%s] %s',$id,$e->getMessage())); 436 501 } 437 502 } … … 459 524 460 525 /** 526 Sets options of defined list 527 */ 528 private function setOptions() 529 { 530 $opts = $_GET; 531 532 $ws = $this->core->auth->user_prefs->addWorkspace('lists'); 533 534 $user_pref = !is_null($ws->{$this->context.'_opts'}) ? unserialize($ws->{$this->context.'_opts'}) : array(); 535 # Sortby 536 $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 540 $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 544 $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 /** 461 557 Sets columns visibility of defined list 462 558 */ 463 559 private function setColumnsVisibility() 464 560 { 561 $opts = $_GET; 562 563 # Visibility 465 564 $ws = $this->core->auth->user_prefs->addWorkspace('lists'); 466 565 467 $user_pref = !is_null($ws->{$this->context }) ? unserialize($ws->{$this->context}) : array();566 $user_pref = !is_null($ws->{$this->context.'_col'}) ? unserialize($ws->{$this->context.'_col'}) : array(); 468 567 469 568 foreach ($this->columns as $k => $v) { 470 569 $visibility = array_key_exists($k,$user_pref) ? $user_pref[$k] : true; 471 if (array_key_exists($this->form_trigger,$ _REQUEST)) {570 if (array_key_exists($this->form_trigger,$opts)) { 472 571 $key = sprintf($this->form_prefix,$k); 473 $visibility = !array_key_exists($key,$ _REQUEST) ? false : true;572 $visibility = !array_key_exists($key,$opts) ? false : true; 474 573 } 475 574 $v->setVisibility($visibility); … … 477 576 } 478 577 479 if (array_key_exists($this->form_trigger,$ _REQUEST)) {480 $this->core->auth->user_prefs->lists->put($this->context ,serialize($user_pref),'string');578 if (array_key_exists($this->form_trigger,$opts)) { 579 $this->core->auth->user_prefs->lists->put($this->context.'_col',serialize($user_pref),'string'); 481 580 } 482 581 } … … 532 631 { 533 632 $order = 'desc'; 534 if ( isset($_GET['sortby']) && $_GET['sortby']=== $c->getInfo('alias')) {535 if ( isset($_GET['order']) && $_GET['order'] === 'desc') {633 if (!is_null($this->sortby) && $this->sortby === $c->getInfo('alias')) { 634 if (!is_null($this->order) && $this->order === $order) { 536 635 $order = 'asc'; 537 636 } … … 558 657 Handle posts list on admin side 559 658 */ 560 class adminPostList extends admin GenericList659 class adminPostList extends adminItemsList 561 660 { 562 661 public function setColumns() … … 710 809 Handle comments list on admin side 711 810 */ 712 class adminCommentList extends admin GenericList811 class adminCommentList extends adminItemsList 713 812 { 714 813 public function setColumns() … … 813 912 Handle users list on admin side 814 913 */ 815 class adminUserList extends admin GenericList914 class adminUserList extends adminItemsList 816 915 { 817 916 public function setColumns() … … 880 979 Handle blogs list on admin side 881 980 */ 882 class adminBlogList extends admin GenericList981 class adminBlogList extends adminItemsList 883 982 { 884 983 public function setColumns() … … 888 987 $this->addColumn('entries',null,__('Entries'),array('adminBlogList','getEntries'),array('class' => array('nowrap')),false); 889 988 $this->addColumn('blogid','B.blog_id',__('Blog ID'),array('adminBlogList','getBlogId'),array('class' => array('nowrap'))); 890 $this->addColumn('action',null,'',array('adminBlogList','getAction'),array('class' => array('nowrap')) );989 $this->addColumn('action',null,'',array('adminBlogList','getAction'),array('class' => array('nowrap')),false); 891 990 $this->addColumn('status','blog_status',__('status'),array('adminBlogList','getStatus'),array('class' => array('nowrap'))); 892 991 }
Note: See TracChangeset
for help on using the changeset viewer.