| MojoMojo documentation | Contained in the MojoMojo distribution. |
MojoMojo::Controller::Gallery - Page gallery.
See MojoMojo
Controller for page photo galleries.
Private action to return a 404 not found page.
Show a gallery page for the current node.
Show a gallery by a given tag. Will also show photos in the descendants of the page with the given tag.
Show a gallery photo page.
Show a picture in tag gallery.
Add a tag through form submit.
Add a tag to a page. Forwards to inline_tags.
Remove a tag from a page. Forwards to inline_tags.
AJAX method for updating picture descriptions inline.
AJAX method for updating picture titles inline.
Marcus Ramberg <mramberg@cpan.org>
This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.
| MojoMojo documentation | Contained in the MojoMojo distribution. |
package MojoMojo::Controller::Gallery; use strict; use parent 'Catalyst::Controller';
sub default : Private { my ( $self, $c ) = @_; $c->stash->{template} = 'message.tt'; $c->stash->{message} ||= $c->loc('Photo not found'); return ( $c->res->status(404) ); }
sub gallery : Path { my ( $self, $c, $page ) = @_; $c->stash->{template} = 'gallery.tt'; $c->stash->{pictures} = $c->model("DBIC::Photo")->search( { 'attachment.page' => $c->stash->{page}->id }, { page => $page || 1, join => [qw/attachment/], rows => 12, order_by => 'position' } ); }
sub by_tag : Local { my ( $self, $c, $tag, $page ) = @_; $tag = $c->model("DBIC::Tag")->search( tag => $tag )->next; if (not $tag) { $c->stash->{message} = $c->loc('Tag not found'); $c->detach('default'); } $c->stash->{template} = 'gallery.tt'; $c->stash->{tag} = $tag->tag; my $conditions = { 'tags.tag' => $tag->tag }; $$conditions{'attachment.page'} = [ map { $_->id } ( $c->stash->{page}->descendants, $c->stash->{page} ) ] unless length( $c->stash->{page}->path ) == 1; # root $c->stash->{pictures} = $c->model("DBIC::Photo")->search( $conditions, { join => [qw/attachment tags/], page => $page || 1, rows => 12, order_by => 'taken DESC' } ); }
sub photo : Global { my ( $self, $c, $photo ) = @_; $photo = $c->model("DBIC::Photo")->find($photo) or $c->detach('default'); $c->stash->{photo} = $photo; $c->forward('inline_tags'); $c->stash->{template} = 'gallery/photo.tt'; $c->stash->{next} = $photo->next_sibling; $c->stash->{prev} = $photo->previous_sibling; }
sub photo_by_tag : Global { my ( $self, $c, $tag, $photo ) = @_; $photo = $c->model("DBIC::Photo")->find($photo) or $c->detach('default'); $c->stash->{photo} = $photo; $c->stash->{tag} = $tag; $c->forward('inline_tags'); $c->stash->{template} = 'gallery/photo.tt'; $c->stash->{next} = $photo->next_by_tag($tag); $c->stash->{prev} = $photo->prev_by_tag($tag); }
sub submittag : Local { my ( $self, $c, $photo ) = @_; $c->forward( 'tag', [ $photo, $c->req->params->{tag} ] ); }
sub tag : Local { my ( $self, $c, $photo, $tagname ) = @_; ($tagname) = $tagname =~ m/([\w\s]+)/; foreach my $tag ( split m/\s/, $tagname ) { if ( $tag && !$c->model("DBIC::Tag")->search( photo => $photo, person => $c->user->obj->id, tag => $tag )->next() ) { $c->model("DBIC::Tag")->create( { photo => $photo, tag => $tag, person => $c->user->obj->id } ) if $photo; } } $c->stash->{photo} = $photo; $c->forward( 'inline_tags', [$tagname] ); }
sub untag : Local { my ( $self, $c, $photo, $tagname ) = @_; my $tag = $c->model("DBIC::Tag")->search( photo => $photo, person => $c->user->obj->id, tag => $tagname )->next(); $tag->delete() if $tag; $c->stash->{photo} = $photo; $c->forward( 'inline_tags', [$tagname] ); }
sub inline_tags : Local { my ( $self, $c, $highlight ) = @_; $c->stash->{template} = 'gallery/tags.tt'; $c->stash->{highlight} = $highlight; my $photo = $c->stash->{photo} || $c->req->params->{photo}; $photo = $c->model("DBIC::Photo")->find($photo) unless ref $photo; $c->stash->{photo} = $photo; if ( $c->user_exists ) { my @tags = $photo->others_tags( $c->user->obj->id ); $c->stash->{others_tags} = [@tags]; @tags = $photo->user_tags( $c->user->obj->id ); $c->stash->{taglist} = ' ' . join( ' ', map { $_->tag } @tags ) . ' '; $c->stash->{tags} = [@tags]; } else { $c->stash->{others_tags} = [ $photo->others_tags(undef) ]; } }
sub description : Local { my ( $self, $c, $photo ) = @_; my $img = $c->model("DBIC::Photo")->find($photo) or $c->detach('default'); if ( $c->req->param('update_value') ) { $img->description( $c->req->param('update_value') ); $img->update; } $c->res->body( $img->description ); }
sub title : Local { my ( $self, $c, $photo ) = @_; my $img = $c->model("DBIC::Photo")->find($photo) or $c->detach('default'); if ( $c->req->param('update_value') ) { $img->title( $c->req->param('update_value') ); $img->update; } $c->res->body( $img->title ); } sub tags : Local { my ( $self, $c, $tag ) = @_; $c->stash->{tags} = [ $c->model("DBIC::Tag")->by_photo ]; my $cloud = HTML::TagCloud->new(); foreach my $tag ( @{ $c->stash->{tags} } ) { $cloud->add( $tag->tag, $c->req->base . $c->stash->{path} . '.gallery/by_tag/' . $tag->tag . '/' . $tag->photo, $tag->refcount ); } $c->stash->{cloud} = $cloud; $c->stash->{template} = 'gallery/cloud.tt'; }
1;