Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix my mess with the tags

  • Loading branch information...
commit 84feb2feb9b552692a63219b73f7a7c8db7894a1 1 parent 28a244f
@yanick authored
Showing with 13 additions and 22 deletions.
  1. +13 −21 lib/Galuga/Controller/Tag.pm
  2. +0 −1  root/tag/index.mason
View
34 lib/Galuga/Controller/Tag.pm
@@ -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  root/tag/index.mason
@@ -1,6 +1,5 @@
<%args>
@entries
-@tags
@selected_tags
</%args>
Please sign in to comment.
Something went wrong with that request. Please try again.