root/branches/release-33/lib/MT/ArchiveType/Category.pm @ 1741

Revision 1741, 4.5 kB (checked in by bsmith, 20 months ago)

bugzid:75115 - remove 'main_template' variable

Line 
1# Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd.
2# This program is distributed under the terms of the
3# GNU General Public License, version 2.
4#
5# $Id$
6
7package MT::ArchiveType::Category;
8
9use strict;
10use base qw( MT::ArchiveType );
11
12sub name {
13    return 'Category';
14}
15
16sub archive_label {
17    return MT->translate("CATEGORY_ADV");
18}
19
20sub dynamic_template {
21    return 'category/<$MTCategoryID$>';
22}
23
24sub default_archive_templates {
25    return [
26        {
27            label => MT->translate('category/sub-category/index.html'),
28            template => '%-c/%i',
29            default  => 1
30        },
31        {
32            label => MT->translate('category/sub_category/index.html'),
33            template => '%c/%i'
34        }
35    ];
36}
37
38sub template_params {
39    return {
40        archive_class                      => "category-archive",
41        category_archive                   => 1,
42        archive_template                   => 1,
43        archive_listing                    => 1,
44        'module_category-monthly_archives' => 1,
45    };
46}
47
48sub archive_title {
49    my $obj = shift;
50    my ($ctx) = @_;
51    my $c = $ctx->stash('category');
52    $c ? $c->label : '';
53}
54
55sub archive_file {
56    my $obj = shift;
57    my ( $ctx, %param ) = @_;
58    my $timestamp = $param{Timestamp};
59    my $file_tmpl = $param{Template};
60    my $blog      = $ctx->{__stash}{blog};
61    my $cat       = $ctx->{__stash}{category};
62    my $entry     = $ctx->{__stash}{entry};
63    my $file;
64
65    my $this_cat = $cat ? $cat : ( $entry ? $entry->category : undef );
66    if ($file_tmpl) {
67        $ctx->stash( 'archive_category', $this_cat );
68        $ctx->{inside_mt_categories} = 1;
69        $ctx->{__stash}{category} = $this_cat;
70    }
71    else {
72        if ( !$this_cat ) {
73            return "";
74        }
75        my $label = '';
76        $label = dirify( $this_cat->label );
77        if ( $label !~ /\w/ ) {
78            $label = $this_cat ? "cat" . $this_cat->id : "";
79        }
80        $file = sprintf( "%s/index", $this_cat->category_path );
81    }
82    $file;
83}
84
85sub archive_group_iter {
86    my $obj = shift;
87    my ( $ctx, $args ) = @_;
88
89    my $blog_id = $ctx->stash('blog')->id;
90    require MT::Category;
91    my $iter = MT::Category->load_iter( { blog_id => $blog_id },
92        { 'sort' => 'label', direction => 'ascend' } );
93    require MT::Placement;
94    require MT::Entry;
95
96    return sub {
97        while ( my $c = $iter->() ) {
98            my @arguments = (
99                {
100                    blog_id => $blog_id,
101                    status  => MT::Entry::RELEASE()
102                },
103                {
104                    'join' => [
105                        'MT::Placement', 'entry_id', { category_id => $c->id }
106                    ]
107                }
108            );
109            my $count = MT::Entry->count( @arguments );
110            next unless $count || $args->{show_empty};
111            return ( $count, category => $c );
112        }
113        undef;
114      }
115}
116
117sub archive_group_entries {
118    my $obj = shift;
119    my ( $ctx, %param ) = @_;
120    my $limit = $param{limit};
121    if ( $limit && ($limit eq 'auto') ) {
122        my $blog = $ctx->stash('blog');
123        $limit = $blog->entries_on_index if $blog;
124    }
125    my $c = $ctx->stash('archive_category') || $ctx->stash('category');
126    require MT::Entry;
127    my @entries = MT::Entry->load(
128        { status => MT::Entry::RELEASE() },
129        {
130            join => [
131                'MT::Placement', 'entry_id',
132                { category_id => $c->id }, { unqiue => 1 }
133            ],
134            'sort'      => 'authored_on',
135            'direction' => 'descend',
136            ( $limit ? ( 'limit' => $limit ) : () ),
137        }
138    );
139    \@entries;
140}
141
142sub archive_entries_count {
143    my $obj = shift;
144    my ( $blog, $at, $entry ) = @_;
145    return $obj->SUPER::archive_entries_count(@_) unless $entry;
146    my $cat = $entry->category;
147    return 0 unless $cat;
148    return $obj->SUPER::archive_entries_count(
149        {
150            Blog        => $blog,
151            ArchiveType => $at,
152            Category    => $cat
153        }
154    );
155}
156
157sub display_name {
158    my $archiver = shift;
159    my $ctx      = shift;
160    my $tmpl     = $ctx->stash('template');
161    my $cat      = '';
162    if (   !$tmpl
163        || $tmpl->type eq 'index'
164        || !$archiver
165        || ( $archiver && !$archiver->category_based )
166        || !$ctx->{inside_archive_list} )
167    {
168        $cat = $ctx->stash('archive_category') || $ctx->stash('category');
169        $cat = $cat ? $cat->label . ': ' : '';
170    }
171    return $cat;
172}
173
174sub group_based {
175    return 1;
176}
177
1781;
Note: See TracBrowser for help on using the browser.