Changeset 452:c68ac440f56f
- Timestamp:
- 06/30/11 10:55:01 (14 years ago)
- Branch:
- formfilters
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/admin/lib.pager.php
r449 r452 12 12 if (!defined('DC_RC_PATH')) { return; } 13 13 14 /** 15 @ingroup DC_CORE 16 @nosubgrouping 17 @brief Dotclear Pager class. 18 19 Dotclear Pager handles pagination for every admin list. 20 */ 14 21 class dcPager extends pager 15 22 { … … 27 34 28 35 # Page text 29 $htmlText = sprintf(__('Page %s over %s'),$this->env,$this->nb_ elements).' ';36 $htmlText = sprintf(__('Page %s over %s'),$this->env,$this->nb_pages).' '; 30 37 31 38 # Previous page … … 82 89 } 83 90 91 /** 92 @ingroup DC_CORE 93 @nosubgrouping 94 @brief Dotclear Generic column class. 95 96 Dotclear Generic column handles each column object use in adminGenericList class. 97 */ 84 98 class adminGenericColumn 85 99 { 86 protected $core; 87 protected $rs; 88 protected $id; 89 protected $title; 90 protected $callback; 91 protected $html; 92 protected $visibility; 93 100 protected $core; /// <b>object</b> dcCore object 101 protected $id; /// <b>string</b> ID of defined column 102 protected $title; /// <b>string</b> Title of defined column 103 protected $callback; /// <b>array</b> Callback calls to display defined column 104 protected $html; /// <b>string</b> Extra HTML for defined column 105 protected $visibility; /// <b>boolean</b> Visibility of defined column 106 107 /** 108 Inits Generic column object 109 110 @param id <b>string</b> Column id 111 @param title <b>string</b> Column title (for table headers) 112 @param callback <b>array</b> Column callback (used for display) 113 @param html <b>string</b> Extra html (used for table headers) 114 @param can_hide <b>boolean</b> Defines if the column can be hidden or not 115 */ 94 116 public function __construct($id,$title,$callback,$html = null,$can_hide = true) 95 117 { … … 136 158 } 137 159 138 public function getInfo($k) 139 { 140 return property_exists(get_class($this),$k) ? $this->{$k} : null; 141 } 142 160 /** 161 Gets information of defined column 162 163 @param info <b>string</b> Column info to retrive 164 165 @return <b>mixed</b> The information requested, null otherwise 166 */ 167 public function getInfo($info) 168 { 169 return property_exists(get_class($this),$info) ? $this->{$info} : null; 170 } 171 172 /** 173 Sets visibility of defined column 174 175 @param visibility <b>boolean</b> Column visibility 176 */ 143 177 public function setVisibility($visibility) 144 178 { … … 148 182 } 149 183 184 /** 185 Returns visibility status of defined column 186 187 @return <b>boolean</b> true if column is visible, false otherwise 188 */ 150 189 public function isVisible() 151 190 { … … 153 192 } 154 193 194 /** 195 Returns if the defined column can be hidden 196 197 @return <b>boolean</b> true if column can be hidden, false otherwise 198 */ 155 199 public function canHide() 156 200 { … … 159 203 } 160 204 161 class adminGenericList 205 /** 206 @ingroup DC_CORE 207 @nosubgrouping 208 @brief abstract Generic list class. 209 210 Dotclear Generic list handles administration lists 211 */ 212 abstract class adminGenericList 162 213 { 163 214 protected $core; … … 166 217 protected $columns; 167 218 219 /* 220 Sets columns of defined list 221 */ 222 abstract function setColumns(); 223 224 /** 225 Inits List object 226 227 @param core <b>dcCore</b> dcCore object 228 @param rs <b>recordSet</b> Items recordSet to display 229 @param rs_count <b>int</b> Total items number 230 */ 168 231 public function __construct($core,$rs,$rs_count) 169 232 { … … 181 244 $this->html_end = __('end'); 182 245 183 # Post columns 184 $this->addColumn('adminPostList','title',__('Title'),array('adminPostList','getTitle'),' class="maximal"',false); 185 $this->addColumn('adminPostList','date',__('Date'),array('adminPostList','getDate')); 186 $this->addColumn('adminPostList','datetime',__('Date and time'),array('adminPostList','getDateTime')); 187 $this->addColumn('adminPostList','category',__('Category'),array('adminPostList','getCategory')); 188 $this->addColumn('adminPostList','author',__('Author'),array('adminPostList','getAuthor')); 189 $this->addColumn('adminPostList','comment',__('Comments'),array('adminPostList','getComments')); 190 $this->addColumn('adminPostList','trackback',__('Trackbacks'),array('adminPostList','getTrackbacks')); 191 $this->addColumn('adminPostList','status',__('Status'),array('adminPostList','getStatus')); 192 193 # Post (mini list) columns 194 $this->addColumn('adminPostMiniList','title',__('Title'),array('adminPostList','getTitle'),' class="maximal"',false); 195 $this->addColumn('adminPostMiniList','date',__('Date'),array('adminPostList','getDate')); 196 $this->addColumn('adminPostMiniList','author',__('Author'),array('adminPostList','getAuthor')); 197 $this->addColumn('adminPostMiniList','status',__('Status'),array('adminPostList','getStatus')); 198 199 # Comment columns 200 $this->addColumn('adminCommentList','title',__('Title'),array('adminCommentList','getTitle'),' class="maximal"',false); 201 $this->addColumn('adminCommentList','date',__('Date'),array('adminCommentList','getDate')); 202 $this->addColumn('adminCommentList','author',__('Author'),array('adminCommentList','getAuthor')); 203 $this->addColumn('adminCommentList','type',__('Type'),array('adminCommentList','getType')); 204 $this->addColumn('adminCommentList','status',__('Status'),array('adminCommentList','getStatus')); 205 $this->addColumn('adminCommentList','edit','',array('adminCommentList','getEdit')); 206 207 # User columns 208 $this->addColumn('adminUserList','username',__('Username'),array('adminUserList','getUserName'),' class="maximal"',false); 209 $this->addColumn('adminUserList','firstname',__('First name'),array('adminUserList','getFirstName')); 210 $this->addColumn('adminUserList','lastname',__('Last name'),array('adminUserList','getLastName')); 211 $this->addColumn('adminUserList','displayname',__('Display name'),array('adminUserList','getDisplayName')); 212 $this->addColumn('adminUserList','entries',__('Entries'),array('adminUserList','getEntries')); 213 214 $core->callBehavior('adminGenericListConstruct',$this); 246 $this->setColumns(); 247 248 $core->callBehavior('adminListConstruct',$this); 215 249 216 250 $this->setColumnsVisibility(); 217 251 } 218 252 219 public function addColumn($context,$id,$title,$callback,$html = null,$can_hide = true) 220 { 221 try { 222 if (!array_key_exists($context,$this->columns)) { 223 $this->columns[$context] = array(); 224 } 225 226 $c = new adminGenericColumn($id,$title,$callback,$html,$can_hide); 227 $this->columns[$context][$c->getInfo('id')] = $c; 228 } 229 catch (Exception $e) { 230 if (DC_DEBUG) { 231 $this->core->error->add($e->getMessage()); 232 } 233 } 234 } 235 236 public function setColumnsVisibility() 237 { 238 $ws = $this->core->auth->user_prefs->addWorkspace('lists'); 239 240 $user_pref = !is_null($ws->{$this->context}) ? unserialize($ws->{$this->context}) : array(); 241 242 foreach ($this->columns[$this->context] as $k => $v) { 243 $visibility = array_key_exists($k,$user_pref) ? $user_pref[$k] : true; 244 if (array_key_exists($this->form_trigger,$_REQUEST)) { 245 $key = sprintf($this->form_prefix,$k); 246 $visibility = !array_key_exists($key,$_REQUEST) ? false : true; 247 } 248 if (!$v->canHide()) { 249 $visibility = true; 250 } 251 $v->setVisibility($visibility); 252 $user_pref[$k] = $visibility; 253 } 254 255 if (array_key_exists($this->form_trigger,$_REQUEST)) { 256 $this->core->auth->user_prefs->lists->put($this->context,serialize($user_pref),'string'); 257 } 258 } 259 253 /** 254 Returns HTML code form used to choose which column to display 255 256 @return <b>string</b> HTML code form 257 */ 260 258 public function getColumnsForm() 261 259 { … … 266 264 $list = array(); 267 265 268 foreach ($this->columns [$this->context]as $k => $v) {266 foreach ($this->columns as $k => $v) { 269 267 $col_id = sprintf($this->form_prefix,$k); 270 268 $col_label = sprintf('<label for="%s">%s</label>',$col_id,$v->getInfo('title')); … … 281 279 } 282 280 283 public function display($page,$nb_per_page,$enclose_block='') 281 /** 282 Returns HTML code list to display 283 284 @param page <b>string|int</b> Current page 285 @param nb_per_page <b>string|int</b> Number of items to display in each page 286 @param enclose_block <b>string</b> HTML wrapper of defined list 287 288 @return <b>string</b> HTML code list 289 */ 290 public function display($page,$nb_per_page,$enclose_block = '') 284 291 { 285 292 if ($this->rs->isEmpty()) … … 301 308 '<thead><tr>'; 302 309 303 foreach ($this->columns [$this->context]as $k => $v) {310 foreach ($this->columns as $k => $v) { 304 311 if ($v->isVisible()) { 305 312 $html_extra = $v->getInfo('html') != '' ? ' '.$v->getInfo('html') : ''; … … 334 341 } 335 342 343 /** 344 Adds column to defined list 345 346 @param id <b>string</b> Column id 347 @param title <b>string</b> Column title (for table headers) 348 @param callback <b>array</b> Column callback (used for display) 349 @param html <b>string</b> Extra html (used for table headers) 350 @param can_hide <b>boolean</b> Defines if the column can be hidden or not 351 */ 352 protected function addColumn($id,$title,$callback,$html = null,$can_hide = true) 353 { 354 try { 355 $c = new adminGenericColumn($id,$title,$callback,$html,$can_hide); 356 $this->columns[$id] = $c; 357 } 358 catch (Exception $e) { 359 if (DC_DEBUG) { 360 $this->core->error->add($e->getMessage()); 361 } 362 } 363 } 364 365 /** 366 Returns default caption text 367 368 @return <b>string</b> Default caption 369 */ 370 protected function getDefaultCaption() 371 { 372 return; 373 } 374 375 /** 376 Returns default HTMl code line 377 378 @return <b>string</b> Default HTMl code line 379 */ 380 protected function getDefaultLine() 381 { 382 return '<tr class="line">%s</tr>'; 383 } 384 385 /** 386 Sets columns visibility of defined list 387 */ 388 private function setColumnsVisibility() 389 { 390 $ws = $this->core->auth->user_prefs->addWorkspace('lists'); 391 392 $user_pref = !is_null($ws->{$this->context}) ? unserialize($ws->{$this->context}) : array(); 393 394 foreach ($this->columns as $k => $v) { 395 $visibility = array_key_exists($k,$user_pref) ? $user_pref[$k] : true; 396 if (array_key_exists($this->form_trigger,$_REQUEST)) { 397 $key = sprintf($this->form_prefix,$k); 398 $visibility = !array_key_exists($key,$_REQUEST) ? false : true; 399 } 400 if (!$v->canHide()) { 401 $visibility = true; 402 } 403 $v->setVisibility($visibility); 404 $user_pref[$k] = $visibility; 405 } 406 407 if (array_key_exists($this->form_trigger,$_REQUEST)) { 408 $this->core->auth->user_prefs->lists->put($this->context,serialize($user_pref),'string'); 409 } 410 } 411 412 /** 413 Returns HTML code for each line of defined list 414 415 @return <b>string</b> HTML code line 416 */ 336 417 private function displayLine() 337 418 { 338 419 $res = ''; 339 420 340 foreach ($this->columns [$this->context]as $k => $v) {421 foreach ($this->columns as $k => $v) { 341 422 if ($v->isVisible()) { 342 423 $c = $v->getInfo('callback'); … … 349 430 } 350 431 432 /** 433 Returns caption of defined list 434 435 @param page <b>string|int</b> Current page 436 437 @return <b>string</b> HTML caption tag 438 */ 351 439 private function getCaption($page) 352 440 { … … 362 450 return $caption; 363 451 } 364 365 protected function getDefaultCaption()366 {367 return;368 }369 370 protected function getDefaultLine()371 {372 return '<tr class="line">%s</tr>';373 }374 452 } 375 453 454 /** 455 @ingroup DC_CORE 456 @nosubgrouping 457 @brief abstract posts list class. 458 459 Handle posts list on admin side 460 */ 376 461 class adminPostList extends adminGenericList 377 462 { 463 public function setColumns() 464 { 465 $this->addColumn('title',__('Title'),array('adminPostList','getTitle'),' class="maximal"',false); 466 $this->addColumn('date',__('Date'),array('adminPostList','getDate')); 467 $this->addColumn('datetime',__('Date and time'),array('adminPostList','getDateTime')); 468 $this->addColumn('category',__('Category'),array('adminPostList','getCategory')); 469 $this->addColumn('author',__('Author'),array('adminPostList','getAuthor')); 470 $this->addColumn('comment',__('Comments'),array('adminPostList','getComments')); 471 $this->addColumn('trackback',__('Trackbacks'),array('adminPostList','getTrackbacks')); 472 $this->addColumn('status',__('Status'),array('adminPostList','getStatus')); 473 } 474 378 475 protected function getDefaultCaption() 379 476 { … … 479 576 } 480 577 578 /** 579 @ingroup DC_CORE 580 @nosubgrouping 581 @brief abstract mini posts list class. 582 583 Handle mini posts list on admin side (used for link popup) 584 */ 481 585 class adminPostMiniList extends adminPostList 482 586 { 587 public function setColumns() 588 { 589 $this->addColumn('title',__('Title'),array('adminPostList','getTitle'),' class="maximal"',false); 590 $this->addColumn('date',__('Date'),array('adminPostList','getDate')); 591 $this->addColumn('author',__('Author'),array('adminPostList','getAuthor')); 592 $this->addColumn('status',__('Status'),array('adminPostList','getStatus')); 593 } 594 483 595 protected function getTitle() 484 596 { … … 492 604 } 493 605 606 /** 607 @ingroup DC_CORE 608 @nosubgrouping 609 @brief abstract comments list class. 610 611 Handle comments list on admin side 612 */ 494 613 class adminCommentList extends adminGenericList 495 614 { 615 public function setColumns() 616 { 617 $this->addColumn('title',__('Title'),array('adminCommentList','getTitle'),' class="maximal"',false); 618 $this->addColumn('date',__('Date'),array('adminCommentList','getDate')); 619 $this->addColumn('author',__('Author'),array('adminCommentList','getAuthor')); 620 $this->addColumn('type',__('Type'),array('adminCommentList','getType')); 621 $this->addColumn('status',__('Status'),array('adminCommentList','getStatus')); 622 $this->addColumn('edit','',array('adminCommentList','getEdit')); 623 } 624 496 625 protected function getDefaultCaption() 497 626 { … … 578 707 } 579 708 709 /** 710 @ingroup DC_CORE 711 @nosubgrouping 712 @brief abstract users list class. 713 714 Handle users list on admin side 715 */ 580 716 class adminUserList extends adminGenericList 581 717 { 718 public function setColumns() 719 { 720 $this->addColumn('username',__('Username'),array('adminUserList','getUserName'),'class="maximal"',false); 721 $this->addColumn('firstname',__('First name'),array('adminUserList','getFirstName'),'class="nowrap"'); 722 $this->addColumn('lastname',__('Last name'),array('adminUserList','getLastName'),'class="nowrap"'); 723 $this->addColumn('displayname',__('Display name'),array('adminUserList','getDisplayName'),'class="nowrap"'); 724 $this->addColumn('entries',__('Entries'),array('adminUserList','getEntries'),'class="nowrap"'); 725 } 726 582 727 protected function getDefaultCaption() 583 728 {
Note: See TracChangeset
for help on using the changeset viewer.