]> git.decadent.org.uk Git - memories.git/blobdiff - Memories/Photo.pm
Quarantine non-tagged photos. Closes #14.
[memories.git] / Memories / Photo.pm
index e2175c5ca80737387fae96525b7f4e559369a8b5..b48c69abd4b195b5bb349557cb7ccf527ae26ed1 100644 (file)
@@ -48,18 +48,50 @@ sub do_upload :Exported {
     my ($self, $r) = @_;
     my $upload = $r->{ar}->upload("photo");
     # Check $self->type
-    my @photos = $self->upload_jpeg($upload->tempname, ($r->params->{title}||basename($upload->filename)), $r->params->{tags}, $r);
+    my @photos = ($self->upload_jpeg($upload->tempname, ($r->params->{title}||basename($upload->filename)), $r->params->{tags}, $r));
     my @quarantined = grep { !$_->tags } @photos;
+    warn "Quarantined these photos: ".join(",", map {$_->id} @quarantined);
     # Set it up to go again
+    if (@quarantined) { 
+        $r->{session}{quarantined} = join ",", sort map { $_->id} @quarantined;
+        warn "Setting quarantineined to: ".( join ",", sort map { $_->id} @quarantined);
+        $r->objects(\@quarantined);
+        $r->template("quarantine");
+        return;
+    }
     $r->objects(\@photos);
-    $r->template("view");
+    if (@photos > 1) { $r->template("list") } 
+    else { $r->template("view"); }
     $r->message("Thanks for the upload!"); 
-    # Deal with the quarantined
+}
+
+sub quarantine :Exported {
+    my ($self, $r) = @_;
+    my @quarantined = split /,/, $r->{session}{quarantined};
+    my %q = map { $_ => 1 } @quarantined;
+    warn "Before we had these quarantined: @{[ keys %q ]}";
+    for (map /(\d+)/,grep /tags\d+/, keys %{$r->{params}}) {
+        my $tags = $r->{params}{"tags$_"};
+        warn "Got tags for $_: <$tags>";
+        next unless $tags;
+        if (my $photo = $self->retrieve($_)) {
+            $photo->add_tags($tags);
+            delete $q{$_};
+        }
+    }
+    $r->{session}{quarantined} = join ",", sort keys %q;
+    warn "After, we have these quarantined: @{[ keys %q ]}";
+    warn "And we set session to  $r->{session}{quarantined}";
+    if (!$r->{session}{quarantined}) {
+        $r->template("list");
+        $r->objects([ map { $self->retrieve($_) } @quarantined ]);
+    } else {
+        $r->objects([ map { $self->retrieve($_) } sort keys %q ]);
+    }
 }
 
 sub upload_jpeg {
     my ($self, $filename, $title, $tags, $r) = @_;
-    my $quarantine;
     my $photo = $self->create({
         uploader => $r->user,
         uploaded => Time::Piece->new(),