]> git.decadent.org.uk Git - memories.git/blobdiff - Memories/Tag.pm
Merged upstream v1.2.
[memories.git] / Memories / Tag.pm
index bcaa6c04437e06ff57c1a2c585180f6dc36b4e2a..e1afdd2f544715c613c9e7a44742c04084055ed0 100644 (file)
@@ -20,14 +20,18 @@ sub view :Exported {
     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
@@ -37,23 +41,20 @@ sub view :Exported {
 }
 
 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 {
@@ -81,7 +82,7 @@ SELECT  id, tag, count(*) AS count
 FROM tagging
 GROUP BY tag
 ORDER BY count DESC
-LIMIT 50
+LIMIT 75
     /);
 __PACKAGE__->set_sql(all => qq/
 SELECT  id, tag, count(*) AS count