Changeset 390
- Timestamp:
- 08/24/07 17:41:49 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
FiscalYearlyArchives/trunk/FiscalYearlyArchives/fiscal_yearly_archives.pl
r389 r390 61 61 dynamic_support => 1, 62 62 date_based => 1, 63 # ??? 63 64 template_params => { 64 65 datebased_only_archive => 1, … … 136 137 my $order = $sort_order eq 'ascend' ? 'asc' : 'desc'; 137 138 138 require MT::Entry; 139 my $iter = MT::Entry->count_group_by({ 139 my $iter = MT->model('entry')->count_group_by({ 140 140 blog_id => $blog->id, 141 141 status => MT::Entry::RELEASE(), 142 142 }, { 143 ## WRONG! WRONG! 144 group => ["extract(year from authored_on)"], 145 $args->{lastn} ? ( limit => $args->{lastn} ) : (), 146 sort => "extract(year from authored_on) $order", 143 group => ["extract(year from authored_on)", "extract(month from authored_on)"], 144 sort => "extract(year from authored_on) $order, extract(month from authored_on) $order", 147 145 }) 148 or return $ctx->error("Couldn't get yearly archive list"); 146 or return $ctx->error("Couldn't get FiscalYearly archive list"); 147 148 # dirrty! 149 my @count_groups; 150 my $prev_year; 151 while (my @row = $iter->()) { 152 my $ts = sprintf("%04d%02d%02d000000", $row[1], $row[2], 1); 153 my ($start, $end) = start_end_fiscal_year($ts); 154 my ($year) = unpack 'A4', $start; 155 if ($year == $prev_year) { 156 $count_groups[-1]->{count} += $row[0]; 157 } else { 158 push @count_groups, { 159 count => $row[0], 160 fiscal_year => $year, 161 start => $start, 162 end => $end, 163 }; 164 $prev_year = $year; 165 } 166 } 167 my $lastn = $args->{lastn}; 168 splice(@count_groups, $lastn) if $lastn; 149 169 150 170 return sub { 151 while (my @row = $iter->()) { 152 my $date = sprintf("%04d%02d%02d000000", $row[1], 1, 1); 153 my ($start, $end) = start_end_fiscal_year($date); 154 return ($row[0], year => $row[1], start => $start, end => $end); 171 while (my $group = shift(@count_groups)) { 172 return ($group->{count}, %$group); 155 173 } 156 174 undef; … … 160 178 sub archive_group_entries { 161 179 my ($ctx, %param) = @_; 162 my $ts = sprintf("%04d%02d%02d000000", $param{ year}, 4, 1)180 my $ts = sprintf("%04d%02d%02d000000", $param{fiscal_year}, 4, 1) 163 181 if %param; 164 182 my ($start, $end); … … 181 199 'direction' => 'descend', 182 200 }) 183 or return $ctx->error("Couldn't get Fiscal -Yeararchive list");201 or return $ctx->error("Couldn't get FiscalYearly archive list"); 184 202 \@entries; 185 203 } … … 187 205 sub archive_entries_count { 188 206 my ($params) = @_; 189 my $blog = $params->{Blog};190 my $at = $params->{ArchiveType};191 my $ts = $params->{Timestamp};192 my $cat = $params->{Category};193 my $auth = $params->{Author};207 my $blog = $params->{Blog}; 208 my $at = $params->{ArchiveType}; 209 my $ts = $params->{Timestamp}; 210 my $cat = $params->{Category}; 211 my $auth = $params->{Author}; 194 212 195 213 my ($start, $end); … … 200 218 blog_id => $blog->id, 201 219 status => MT::Entry::RELEASE(), 202 ( $ts ? ( authored_on => [ $start, $end ] ) : ()),203 ( $auth ? ( author_id => $auth->id ) : ()),220 ($ts ? (authored_on => [$start, $end]) : ()), 221 ($auth ? (author_id => $auth->id) : ()), 204 222 }, { 205 ( $ts ? ( range => { authored_on => 1 } ) : () ), 206 ( 207 $cat 208 ? ( 209 'join' => [ 210 'MT::Placement', 'entry_id', 211 { category_id => $cat->id } 212 ] 213 ) 214 : () 215 ), 216 } 217 ); 223 ($ts ? (range => { authored_on => 1 }) : ()), 224 ($cat ? ('join' => ['MT::Placement', 'entry_id', { category_id => $cat->id }]) : ()), 225 }); 218 226 $count; 219 227 }
