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

Implemented BugId:72216
* Implemented offset attribute to MTComments

Files:
1 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)) {