]> git.etc.gen.nz Git - picture-display.git/commitdiff
Allow specifying tags in the config file, default to Favorites.
authorAndrew Ruthven <andrew@etc.gen.nz>
Sun, 5 Oct 2008 08:37:28 +0000 (21:37 +1300)
committerAndrew Ruthven <andrew@etc.gen.nz>
Sun, 5 Oct 2008 08:37:28 +0000 (21:37 +1300)
lib/Display/Plugins/Photo/FSpot.pm

index 9358a7ecbb99f9ca963513d1af8658667be85ea2..e3d4a8070917b3ee428c6078b9febc4ace549f42 100644 (file)
@@ -25,7 +25,11 @@ sub find_photo {
   my $self = shift;
 
   $self->{'kernel'}->post('FSpotDB',
-    single => { sql => $self->{'sql'}, event => 'find_photo_result' }
+    single => {
+      sql          => $self->{'sql'},
+      placeholders => $self->{'tags'},
+      event        => 'find_photo_result',
+    }
   );
 }
 
@@ -59,7 +63,26 @@ SELECT uri
 FROM photos, photo_tags, tags
   WHERE photos.id = photo_tags.photo_id
   AND photo_tags.tag_id = tags.id
-  AND tags.name = 'Brooke'
+  ";
+
+  if (defined $self->{'config'}{'_config'}{'plugins'}{'FSpot'}{'tags'}) {
+    $self->{'tags'} = $self->{'config'}{'_config'}{'plugins'}{'FSpot'}{'tags'};
+
+    if (scalar (@{ $self->{'tags'} })) {
+      my $holders = "?, " x scalar(@{ $self->{'tags'} });
+      $holders =~ s/, $//;
+
+      $self->{'sql'} .= "AND tags.name IN ($holders)";
+    } else {
+      $self->{'sql'} .= "AND tags.name = '?'";
+    }
+
+    $self->{'tags'} = $self->{'config'}{'_config'}{'plugins'}{'FSpot'}{'tags'};
+  } else {
+    $self->{'sql'} .= "AND tags.name = 'Favorites'";  # Sigh
+  }
+
+  $self->{'sql'} .= "
 ORDER BY random()
 LIMIT 1
 ";