my $pager = Class::DBI::Pager::_pager("Memories::Photo",
Memories->config->{photos_per_page}, $page);
$r->{template_args}{pager} = $pager;
+ my @tags = map { $self->search(name => $_)->first } @{$r->args};
if (@{$r->args} > 1) { # This is actually an n-level search
- $self->multi_search($r);
+ my $sth = $self->multi_search(@tags);
+ $r->{template_args}{photos} = [ $r->{template_args}{pager}->sth_to_objects($sth) ];
+ $sth->finish;
+ $r->{template_args}{tags} = \@tags;
} else {
if (!$r->objects) {
- $tag = $self->search(name => $r->{args}->[0])->first;
+ $tag = $tags[0];
} else {
- $tag = $r->objects->[0]; # Should hardly happen
+ $tag = $r->objects->[0];
}
$r->{template_args}{tag} = $tag;
$r->{template_args}{tags} = [$tag]; # For selector
}
sub multi_search {
- my ($self, $r) = @_;
+ my ($self, @tags) = @_;
my $counter = "tagaaa";
- my @tags;
- for (@{$r->{args}}) {
- my $tag = $self->search(name => $_)->first;
+ my @stuff;
+ for my $tag (@tags) {
if (!$tag) { return }
- push @tags, { tag => $tag, id => $tag-> id, counter => $counter++ };
+ push @stuff, { tag => $tag, id => $tag->id, counter => $counter++ };
}
my $sql = "select photo.id as id, photo.title as title, uploader, uploaded, x, y
-from photo, ". (join ",", map{ "tagging ".$_->{counter} } @tags).
-" where ". (join " AND ", map { "$_->{counter}.tag=$_->{id} and photo.id = $_->{counter}.photo" } @tags);
+from photo, ". (join ",", map{ "tagging ".$_->{counter} } @stuff).
+" where ". (join " AND ", map { "$_->{counter}.tag=$_->{id} and photo.id
+= $_->{counter}.photo" } @stuff);
$sql .= " order by photo.uploaded desc";
my $sth = $self->db_Main->prepare($sql);
- $r->{template_args}{photos} = [ $r->{template_args}{pager}->sth_to_objects($sth) ];
- $sth->finish;
- $r->{template_args}{tags} = [ map { $_->{tag} } @tags ];
}
sub list :Exported {
FROM tagging
GROUP BY tag
ORDER BY count DESC
-LIMIT 50
+LIMIT 75
/);
__PACKAGE__->set_sql(all => qq/
SELECT id, tag, count(*) AS count