Changeset 213 for trunk/trax/vendor
- Timestamp:
- 05/31/06 14:47:07 (6 years ago)
- Location:
- trunk/trax/vendor/trax
- Files:
-
- 2 modified
-
action_view/helpers/active_record_helper.php (modified) (2 diffs)
-
active_record.php (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/trax/vendor/trax/action_view/helpers/active_record_helper.php
r201 r213 482 482 return $column['type']; 483 483 } 484 484 485 /** 486 * Paging html functions 487 * @todo Document this API 488 */ 489 function pagination_limit_select($object_name_or_object, $default_text = "per page:") { 490 491 if(is_object($object_name_or_object)) { 492 $object = $object_name_or_object; 493 } else { 494 $object = $this->object($object_name_or_object); 495 } 496 497 if(!is_object($object)) { 498 return null; 499 } 500 501 if($object->pages > 0) { 502 $html .= " 503 <select name=\"per_page\" onChange=\"document.location = '?".escape_javascript($object->paging_extra_params)."&per_page=' + this.options[this.selectedIndex].value;\"> 504 <option value=\"$object->rows_per_page\" selected>$default_text</option> 505 <option value=10>10</option> 506 <option value=20>20</option> 507 <option value=50>50</option> 508 <option value=100>100</option> 509 <option value=999999999>ALL</option> 510 </select> 511 "; 512 } 513 return $html; 514 } 515 516 /** 517 * @todo Document this API 518 * 519 * @return string HTML to link to previous and next pages 520 * @uses $display 521 * @uses $page 522 * @uses $pages 523 * @uses $paging_extra_params 524 * @uses rows_per_page 525 */ 526 function pagination_links($object_name_or_object){ 527 528 if(is_object($object_name_or_object)) { 529 $object = $object_name_or_object; 530 } else { 531 $object = $this->object($object_name_or_object); 532 } 533 534 if(!is_object($object)) { 535 return null; 536 } 537 538 //$html = "<pre>".print_r($object,1); 539 /* Print the first and previous page links if necessary */ 540 if(($object->page != 1) && ($object->page)) { 541 $html .= link_to("<<", 542 "?$object->paging_extra_params&page=1&per_page=$object->rows_per_page", 543 array( 544 "class" => "pageList", 545 "title" => "First page" 546 ))." "; 547 } 548 if(($object->page-1) > 0) { 549 $html .= link_to("<", 550 "?$object->paging_extra_params&page=".($object->page-1)."&per_page=$object->rows_per_page", 551 array( 552 "class" => "pageList", 553 "title" => "Previous Page" 554 )); 555 } 556 557 if($object->pages < $object->display) { 558 $object->display = $object->pages; 559 } 560 561 if($object->page == $object->pages) { 562 if(($object->pages - $object->display) == 0) { 563 $start = 1; 564 } else { 565 $start = $object->pages - $object->display; 566 } 567 $end = $object->pages; 568 } else { 569 if($object->page >= $object->display) { 570 $start = $object->page - ($object->display / 2); 571 $end = $object->page + (($object->display / 2) - 1); 572 } else { 573 $start = 1; 574 $end = $object->display; 575 } 576 } 577 578 if($end >= $object->pages) { 579 $end = $object->pages; 580 } 581 582 /* Print the numeric page list; make the current page unlinked and bold */ 583 if($end != 1) { 584 for($i=$start; $i<=$end; $i++) { 585 if($i == $object->page) { 586 $html .= "<span class=\"pageList\"><b>".$i."</b></span>"; 587 } else { 588 $html .= link_to($i, 589 "?$object->paging_extra_params&page=$i&per_page=$object->rows_per_page", 590 array( 591 "class" => "pageList", 592 "title" => "Page $i" 593 )); 594 } 595 $html .= " "; 596 } 597 } 598 599 /* Print the Next and Last page links if necessary */ 600 if(($object->page+1) <= $object->pages) { 601 $html .= link_to(">", 602 "?$object->paging_extra_params&page=".($object->page+1)."&per_page=$object->rows_per_page", 603 array( 604 "class" => "pageList", 605 "title" => "Next Page" 606 )); 607 } 608 if(($object->page != $object->pages) && ($object->pages != 0)) { 609 $html .= link_to(">>", 610 "?$object->paging_extra_params&page=".$object->pages."&per_page=$object->rows_per_page", 611 array( 612 "class" => "pageList", 613 "title" => "Last Page" 614 )); 615 } 616 $html .= "\n"; 617 618 return $html; 619 } 620 621 function pagination_range_text($object_name_or_object, $showing_text = "Showing", $showing_type = "items") { 622 if(is_object($object_name_or_object)) { 623 $object = $object_name_or_object; 624 } else { 625 $object = $this->object($object_name_or_object); 626 } 627 628 if(!is_object($object)) { 629 return null; 630 } 631 $end = $object->rows_per_page * $object->page; 632 $start = $end - ($object->rows_per_page - 1); 633 if($end >= $object->pagination_count) { 634 $end = $object->pagination_count; 635 } 636 637 return "{$showing_text} {$start} - {$end} of {$object->pagination_count} {$showing_type}."; 638 } 639 485 640 } 486 641 … … 537 692 $args = func_get_args(); 538 693 return call_user_func_array(array($ar_helper, 'input_scaffolding'), $args); 694 } 695 696 /** 697 * 698 * @uses ActiveRecordHelper::pagination_limit_select() 699 */ 700 function pagination_limit_select() { 701 $ar_helper = new ActiveRecordHelper(); 702 $args = func_get_args(); 703 return call_user_func_array(array($ar_helper, 'pagination_limit_select'), $args); 704 } 705 706 /** 707 * 708 * @uses ActiveRecordHelper::pagination_links() 709 */ 710 function pagination_links() { 711 $ar_helper = new ActiveRecordHelper(); 712 $args = func_get_args(); 713 return call_user_func_array(array($ar_helper, 'pagination_links'), $args); 714 } 715 716 /** 717 * 718 * @uses ActiveRecordHelper::pagination_range_text() 719 */ 720 function pagination_range_text() { 721 $ar_helper = new ActiveRecordHelper(); 722 $args = func_get_args(); 723 return call_user_func_array(array($ar_helper, 'pagination_range_text'), $args); 539 724 } 540 725 -
trunk/trax/vendor/trax/active_record.php
r210 r213 100 100 101 101 /** 102 * Class name 103 * 104 * Name of the child class. (this is optional and will automatically be determined) 105 * Normally set to the singular camel case form of the table name. 106 * May be overridden. 107 * @var string 108 */ 109 public $class_name = null; 110 111 /** 102 112 * Table name 103 113 * … … 290 300 */ 291 301 public $display = 10; # Pagination how many numbers in the list << < 1 2 3 4 > >> 302 303 /** 304 * @todo Document this variable 305 */ 306 public $pagination_count = 0; 292 307 293 308 /** … … 540 555 */ 541 556 private function find_all_habtm($other_table_name, $parameters = null) { 542 $other_class_name = Inflector::classify($other_table_name); 557 558 # Use any passed-in parameters 559 if (!is_null($parameters)) { 560 if(@array_key_exists("conditions", $parameters)) 561 $additional_conditions = $parameters['conditions']; 562 elseif($parameters[0] != "") 563 $additional_conditions = $parameters[0]; 564 565 if(@array_key_exists("order", $parameters)) 566 $orderings = $parameters['order']; 567 elseif($parameters[1] != "") 568 $orderings = $parameters[1]; 569 570 if(@array_key_exists("limit", $parameters)) 571 $limit = $parameters['limit']; 572 elseif($parameters[2] != "") 573 $limit = $parameters[2]; 574 575 if(@array_key_exists("joins", $parameters)) 576 $additional_joins = $parameters['joins']; 577 elseif($parameters[3] != "") 578 $additional_joins = $parameters[3]; 579 580 if(!empty($additional_conditions)) 581 $conditions .= " AND (" . $additional_conditions . ")"; 582 if(!empty($additional_joins)) 583 $joins .= " " . $additional_joins; 584 585 if(@array_key_exists("class_name", $parameters)) { 586 $other_object_name = $parameters['class_name']; 587 } 588 if(@array_key_exists("join_table", $parameters)) { 589 $join_table = $parameters['join_table']; 590 } 591 } 592 if(!is_null($other_object_name)) { 593 $other_class_name = Inflector::camelize($other_object_name); 594 } else { 595 $other_class_name = Inflector::classify($other_table_name); 596 } 543 597 # Instantiate an object to access find_all 544 $ results= new $other_class_name();598 $object = new $other_class_name(); 545 599 546 600 # Prepare the join table name primary keys (fields) to do the join on 547 $join_table = $this->get_join_table_name($this->table_name, $other_table_name); 601 if(is_null($join_table)) { 602 $join_table = $this->get_join_table_name($this->table_name, $other_table_name); 603 } 548 604 $this_foreign_key = Inflector::singularize($this->table_name)."_id"; 549 605 $other_foreign_key = Inflector::singularize($other_table_name)."_id"; … … 552 608 $orderings = null; 553 609 $limit = null; 554 $joins = "LEFT JOIN {$join_table} ON {$other_table_name}.id = {$other_foreign_key}"; 555 556 # Use any passed-in parameters 557 if (!is_null($parameters)) { 558 if(@array_key_exists("conditions", $parameters)) 559 $additional_conditions = $parameters['conditions']; 560 elseif($parameters[0] != "") 561 $additional_conditions = $parameters[0]; 562 563 if(@array_key_exists("orderings", $parameters)) 564 $orderings = $parameters['orderings']; 565 elseif($parameters[1] != "") 566 $orderings = $parameters[1]; 567 568 if(@array_key_exists("limit", $parameters)) 569 $limit = $parameters['limit']; 570 elseif($parameters[2] != "") 571 $limit = $parameters[2]; 572 573 if(@array_key_exists("joins", $parameters)) 574 $additional_joins = $parameters['joins']; 575 elseif($parameters[3] != "") 576 $additional_joins = $parameters[3]; 577 578 if (!empty($additional_conditions)) 579 $conditions .= " AND (" . $additional_conditions . ")"; 580 if (!empty($additional_joins)) 581 $joins .= " " . $additional_joins; 582 } 610 $joins .= "LEFT JOIN {$join_table} ON {$other_table_name}.id = {$other_foreign_key}"; 583 611 584 612 # Get the list of other_class_name objects 585 return $ results->find_all($conditions, $orderings, $limit, $joins);613 return $object->find_all($conditions, $orderings, $limit, $joins); 586 614 } 587 615 … … 595 623 */ 596 624 private function find_all_has_many($other_table_name, $parameters = null) { 597 # Prepare the class name and primary key, e.g. if598 # customers has_many contacts, then we'll need a Contact599 # object, and the customer_id field name.600 if(@array_key_exists("foreign_key", $parameters))601 $foreign_key = $parameters['foreign_key'];602 else603 $foreign_key = Inflector::singularize($this->table_name)."_id";604 605 $other_class_name = Inflector::classify($other_table_name);606 $conditions = "{$foreign_key}=$this->id";607 625 608 626 # Use any passed-in parameters … … 614 632 $additional_conditions = $parameters[0]; 615 633 616 if(@array_key_exists("order ings", $parameters))617 $orderings = $parameters['order ings'];634 if(@array_key_exists("order", $parameters)) 635 $orderings = $parameters['order']; 618 636 elseif($parameters[1] != "") 619 637 $orderings = $parameters[1]; … … 633 651 if(!empty($additional_joins)) 634 652 $joins .= " " . $additional_joins; 653 654 if(@array_key_exists("class_name", $parameters)) { 655 $other_object_name = $parameters['class_name']; 656 } 657 } 658 659 if(!is_null($other_object_name)) { 660 $other_class_name = Inflector::camelize($other_object_name); 661 } else { 662 $other_class_name = Inflector::classify($other_table_name); 635 663 } 636 664 637 665 # Instantiate an object to access find_all 638 666 $other_class_object = new $other_class_name(); 667 668 if(@array_key_exists("foreign_key", $parameters)) { 669 $foreign_key = $parameters['foreign_key']; 670 } else { 671 $foreign_key = Inflector::singularize($this->table_name)."_id"; 672 } 673 if(count($other_class_object->primary_keys) == 1) { 674 $id = $other_class_object->primary_keys[0]; 675 } else { 676 $id = "id"; 677 } 678 $id_value = $this->$id; 679 if(is_numeric($id_value)) { 680 $conditions = "$foreign_key={$id_value}"; 681 } else { 682 $conditions = "$foreign_key='{$id_value}'"; 683 } 684 639 685 # Get the list of other_class_name objects 640 $results = $other_class_object->find_all($conditions, $orderings, $limit, $joins); 641 642 return $results; 686 return $other_class_object->find_all($conditions, $orderings, $limit, $joins); 643 687 } 644 688 … … 652 696 */ 653 697 private function find_one_has_one($other_object_name, $parameters = null) { 654 # Prepare the class name and primary key, e.g. if 655 # customers has_many contacts, then we'll need a Contact 656 # object, and the customer_id field name. 657 $other_ = Inflector::camelize($other_object_name); 658 if(@array_key_exists("foreign_key", $parameters)) 698 if(@array_key_exists("class_name", $parameters)) { 699 $other_object_name = $parameters['class_name']; 700 } 701 $other_class_name = Inflector::camelize($other_object_name); 702 703 # Instantiate an object to access find_all 704 $other_class_object = new $other_class_name(); 705 706 if(@array_key_exists("foreign_key", $parameters)) { 659 707 $foreign_key = $parameters['foreign_key']; 660 else708 } else { 661 709 $foreign_key = Inflector::singularize($this->table_name)."_id"; 662 663 $conditions = "$foreign_key='{$this->id}'"; 664 # Instantiate an object to access find_all 665 $results = new $other_class_name(); 710 } 711 712 if(count($other_class_object->primary_keys) == 1) { 713 $id = $other_class_object->primary_keys[0]; 714 } else { 715 $id = "id"; 716 } 717 $id_value = $this->$id; 718 if(is_numeric($id_value)) { 719 $conditions = "$foreign_key={$id_value}"; 720 } else { 721 $conditions = "$foreign_key='{$id_value}'"; 722 } 723 666 724 # Get the list of other_class_name objects 667 $result s = $results->find_first($conditions, $orderings);725 $result = $other_class_object->find_first($conditions, $orderings); 668 726 # There should only be one result, an object, if so return it 669 if(is_object($result s)) {670 return $result s;727 if(is_object($result)) { 728 return $result; 671 729 } else { 672 730 return null; … … 684 742 */ 685 743 private function find_one_belongs_to($other_object_name, $parameters = null) { 686 # Prepare the class name and primary key, e.g. if687 # customers has_many contacts, then we'll need a Contact688 # object, and the customer_id field name.744 if(@array_key_exists("class_name", $parameters)) { 745 $other_object_name = $parameters['class_name']; 746 } 689 747 $other_class_name = Inflector::camelize($other_object_name); 690 if(@array_key_exists("foreign_key", $parameters)) 748 749 # Instantiate an object to access find_all 750 $other_class_object = new $other_class_name(); 751 752 if(@array_key_exists("foreign_key", $parameters)) { 691 753 $foreign_key = $parameters['foreign_key']; 692 else754 } else { 693 755 $foreign_key = $other_object_name."_id"; 694 695 $conditions = "id='".$this->$foreign_key."'"; 696 # Instantiate an object to access find_all 697 $results = new $other_class_name(); 756 } 757 758 if(count($other_class_object->primary_keys) == 1) { 759 $id = $other_class_object->primary_keys[0]; 760 } else { 761 $id = "id"; 762 } 763 $foreign_key_value = $this->$foreign_key; 764 if(is_numeric($foreign_key_value)) { 765 $conditions = "$id = $foreign_key_value"; 766 } else { 767 $conditions = "$id = '$foreign_key_value'"; 768 } 769 698 770 # Get the list of other_class_name objects 699 $result s = $results->find_first($conditions, $orderings);771 $result = $other_class_object->find_first($conditions, $orderings); 700 772 # There should only be one result, an object, if so return it 701 if(is_object($result s)) {702 return $result s;773 if(is_object($result)) { 774 return $result; 703 775 } else { 704 776 return null; … … 744 816 if(!empty($conditions)) $sql .= "WHERE $conditions "; 745 817 746 //echo "sql:$sql<br>";818 # echo "$aggregrate_type sql:$sql<br>"; 747 819 if($this->is_error($rs = $this->query($sql))) { 748 820 $this->raise($rs->getMessage()); 749 821 } else { 750 822 $row = $rs->fetchRow(); 751 return $row["agg_result"]; 823 if($row["agg_result"]) { 824 return $row["agg_result"]; 825 } 752 826 } 753 827 return 0; … … 978 1052 // .', ' . (is_null($joins)?'null':$joins).')'); 979 1053 980 // Is output to be generated in pages? 981 if (is_array($limit)) { 982 983 // Yes, get next page number and rows per page from argument 984 list($this->page, $this->rows_per_page) = $limit; 985 if($this->page <= 0) { 986 $this->page = 1; 987 } 988 # Default for rows_per_page: 989 if ($this->rows_per_page == null) { 990 $this->rows_per_page = $this->rows_per_page_default; 991 } 992 # Set the LIMIT string segment for the SQL in the find_all 993 $this->offset = ($this->page - 1) * $this->rows_per_page; 994 # mysql 3.23 doesn't support OFFSET 995 //$limit = "$rows_per_page OFFSET $offset"; 996 $limit = $this->offset.", ".$this->rows_per_page; 997 998 // Remember that we're generating output in pages 999 // so $limit needs to be added to the query 1000 $set_pages = true; 1001 } 1002 1003 // Test source of SQL for query 1054 # Test source of SQL for query 1004 1055 if(stristr($conditions, "SELECT")) { 1005 1006 // SQL completely specified in argument so use it as is 1056 # SQL completely specified in argument so use it as is 1007 1057 $sql = $conditions; 1008 1058 } else { 1009 1010 // SQL will be built from specifications in argument 1059 # SQL will be built from specifications in argument 1011 1060 $sql = "SELECT * FROM ".$this->table_name." "; 1012 1013 // If join specified, include it 1061 1062 # this is if they passed in an associative array to emulate 1063 # named parameters. 1064 if(is_array($conditions)) { 1065 extract($conditions); 1066 if(is_array($conditions)) { 1067 $conditions = null; 1068 } 1069 } 1070 1071 # If join specified, include it 1014 1072 if(!is_null($joins)) { 1015 1073 if(substr($joins,0,4) != "LEFT") $sql .= ","; … … 1017 1075 } 1018 1076 1019 //If conditions specified, include them1077 # If conditions specified, include them 1020 1078 if(!is_null($conditions)) { 1021 1079 $sql .= "WHERE $conditions "; 1022 1080 } 1023 1081 1024 //If ordering specified, include it1082 # If ordering specified, include it 1025 1083 if(!is_null($orderings)) { 1026 1084 $sql .= "ORDER BY $orderings "; 1027 1085 } 1028 1086 1029 // If limit specified, divide into pages 1030 if(!is_null($limit)) { 1031 // FIXME: Isn't the second test redundant? 1032 if($set_pages) { 1033 1034 // Send query to database 1035 //echo "query: $sql\n"; 1036 if($this->is_error($rs = $this->query($sql))) { 1037 1038 // Error returned, throw error exception 1039 $this->raise($rs->getMessage()); 1040 // Execution doesn't return here 1041 } else { 1042 1043 # Set number of total pages in result set 1044 # without the LIMIT 1045 if($count = $rs->numRows()) 1046 $this->pages = ( 1047 ($count % $this->rows_per_page) == 0) 1048 ? $count / $this->rows_per_page 1049 : floor($count / $this->rows_per_page) + 1; 1050 } 1087 # If limit specified, divide into pages 1088 if(!is_null($limit) || !is_null($offset) || !is_null($per_page)) { 1089 1090 # Is output to be generated in pages? 1091 if(is_array($limit)) { 1092 # Yes, get next page number and rows per page from argument 1093 list($this->page, $this->rows_per_page) = $limit; 1094 } else { 1095 $this->rows_per_page = $limit; 1051 1096 } 1052 $sql .= "LIMIT $limit"; 1053 } 1054 } 1055 1056 //echo "ActiveRecord::find_all() - sql: $sql\n<br>"; 1057 //echo "query: $sql\n"; 1097 if(!is_null($per_page)) { 1098 $this->rows_per_page = $per_page; 1099 } 1100 # Default for rows_per_page: 1101 if ($this->rows_per_page <= 0) { 1102 $this->rows_per_page = $this->rows_per_page_default; 1103 } 1104 1105 $this->page = $_REQUEST['page']; 1106 if($this->page <= 0) { 1107 $this->page = 1; 1108 } 1109 1110 # Set the LIMIT string segment for the SQL 1111 if(!$offset) { 1112 $offset = ($this->page - 1) * $this->rows_per_page; 1113 } 1114 1115 $sql .= "LIMIT $this->rows_per_page OFFSET $offset"; 1116 # $sql .= "LIMIT $offset, $this->rows_per_page"; 1117 1118 # Send query to database 1119 # Set number of total pages in result set 1120 # without the LIMIT 1121 if($count = $this->count_all("*", $conditions, $joins)) { 1122 $this->pagination_count = $count; 1123 $this->pages = ( 1124 ($count % $this->rows_per_page) == 0) 1125 ? $count / $this->rows_per_page 1126 : floor($count / $this->rows_per_page) + 1; 1127 } 1128 } 1129 } 1130 1131 # echo "ActiveRecord::find_all() - sql: $sql\n<br>"; 1132 # echo "query: $sql\n"; 1058 1133 if($this->is_error($rs = $this->query($sql))) { 1059 1134 $this->raise($rs->getMessage()); … … 1062 1137 $objects = array(); 1063 1138 while($row = $rs->fetchRow()) { 1064 $class = get_class($this); 1065 #$class = Inflector::classify($this->table_name); 1066 $object = new $class(); 1139 $class_name = $this->get_class_name(); 1140 $object = new $class_name(); 1067 1141 $object->new_record = false; 1068 foreach($row as $field => $val ) {1069 $object->$field = $val ;1142 foreach($row as $field => $value) { 1143 $object->$field = $value; 1070 1144 if($field == $this->index_on) { 1071 $objects_key = $val ;1145 $objects_key = $value; 1072 1146 } 1073 1147 } … … 1210 1284 } 1211 1285 } else { 1212 $class = get_class($this);1213 $object = new $class ();1286 $class_name = $this->get_class_name(); 1287 $object = new $class_name(); 1214 1288 $object->save($attributes, $dont_validate); 1215 1289 } … … 1968 2042 function set_table_name_using_class_name() { 1969 2043 if(!$this->table_name) { 1970 $this->table_name = Inflector::tableize(get_class($this)); 1971 } 2044 $class_name = $this->get_class_name(); 2045 $this->table_name = Inflector::tableize($class_name); 2046 } 2047 } 2048 2049 /** 2050 * Get class name of child object 2051 * 2052 * this will return the manually set name or get_class($this) 2053 * @return string child class name 2054 */ 2055 private function get_class_name() { 2056 if(!is_null($this->class_name)) { 2057 $class_name = $this->class_name; 2058 } else { 2059 $class_name = get_class($this); 2060 } 2061 return $class_name; 1972 2062 } 1973 2063 … … 2096 2186 */ 2097 2187 function raise($message) { 2098 $error_message = "Model Class: ". get_class($this)."<br>";2188 $error_message = "Model Class: ".$this->get_class_name()."<br>"; 2099 2189 $error_message .= "Error Message: ".$message; 2100 2190 throw new ActiveRecordError($error_message, "ActiveRecord Error", "500"); … … 2225 2315 $validated_ok = true; 2226 2316 $attrs = $this->get_attributes(); 2227 $methods = get_class_methods( get_class($this));2317 $methods = get_class_methods($this->get_class_name()); 2228 2318 foreach($methods as $method) { 2229 2319 if(preg_match('/^validate_(.+)/', $method, $matches)) { … … 2372 2462 } 2373 2463 2374 /**2375 * Paging html functions2376 * @todo Document this API2377 */2378 function limit_select($controller =null, $additional_query = null) {2379 if($this->pages > 0) {2380 $html = "2381 <select name=\"per_page\" onChange=\"document.location = '?$this->paging_extra_params&per_page=' + this.options[this.selectedIndex].value;\">2382 <option value=\"$this->rows_per_page\" selected>per page:</option>2383 <option value=10>10</option>2384 <option value=20>20</option>2385 <option value=50>50</option>2386 <option value=100>100</option>2387 <option value=999999999>ALL</option>2388 </select>2389 ";2390 }2391 return $html;2392 }2393 2394 /**2395 * @todo Document this API2396 *2397 * @return string HTML to link to previous and next pages2398 * @uses $display2399 * @uses $page2400 * @uses $pages2401 * @uses $paging_extra_params2402 * @uses rows_per_page2403 */2404 function page_list(){2405 $page_list = "";2406 2407 /* Print the first and previous page links if necessary */2408 if(($this->page != 1) && ($this->page))2409 $page_list .= "<a href=\"?$this->paging_extra_params&page=1&per_page=$this->rows_per_page\" class=\"page_list\" title=\"First Page\"><<</a> ";2410 2411 if(($this->page-1) > 0)2412 $page_list .= "<a href=\"?$this->paging_extra_params&page=".($this->page-1)."&per_page=$this->rows_per_page\" class=\"page_list\" title=\"Previous Page\"><</a> ";2413 2414 if($this->pages < $this->display)2415 $this->display = $this->pages;2416 2417 if($this->page == $this->pages) {2418 if($this->pages - $this->display == 0)2419 $start = 1;2420 else2421 $start = $this->pages - $this->display;2422 $max = $this->pages;2423 } else {2424 if($this->page >= $this->display) {2425 $start = $this->page - ($this->display / 2);2426 $max = $this->page + (($this->display / 2)-1);2427 } else {2428 $start = 1;2429 $max = $this->display;2430 }2431 }2432 2433 if($max >= $this->pages)2434 $max = $this->pages;2435 2436 /* Print the numeric page list; make the current page unlinked and bold */2437 if($max != 1) {2438 for ($i=$start; $i<=$max; $i++) {2439 if ($i == $this->page)2440 $page_list .= "<span class=\"pageList\"><b>".$i."</b></span>";2441 else2442 $page_list .= "<a href=\"?$this->paging_extra_params&page=$i&per_page=$this->rows_per_page\" class=\"page_list\" title=\"Page ".$i."\">".$i."</a>";2443 2444 $page_list .= " ";2445 }2446 }2447 2448 /* Print the Next and Last page links if necessary */2449 if(($this->page+1) <= $this->pages)2450 $page_list .= "<a href=\"?$this->paging_extra_params&page=".($this->page+1)."&per_page=$this->rows_per_page\" class=\"page_list\" title=\"Next Page\">></a> ";2451 2452 if(($this->page != $this->pages) && ($this->pages != 0))2453 $page_list .= "<a href=\"?$this->paging_extra_params&page=".$this->pages."&per_page=$this->rows_per_page\" class=\"page_list\" title=\"Last Page\">>></a> ";2454 2455 $page_list .= "\n";2456 2457 //error_log("Page list=[$page_list]");2458 return $page_list;2459 }2460 2461 2464 } 2462 2465
