Show
Ignore:
Timestamp:
05/31/06 14:47:07 (6 years ago)
Author:
john
Message:

moved paging to AR Helper, find_all can take an array now, bug fixes

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/trax/vendor/trax/action_view/helpers/active_record_helper.php

    r201 r213  
    482482        return $column['type']; 
    483483    } 
    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     
    485640} 
    486641 
     
    537692    $args = func_get_args(); 
    538693    return call_user_func_array(array($ar_helper, 'input_scaffolding'), $args); 
     694} 
     695 
     696/** 
     697 * 
     698 *  @uses ActiveRecordHelper::pagination_limit_select() 
     699 */ 
     700function 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 */ 
     710function 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 */ 
     720function 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); 
    539724} 
    540725