]> git.decadent.org.uk Git - memories.git/blobdiff - Memories/Tag.pm
Ignore quilt's .pc directory
[memories.git] / Memories / Tag.pm
index bcaa6c04437e06ff57c1a2c585180f6dc36b4e2a..3354489cc661d3a15c9738dddb0687a7fecd669a 100644 (file)
@@ -5,10 +5,9 @@ __PACKAGE__->columns(Essential => qw/id name/);
 
 Memories::Photo->set_sql(sorted_by_tag => q/
 SELECT photo.id as id, title, uploader, uploaded, x, y
-FROM photo, tag, tagging
+FROM photo, tagging
 WHERE tagging.photo = photo.id
-    AND tagging.tag = tag.id
-    AND tag.id = ?
+    AND tagging.tag = ?
 ORDER BY photo.uploaded DESC
 /
 );
@@ -20,40 +19,42 @@ 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;
+        if (!@{$r->objects||[]}) {
+            $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
         $r->{template_args}{photos} =
             [$pager->search_sorted_by_tag($tag->id)];
     }
+    $r->last_search();
 }
 
 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 {
@@ -73,28 +74,14 @@ sub list_js :Exported {
 
 package Memories::Tagging;
 use base qw(Memories::DBI);
-use Class::DBI::Pager;
-__PACKAGE__->columns(TEMP => qw/count/);
-__PACKAGE__->columns(Essential => qw/id tag photo/);
-__PACKAGE__->set_sql(summary => qq/
-SELECT  id, tag, count(*) AS count
-FROM tagging
-GROUP BY tag
-ORDER BY count DESC
-LIMIT 50
-    /);
-__PACKAGE__->set_sql(all => qq/
-SELECT  id, tag, count(*) AS count
-FROM tagging
+
+
+__PACKAGE__->set_sql(user_summary => qq/
+SELECT  tagging.id id, tag, count(*) AS count
+FROM tagging, photo
+WHERE tagging.photo = photo.id AND photo.uploader = ?
 GROUP BY tag
 ORDER BY count DESC
-    /);
-Memories::Tagging->has_a("photo" => "Memories::Photo");
-Memories::Tagging->has_a("tag" => "Memories::Tag");
-
-Memories::Photo->has_many(tags => ["Memories::Tagging" => "tag"]);
-Memories::Photo->has_many(taggings => "Memories::Tagging");
-Memories::Tag->has_many(photos => ["Memories::Tagging" => "photo"] );
-Memories::Tag->has_many(taggings => "Memories::Tagging");
+/);
 
 1;