1 package Blog
::Controller
::Tag
;
5 use base
'Catalyst::Controller';
12 my ( $self, $c ) = @_;
14 my $tags = $c->model( 'Tag' )->search(
15 select => [ 'id', 'name', \'COUNT
(t2
.tag_id
) AS map_count
' ],
16 sort_by => 'name ASC
',
18 with_objects => 'post_tag_map
'
22 my $cloud = HTML::TagCloud->new;
24 foreach my $tag ( @$tags ) {
25 $cloud->add( $tag->name, $c->uri_for( '/tag
', $tag->id ),
30 if ( $c->user_in_realm( 'admins
' ) ) {
31 $c->stash->{ empty_tags } = [ grep { $_->map_count == 0 } @$tags ];
34 $c->stash->{ cloud } = $cloud->html;
38 sub view : LocalRegex('^(\d
+)$') {
39 my ( $self, $c ) = @_;
41 my $tag = $c->model( 'Tag
' )->create( id => $c->req->captures->[ 0 ] );
42 $tag->load( speculative => 1 );
44 $self->throw_not_found( $c ) if $tag->not_found;
46 $c->stash->{ tag } = $tag;
48 my $posts = $tag->posts;
50 $c->stash->{ posts } = [ @$posts ];
53 sub delete : LocalRegex('^(\d
+)/delete$') {
54 my ( $self, $c ) = @_;
56 my $object = $c->model( 'Tag
' )->create( id => $c->req->captures->[ 0 ] );
57 $object->load( speculative => 1, select => [ 'id
' ] );
58 $self->throw_not_found( $c ) if $object->not_found;
62 $c->flash->{ msg } = $c->loc( 'Tag was deleted sucessfully
' );
64 $c->res->redirect( '/tag
' );
68 my ( $self, $c ) = @_;
70 $c->detach( '/default' );
79 This library is free software, you can redistribute it and/or modify
80 it under the same terms as Perl itself.