Permalink
Browse files

fix my mess with the tags

  • Loading branch information...
1 parent 28a244f commit 84feb2feb9b552692a63219b73f7a7c8db7894a1 @yanick committed Mar 27, 2011
Showing with 13 additions and 22 deletions.
  1. +13 −21 lib/Galuga/Controller/Tag.pm
  2. +0 −1 root/tag/index.mason
@@ -27,33 +27,25 @@ sub index : Path : Args {
return unless @tags;
- my $tags = $c->model('DB::Tags')->search(
- {},
- { group_by => 'tag',
- select => [ 'tag', { count => 'entry_path' } ],
- as => [qw/ tag nbr_entries /],
- } );
-
- $c->stash->{tags} = [ $tags->all ];
-
$c->stash->{selected_tags} = [@tags];
- my @entries =
- $c->model('DB::Tags')->search( {} )->get_column('entry_path')->all;
+ my @entries;
+
+ if ( my $t = $c->model('DB::Tags')->find({label => shift @tags}) ) {
+ @entries = $t->search_related('entry_tags')->search_related('entry')->all;
+ }
while ( @tags and @entries ) {
- @entries = $c->model('DB::Tags')->search( {
- tag => shift @tags,
- entry_path => { IN => \@entries } }
- )->get_column('entry_path')->all;
+ my $tag = $c->model('DB::Tags')->find({label => shift @tags });
+ unless ( $tag ) {
+ @entries = ();
+ last;
+ };
+ @entries = grep { $_->count_related('entry_tags', { tag_id => $tag->id } ) }
+ @entries;
}
- $c->stash->{entries} = [
- $c->model('DB::Entries')->search(
- { path => { IN => \@entries } },
- { order_by => { '-desc' => 'created' } }
- )->all
- ];
+ $c->stash->{entries} = [ @entries ];
}
View
@@ -1,6 +1,5 @@
<%args>
@entries
-@tags
@selected_tags
</%args>

0 comments on commit 84feb2f

Please sign in to comment.