Changeset 454

Show
Ignore:
Timestamp:
05/12/08 13:12:59 (2 months ago)
Author:
ogawa
Message:

Add next_archive_entry and previous_archive_entry for MT 4.15.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • FiscalYearlyArchives/trunk/FiscalYearlyArchives/fiscal_yearly_archives.pl

    r427 r454  
    5050                    archive_title => \&archive_title, 
    5151                    date_range => \&date_range, 
     52                    next_archive_entry => \&next_archive_entry, 
     53                    previous_archive_entry => \&previous_archive_entry, 
    5254                    archive_group_iter => \&archive_group_iter, 
    5355                    archive_group_entries => \&archive_group_entries, 
     
    164166sub date_range { start_end_fiscal_year(@_) } 
    165167 
     168sub next_archive_entry     { _adjacent_archive_entry(@_, 'next'    ) } 
     169sub previous_archive_entry { _adjacent_archive_entry(@_, 'previous') } 
     170 
     171sub _adjacent_archive_entry { 
     172    my ( $param, $order ) = @_; 
     173 
     174    $order   = ( $order eq 'previous' ) ? 'descend' : 'ascend'; 
     175    my $ts      = $param->{ts}; 
     176    my $blog_id = $param->{blog_id} || ($param->{blog} ? $param->{blog}->id : undef); 
     177 
     178    # if $param->{entry} given, override $ts and $blog_id. 
     179    if (my $e = $param->{entry}) { 
     180        $ts      = $e->authored_on; 
     181        $blog_id = $e->blog_id; 
     182    } 
     183    my ( $start, $end ) = start_end_fiscal_year($ts); 
     184    $ts = ( $order eq 'descend' ) ? $start : $end; 
     185 
     186    my $entry = MT::Entry->load({ 
     187        status  => MT::Entry::RELEASE(), 
     188        $blog_id ? ( blog_id   => $blog_id    ) : (), 
     189    }, { 
     190        limit     => 1, 
     191        'sort'    => 'authored_on', 
     192        direction => $order, 
     193        start_val => $ts, 
     194    }); 
     195    $entry; 
     196} 
     197 
    166198sub archive_group_iter { 
    167199    my ($ctx, $args) = @_;