Changeset 1379

Show
Ignore:
Timestamp:
02/19/08 09:24:26 (5 months ago)
Author:
auno
Message:

Fixed to get entries in a category using limit attribute. BugzID:68474

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/release-30/lib/MT/Template/ContextHandlers.pm

    r1367 r1379  
    34593459     
    34603460    my $cfg = $ctx->{config}; 
     3461    my $at = $ctx->{current_archive_type} || $ctx->{archive_type}; 
     3462    my $archiver = MT->publisher->archiver($at); 
     3463    if ( $archiver && $archiver->archive_group_entries ) { 
     3464        my $entries = $archiver->archive_group_entries->( $ctx, %$args ); 
     3465        $ctx->stash( 'entries', $entries ); 
     3466    } 
    34613467    my $entries = $ctx->stash('entries'); 
    34623468    my $blog_id = $ctx->stash('blog_id'); 
  • branches/release-30/lib/MT/WeblogPublisher.pm

    r1372 r1379  
    14441444    { 
    14451445        if ( $archiver->archive_group_entries ) { 
    1446  
    1447             # TBD: Would it help to use MT::Promise here? 
    1448             my $entries = $archiver->archive_group_entries->($ctx); 
    1449             $ctx->stash( 'entries', $entries ); 
     1446            require MT::Promise; 
     1447            my $entries = sub { $archiver->archive_group_entries->($ctx) }; 
     1448            $ctx->stash( 'entries', MT::Promise::delay($entries) ); 
    14501449        } 
    14511450 
     
    23342333sub yearly_group_entries { 
    23352334    my ( $ctx, %param ) = @_; 
    2336     date_based_group_entries( $ctx, 'Yearly', 
    2337         %param ? sprintf( "%04d%02d%02d000000", $param{year}, 1, 1 ) : undef ); 
     2335    my $ts = 
     2336        $param{year} 
     2337    ? sprintf( "%04d%02d%02d000000", $param{year}, 1, 1 ) 
     2338        : undef; 
     2339    my $limit = $param{limit}; 
     2340    date_based_group_entries( $ctx, 'Yearly', $ts, $limit ); 
    23382341} 
    23392342 
     
    24312434sub monthly_group_entries { 
    24322435    my ( $ctx, %param ) = @_; 
    2433     date_based_group_entries( $ctx, 'Monthly', 
    2434         %param 
    2435         ? sprintf( "%04d%02d%02d000000", $param{year}, $param{month}, 1 ) 
    2436         : undef ); 
     2436    my $ts = 
     2437        $param{year} 
     2438    ? sprintf( "%04d%02d%02d000000", $param{year}, $param{month}, 1 ) 
     2439        : undef; 
     2440    my $limit = $param{limit}; 
     2441    date_based_group_entries( $ctx, 'Monthly', $ts, $limit ); 
    24372442} 
    24382443 
     
    25202525sub category_group_entries { 
    25212526    my ( $ctx, %param ) = @_; 
    2522  
     2527    my $limit = $param{limit}; 
     2528    if ( $limit eq 'auto' ) { 
     2529        my $blog = $ctx->stash('blog'); 
     2530        $limit = $blog->entries_on_index if $blog; 
     2531    } 
    25232532    my $c = $ctx->stash('archive_category') || $ctx->stash('category'); 
    25242533    require MT::Entry; 
     
    25302539                { category_id => $c->id }, { unqiue => 1 } 
    25312540            ], 
    2532             'sort' => 'authored_on', 
     2541            'sort'      => 'authored_on', 
    25332542            'direction' => 'descend', 
     2543            ( $limit ? ( 'limit' => $limit ) : () ), 
    25342544        } 
    25352545    ); 
     
    27392749sub daily_group_entries { 
    27402750    my ( $ctx, %param ) = @_; 
    2741     date_based_group_entries( 
    2742         $ctx, 'Daily', 
    2743         %param 
    2744         ? sprintf( "%04d%02d%02d000000", 
    2745             $param{year}, $param{month}, $param{day} ) 
    2746         : undef 
    2747     ); 
     2751    my $ts = 
     2752        $param{year} 
     2753    ? sprintf( "%04d%02d%02d000000", $param{year}, $param{month}, 
     2754               $param{day} ) 
     2755        : undef; 
     2756    my $limit = $param{limit}; 
     2757    date_based_group_entries( $ctx, 'Daily', $ts, $limit ); 
    27482758} 
    27492759 
     
    28392849sub weekly_group_entries { 
    28402850    my ( $ctx, %param ) = @_; 
    2841     date_based_group_entries( 
    2842         $ctx, 'Weekly', 
    2843         %param 
    2844         ? sprintf( "%04d%02d%02d000000", 
    2845             week2ymd( $param{year}, $param{week} ) ) 
    2846         : undef 
    2847     ); 
     2851    my $ts = 
     2852        $param{year} 
     2853    ? sprintf( "%04d%02d%02d000000", week2ymd( $param{year}, $param{week} ) ) 
     2854        : undef; 
     2855    my $limit = $param{limit}; 
     2856    date_based_group_entries( $ctx, 'Weekly', $ts, $limit ); 
    28482857} 
    28492858 
     
    28982907 
    28992908sub date_based_group_entries { 
    2900     my ( $ctx, $at, $ts ) = @_; 
     2909    my ( $ctx, $at, $ts, $limit ) = @_; 
    29012910    my $blog = $ctx->stash('blog'); 
    29022911    my ( $start, $end ); 
     
    29252934            'sort' => 'authored_on', 
    29262935            'direction' => 'descend', 
     2936            ( $limit ? ( 'limit' => $limit ) : () ), 
    29272937        } 
    29282938    ) or return $ctx->error("Couldn't get $at archive list"); 
     
    30023012    my $blog = $ctx->stash('blog'); 
    30033013    my $a = $param{author} || $ctx->stash('author'); 
     3014    my $limit = $param{limit}; 
     3015    if ( $limit eq 'auto' ) { 
     3016        my $blog = $ctx->stash('blog'); 
     3017        $limit = $blog->entries_on_index if $blog; 
     3018    } 
    30043019    return [] unless $a; 
    30053020    require MT::Entry; 
     
    30133028            'sort'      => 'authored_on', 
    30143029            'direction' => 'descend', 
     3030            ( $limit ? ( 'limit' => $limit ) : () ), 
    30153031        } 
    30163032    ); 
     
    32013217    my ( $ctx, %param ) = @_; 
    32023218    my $ts = 
    3203       %param 
    3204       ? sprintf( "%04d%02d%02d000000", $param{year}, 1, 1 ) 
    3205       : $ctx->stash('current_timestamp'); 
    3206     my $author = %param ? $param{author} : $ctx->stash('author'); 
    3207     date_based_author_entries( $ctx, 'Author-Yearly', $author, $ts ); 
     3219        $param{year} 
     3220    ? sprintf( "%04d%02d%02d000000", $param{year}, 1, 1 ) 
     3221        : $ctx->stash('current_timestamp'); 
     3222    my $author = $param{author} || $ctx->stash('author'); 
     3223    my $limit = $param{limit}; 
     3224    date_based_author_entries( $ctx, 'Author-Yearly', $author, $ts, $limit ); 
    32083225} 
    32093226 
     
    33843401    my ( $ctx, %param ) = @_; 
    33853402    my $ts = 
    3386       %param 
    3387       ? sprintf( "%04d%02d%02d000000", $param{year}, $param{month}, 1 ) 
    3388       : $ctx->stash('current_timestamp'); 
    3389     my $author = %param ? $param{author} : $ctx->stash('author'); 
    3390     date_based_author_entries( $ctx, 'Author-Monthly', $author, $ts ); 
     3403        $param{year} 
     3404    ? sprintf( "%04d%02d%02d000000", $param{year}, $param{month}, 1 ) 
     3405        : $ctx->stash('current_timestamp'); 
     3406    my $author = $param{author} || $ctx->stash('author'); 
     3407    my $limit = $param{limit}; 
     3408    date_based_author_entries( $ctx, 'Author-Monthly', $author, $ts, $limit ); 
    33913409} 
    33923410 
     
    35653583    my ( $ctx, %param ) = @_; 
    35663584    my $ts = 
    3567       %param 
    3568       ? sprintf( "%04d%02d%02d000000", week2ymd( $param{year}, $param{week} ) ) 
    3569       : $ctx->stash('current_timestamp'); 
    3570     my $author = %param ? $param{author} : $ctx->stash('author'); 
    3571     date_based_author_entries( $ctx, 'Author-Weekly', $author, $ts ); 
     3585        $param{year} 
     3586    ? sprintf( "%04d%02d%02d000000", week2ymd( $param{year}, $param{week} ) ) 
     3587        : $ctx->stash('current_timestamp'); 
     3588    my $author = $param{author} || $ctx->stash('author'); 
     3589    my $limit = $param{limit}; 
     3590    date_based_author_entries( $ctx, 'Author-Weekly', $author, $ts, $limit ); 
    35723591} 
    35733592 
     
    37543773    my ( $ctx, %param ) = @_; 
    37553774    my $ts = 
    3756       %param 
    3757       ? sprintf( "%04d%02d%02d000000", $param{year}, $param{month}, 
    3758         $param{day} ) 
    3759       : $ctx->stash('current_timestamp'); 
    3760     my $author = %param ? $param{author} : $ctx->stash('author'); 
    3761     date_based_author_entries( $ctx, 'Author-Daily', $author, $ts ); 
     3775        $param{year} 
     3776    ? sprintf( "%04d%02d%02d000000", $param{year}, $param{month}, 
     3777               $param{day} ) 
     3778        : $ctx->stash('current_timestamp'); 
     3779    my $author = $param{author} || $ctx->stash('author'); 
     3780    my $limit = $param{limit}; 
     3781    date_based_author_entries( $ctx, 'Author-Daily', $author, $ts, $limit ); 
    37623782} 
    37633783 
     
    39563976sub cat_yearly_group_entries { 
    39573977    my ( $ctx, %param ) = @_; 
    3958  
    39593978    my $ts = 
    3960       %param 
    3961       ? sprintf( "%04d%02d%02d000000", $param{year}, 1, 1 ) 
    3962       : $ctx->stash('current_timestamp'); 
    3963     my $cat = %param ? $param{category} : $ctx->stash('archive_category'); 
    3964  
    3965     date_based_category_entries( $ctx, 'Category-Yearly', $cat, $ts ); 
     3979        $param{year} 
     3980    ? sprintf( "%04d%02d%02d000000", $param{year}, 1, 1 ) 
     3981        : $ctx->stash('current_timestamp'); 
     3982    my $cat = $param{category} || $ctx->stash('archive_category'); 
     3983    my $limit = $param{limit}; 
     3984    date_based_category_entries( $ctx, 'Category-Yearly', $cat, $ts, $limit ); 
    39663985} 
    39673986 
     
    41244143sub cat_monthly_group_entries { 
    41254144    my ( $ctx, %param ) = @_; 
    4126  
    41274145    my $ts = 
    4128       %param 
    4129       ? sprintf( "%04d%02d%02d000000", $param{year}, $param{month}, 1 ) 
    4130       : $ctx->stash('current_timestamp'); 
    4131     my $cat = %param ? $param{category} : $ctx->stash('archive_category'); 
    4132  
    4133     date_based_category_entries( $ctx, 'Category-Monthly', $cat, $ts ); 
     4146        $param{year} 
     4147    ? sprintf( "%04d%02d%02d000000", $param{year}, $param{month}, 1 ) 
     4148        : $ctx->stash('current_timestamp'); 
     4149    my $cat = $param{category} || $ctx->stash('archive_category'); 
     4150    my $limit = $param{limit}; 
     4151    date_based_category_entries( $ctx, 'Category-Monthly', $cat, $ts, $limit ); 
    41344152} 
    41354153 
     
    42974315sub cat_daily_group_entries { 
    42984316    my ( $ctx, %param ) = @_; 
    4299  
    43004317    my $ts = 
    4301       %param 
    4302       ? sprintf( "%04d%02d%02d000000", $param{year}, $param{month}, 
    4303         $param{day} ) 
    4304       : $ctx->stash('current_timestamp'); 
    4305     my $cat = %param ? $param{category} : $ctx->stash('archive_category'); 
    4306  
    4307     date_based_category_entries( $ctx, 'Category-Daily', $cat, $ts ); 
     4318        $param{year} 
     4319    ? sprintf( "%04d%02d%02d000000", $param{year}, $param{month}, 
     4320               $param{day} ) 
     4321        : $ctx->stash('current_timestamp'); 
     4322    my $cat = $param{category} || $ctx->stash('archive_category'); 
     4323    my $limit = $param{limit}; 
     4324    date_based_category_entries( $ctx, 'Category-Daily', $cat, $ts, $limit ); 
    43084325} 
    43094326 
     
    44644481    my ( $ctx, %param ) = @_; 
    44654482    my $ts = 
    4466       %param 
    4467       ? sprintf( "%04d%02d%02d000000", week2ymd( $param{year}, $param{week} ) ) 
    4468       : $ctx->stash('current_timestamp'); 
    4469     my $cat = %param ? $param{category} : $ctx->stash('archive_category'); 
    4470  
    4471     date_based_category_entries( $ctx, 'Category-Weekly', $cat, $ts ); 
     4483        $param{year} 
     4484    ? sprintf( "%04d%02d%02d000000", week2ymd( $param{year}, $param{week} ) ) 
     4485        : $ctx->stash('current_timestamp'); 
     4486    my $cat = $param{category} || $ctx->stash('archive_category'); 
     4487    my $limit = $param{limit}; 
     4488    date_based_category_entries( $ctx, 'Category-Weekly', $cat, $ts, $limit ); 
    44724489} 
    44734490