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 9358a7e..e3d4a80 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
 ";