Show
Ignore:
Timestamp:
04/25/08 11:36:53 (19 months ago)
Author:
fumiakiy
Message:

Implemented PHP version of pager related tags. Dynamically published archives can now be pagination-enabled by adding these tags and specify "auto" to limit and offset.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/release-36/php/lib/mtdb_base.php

    r2091 r2103  
    413413    } 
    414414 
    415     function &fetch_entries($args) { 
     415    function &fetch_entries($args, &$total_count = NULL) { 
    416416        if ($sql = $this->include_exclude_blogs($args)) { 
    417417            $blog_filter = 'and entry_blog_id ' . $sql; 
     
    422422        } 
    423423 
     424        $pagination = 0; 
    424425        # automatically include offset if in request 
    425426        if ($args['offset'] == 'auto') { 
     427            $pagination = 1; 
    426428            $args['offset'] = 0; 
    427429            if ($args['limit'] || $args['lastn']) { 
     
    801803            $post_select_limit = $rco; 
    802804            $no_resort = 1; 
     805        } elseif ( !is_null($total_count) ) { 
     806            $orig_limit = $limit; 
     807            $orig_offset = $offset; 
    803808        } else { 
    804809            $sql = $this->apply_limit_sql($sql . " <LIMIT>", $limit, $offset); 
     
    810815        $entries = array(); 
    811816        $j = 0; 
    812         $offset = $post_select_offset ? $post_select_offset : 0; 
     817        $offset = $post_select_offset ? $post_select_offset : $orig_offset; 
    813818        $limit = $post_select_limit ? $post_select_limit : 0; 
    814819        $id_list = array(); 
     820        $_total_count = 0; 
    815821        while (true) { 
    816822            $e = $this->query_fetch(ARRAY_A); 
     
    826832                } 
    827833            } 
     834            $_total_count++; 
     835            if ( !is_null($total_count) ) { 
     836                if ( ($orig_limit > 0) 
     837                  && ( ($_total_count-$offset) > $orig_limit) ) { 
     838                    // collected all the entries; only count numbers; 
     839                    continue; 
     840                } 
     841            } 
    828842            if ($offset && ($j++ < $offset)) continue; 
    829843            $e['entry_authored_on'] = $this->db2ts($e['entry_authored_on']); 
     
    833847            $this->_comment_count_cache[$e['entry_id']] = $e['entry_comment_count']; 
    834848            $this->_ping_count_cache[$e['entry_id']] = $e['entry_ping_count']; 
    835             if (($limit > 0) && (count($entries) >= $limit)) break; 
     849            if ( is_null($total_count) ) { 
     850                // the request does not want total count; break early 
     851                if (($limit > 0) && (count($entries) >= $limit)) break; 
     852            } 
     853        } 
     854        if ( !is_null($total_count) ) { 
     855            $total_count = $_total_count; 
    836856        } 
    837857