Changeset 1911

Show
Ignore:
Timestamp:
04/15/08 06:44:48 (22 months ago)
Author:
takayama
Message:

Implemented BugId:72216
* Implemented offset attribute to MTComments

Location:
branches/release-35
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/release-35/lib/MT/Template/ContextHandlers.pm

    r1906 r1911  
    50585058    if ($comments) { 
    50595059        my $n = $args->{lastn}; 
     5060        my $col = lc($args->{sort_by} || 'created_on'); 
     5061        @$comments = $so eq 'ascend' ? 
     5062            sort { $a->$col() cmp $b->$col() } @$comments : 
     5063            sort { $b->$col() cmp $a->$col() } @$comments; 
     5064        $no_resort = 1; 
    50605065        if (@filters) { 
     5066            my $offset = $args->{offset} || 0; 
     5067            my $j      = 0; 
    50615068            COMMENTS: for my $c (@$comments) { 
    50625069                for (@filters) { 
    50635070                    next COMMENTS unless $_->($c); 
    50645071                } 
     5072                next if $offset && $j++ < $offset; 
    50655073                push @comments, $c; 
    50665074            } 
    50675075        } 
    50685076        else { 
    5069             @comments = @$comments; 
     5077            my $offset; 
     5078            if ($offset = $args->{offset}) { 
     5079                if ($offset < scalar @comments) { 
     5080                    @comments = @$comments[$offset..$#comments]; 
     5081                } else { 
     5082                    @comments = (); 
     5083                } 
     5084            } else { 
     5085                @comments = @$comments; 
     5086            } 
    50705087            $no_resort = 1 
    50715088                unless $args->{sort_order} || $args->{sort_by}; 
     
    50915108            $args{'sort'} = 'created_on'; 
    50925109            $args{'direction'} = 'descend'; 
    5093             my $comments = $e->comments(\%terms, \%args); 
    5094             my $i = 0; 
     5110            my $cmts = $e->comments(\%terms, \%args); 
     5111            my $offset = $args->{offset} || 0; 
    50955112            if (@filters) { 
    5096                 COMMENTS: for my $c (@$comments) { 
     5113                my $i = 0; 
     5114                my $j = 0; 
     5115                my $offset = $args->{offset} || 0; 
     5116                COMMENTS: for my $c (@$cmts) { 
    50975117                    for (@filters) { 
    50985118                        next COMMENTS unless $_->($c); 
    50995119                    } 
     5120                    next if $offset && $j++ < $offset; 
    51005121                    push @comments, $c; 
    51015122                    last if $n && ( $n <= ++$i ); 
    51025123                } 
    5103             } elsif ($n) { 
    5104                 my $max = $n - 1 > $#$comments ? $#$comments : $n - 1; 
    5105                 @comments = @$comments[0..$max]; 
     5124            } elsif ($offset || $n) { 
     5125                if ($offset) { 
     5126                    if ($offset < scalar @$cmts - 1) { 
     5127                        @$cmts = @$cmts[$offset..(scalar @$cmts - 1)]; 
     5128                     } else { 
     5129                        @$cmts = (); 
     5130                    } 
     5131                } 
     5132                if ($n) { 
     5133                    my $max = $n - 1 > scalar @$cmts - 1 ? scalar @$cmts - 1 : $n - 1; 
     5134                    @$cmts = @$cmts[0..$max]; 
     5135                } 
     5136                @comments = @$cmts; 
    51065137            } else { 
    5107                 @comments = @$comments; 
     5138                @comments = @$cmts; 
    51085139            } 
    51095140        } else { 
     
    51145145            if (!@filters) { 
    51155146                $args{limit} = $n if $n; 
     5147                $args{offset} = $args->{offset} if $args->{offset}; 
    51165148                $args{join} = MT->model('entry')->join_on( 
    51175149                    undef, 
     
    51255157                my $iter = MT::Comment->load_iter(\%terms, \%args); 
    51265158                my %entries; 
     5159                my $j = 0; 
     5160                my $offset = $args->{offset} || 0; 
    51275161                COMMENT: while (my $c = $iter->()) { 
    51285162                    my $e = $entries{$c->entry_id} ||= $c->entry; 
     
    51325166                        next COMMENT unless $_->($c); 
    51335167                    } 
     5168                    next if $offset && $j++ < $offset; 
    51345169                    push @comments, $c; 
    51355170                    if ($n && (scalar @comments == $n)) { 
  • branches/release-35/php/lib/mtdb_base.php

    r1800 r1911  
    20042004        } 
    20052005 
    2006         $order = 'desc'; 
     2006        $order = $query_order = 'desc'; 
    20072007        if (isset($args['sort_order'])) { 
    20082008            if ($args['sort_order'] == 'ascend') { 
    2009                 $order = 'asc'; 
     2009                $order = $query_order = 'asc'; 
    20102010            } 
    20112011        } elseif (isset($blog) && isset($blog['blog_sort_order_comments'])) { 
    20122012            if ($blog['blog_sort_order_comments'] == 'ascend') { 
    2013                 $order = 'asc'; 
    2014             } 
    2015         } 
    2016         if ($order == 'asc' && $args['lastn']) { 
     2013                $order = $query_order = 'asc'; 
     2014            } 
     2015        } 
     2016        if ($order == 'asc' && (isset($args['lastn']) || isset($args['offset']))) { 
    20172017            $reorder = 1; 
    2018             $order = 'desc'; 
     2018            $query_order = 'desc'; 
    20192019        } 
    20202020 
     
    20412041            $limit = $args['limit']; 
    20422042        if (isset($args['offset'])) 
    2043             $limit = $args['offset']; 
     2043            $offset = $args['offset']; 
    20442044        if (count($filters)) { 
    20452045            $post_select_limit = $limit; 
     
    20582058                   $entry_filter 
    20592059                   $blog_filter 
    2060              order by comment_created_on $order 
     2060             order by comment_created_on $query_order 
    20612061                   <LIMIT>"; 
    20622062        $sql = $this->apply_limit_sql($sql, $limit, $offset); 
     2063 
    20632064        # Fetch resultset 
    20642065        $result = $this->query_start($sql); 
     
    20662067 
    20672068        $comments = array(); 
     2069        $j = 0; 
    20682070        while (true) { 
    20692071            $e = $this->query_fetch(ARRAY_A); 
    2070             if ($offset && ($j++ < $offset)) continue; 
    20712072            if (!isset($e)) break; 
    20722073            if (count($filters)) { 
     
    20742075                    if (!$f($e, $ctx)) continue 2; 
    20752076                } 
     2077                if ($post_select_offset && ($j++ < $post_select_offset)) continue; 
     2078                if (($post_select_limit > 0) && (count($comments) >= $post_select_limit)) break; 
    20762079            } 
    20772080            $comments[] = $e; 
    2078             if (($limit > 0) && (count($comments) >= $limit)) break; 
    20792081        } 
    20802082 
     
    21242126            return array(); 
    21252127 
    2126         if ($reorder) {  // lastn and ascending sort 
     2128        if ($reorder && !isset($args['sort_by'])) {  // lastn and ascending sort 
    21272129            $asc_created_on = create_function('$a,$b', 'return strcmp($a["comment_created_on"], $b["comment_created_on"]);'); 
    21282130            usort($comments, $asc_created_on);