root/branches/release-32/lib/MT/ArchiveType.pm @ 1618

Revision 1618, 4.2 kB (checked in by takayama, 20 months ago)

Fixed BugId:70976 BugId:70966, BugId:69874
* Applied ogawa-san's patch.

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;
8
9use strict;
10use MT::WeblogPublisher;
11
12sub new {
13    my $pkg  = shift;
14    my $self = {@_};
15    bless $self, $pkg;
16}
17
18sub _getset {
19    my $self = shift;
20    my $name = shift;
21    @_ ? $self->{$name} = $_[0] : $self->{$name};
22}
23
24sub _getset_coderef {
25    my ($obj, $key, @param) = @_;
26    # We only do this weird thing for MT::ArchiveType, which for MT 4
27    # allowed assignment of a coderef to the base MT::ArchiveType class.
28    # With MT 4.2 and later, this routine should be overridden by a
29    # subclass, and therefore, shouldn't do anything by itself.
30    if (ref($obj) eq __PACKAGE__) {
31        if (@param && ref($param[0]) eq 'CODE') {
32            $obj->_getset( $key, @param );
33            return;
34        }
35        if (my $code = $obj->_getset($key)) {
36            return $code->(@param);
37        }
38    }
39    return;
40}
41
42sub name { shift->_getset( 'name', @_ ) }
43
44# The base class routine should handle coderef assignment
45# calling date_range with other parameters invokes this routine
46# and returns the result
47sub archive_group_iter {
48    shift->_getset_coderef( 'archive_group_iter', @_ );
49}
50sub archive_group_entries {
51    shift->_getset_coderef( 'archive_group_entries', @_ );
52}
53sub archive_file {
54    shift->_getset_coderef( 'archive_file', @_ );
55}
56sub archive_title {
57    shift->_getset_coderef( 'archive_title', @_ );
58}
59sub archive_label {
60    shift->_getset_coderef( 'archive_label', @_ );
61}
62# sub date_range {
63#     shift->_getset_coderef( 'date_range', @_ );
64# }
65
66sub group_based {
67    my $obj = shift;
68    if (ref($obj) eq __PACKAGE__) {
69        return $obj->_getset( 'archive_group_entries' ) ? 1 : 0;
70    }
71    return 0;
72}
73
74sub default_archive_templates {
75    shift->_getset( 'default_archive_templates', @_ );
76}
77sub dynamic_template { shift->_getset( 'dynamic_template', @_ ) }
78sub entry_class      { shift->_getset( 'entry_class',      @_ ) || 'entry' }
79sub category_class   { shift->_getset( 'category_class',   @_ ) || 'category' }
80sub template_params  { shift->_getset('template_params') }
81
82sub dynamic_support  {
83    my $obj = shift;
84    if (ref $obj ne __PACKAGE__) {
85        return 1; # assume support unless overridden
86    }
87    $obj->_getset( 'dynamic_support',  @_ );
88}
89
90sub category_based {
91    my $obj = shift;
92    if (ref $obj ne __PACKAGE__) {
93        return $obj->isa('MT::ArchiveType::Category');
94    }
95    return $obj->_getset('category_based', @_);
96}
97
98sub entry_based {
99    my $obj = shift;
100    if (ref $obj ne __PACKAGE__) {
101        return $obj->isa('MT::ArchiveType::Individual');
102    }
103    return $obj->_getset('entry_based', @_);
104}
105
106sub date_based {
107    my $obj = shift;
108    if (ref $obj ne __PACKAGE__) {
109        return $obj->isa('MT::ArchiveType::Date');
110    }
111    return $obj->_getset('date_based', @_);
112}
113
114sub author_based {
115    my $obj = shift;
116    if (ref $obj ne __PACKAGE__) {
117        return $obj->isa('MT::ArchiveType::Author');
118    }
119    return $obj->_getset('author_based', @_);
120}
121
122sub archive_entries_count {
123    my $self = shift;
124
125    return $self->_getset_coderef( 'archive_entries_count', @_ )
126        if ref($self) eq __PACKAGE__;
127
128    my ($params) = @_;
129    my $blog     = $params->{Blog};
130    my $at       = $params->{ArchiveType};
131    my $ts       = $params->{Timestamp};
132    my $cat      = $params->{Category};
133    my $auth     = $params->{Author};
134    my ( $start, $end );
135    if ($ts) {
136        my $archiver = MT->publisher->archiver($at);
137        ( $start, $end ) = $archiver->date_range($ts) if $archiver;
138    }
139
140    my $count = MT->model('entry')->count(
141        {
142            blog_id => $blog->id,
143            status  => MT::Entry::RELEASE(),
144            ( $ts ? ( authored_on => [ $start, $end ] ) : () ),
145            ( $auth ? ( author_id => $auth->id ) : () ),
146        },
147        {
148            ( $ts ? ( range_incl => { authored_on => 1 } ) : () ),
149            (
150                $cat
151                ? (
152                    'join' => [
153                        'MT::Placement', 'entry_id',
154                        { category_id => $cat->id }
155                    ]
156                  )
157                : ()
158            ),
159        }
160    );
161    return $count;
162}
163
1641;
Note: See TracBrowser for help on using the browser.