MojoMojo
view release on metacpan or search on metacpan
lib/MojoMojo/Controller/Gallery.pm view on Meta::CPAN
}
);
}
=head2 photo ( .photo/<id> )
Show a gallery photo page.
=cut
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;
}
=head2 ( /photo_by_tag/<id> )
Show a picture in tag gallery.
=cut
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);
}
=head2 submittag ( /gallery/submittag )
Add a tag through form submit.
=cut
sub submittag : Local {
my ( $self, $c, $photo ) = @_;
$c->forward( 'tag', [ $photo, $c->req->params->{tag} ] );
}
=head2 tag ( /.jsrpc/tag )
Add a tag to a page. Forwards to
L<< inline_tags|/inline_tags ( .gallery/tags ) >>.
=cut
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] );
}
=head2 untag ( .gallery/untag )
Remove a tag from a page. Forwards to
L<< inline_tags|/inline_tags ( .gallery/tags ) >>.
=cut
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] );
}
=head2 inline_tags ( .gallery/tags )
Make a list of the user's tags and popular tags, or just popular tags
if no user is logged in.
=cut
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 ) . ' ';
( run in 1.846 second using v1.01-cache-2.11-cpan-71847e10f99 )