Add a counter for how much each equipment combination is used.
authorSteinar H. Gunderson <sesse@debian.org>
Mon, 26 Mar 2007 20:11:59 +0000 (22:11 +0200)
committerSteinar H. Gunderson <sesse@debian.org>
Mon, 26 Mar 2007 20:11:59 +0000 (22:11 +0200)
perl/Sesse/pr0n/Index.pm
templates/bilder.knatten.com/equipment-item [new file with mode: 0644]
templates/bilder.knatten.com/equipment-item-singular [new file with mode: 0644]
templates/default/equipment-item [new file with mode: 0644]
templates/default/equipment-item-singular [new file with mode: 0644]
templates/images.tg05.gathering.org/equipment-item [new file with mode: 0644]
templates/images.tg05.gathering.org/equipment-item-singular [new file with mode: 0644]
templates/skoyen.bilder.knatten.com/equipment-item [new file with mode: 0644]
templates/skoyen.bilder.knatten.com/equipment-item-singular [new file with mode: 0644]
templates/skoyen.bildereks.knatten.com/equipment-item [new file with mode: 0644]
templates/skoyen.bildereks.knatten.com/equipment-item-singular [new file with mode: 0644]

index f8f44048ff385a6bdfaa3ed5f506b84fcd8d0f7f..737eba6e7f908a42fa0cd7a57d225297ff919ee2 100644 (file)
@@ -155,14 +155,16 @@ sub handler {
                
                # Find the equipment used
                my $eq = $dbh->prepare('
-                       SELECT DISTINCT
+                       SELECT 
                                model.value AS model,
-                               coalesce(lens_spec.value, lens.value) AS lens
+                               coalesce(lens_spec.value, lens.value) AS lens,
+                               COUNT(*) AS num
                        FROM images i
                                LEFT JOIN exif_info model ON i.id=model.image
                                LEFT JOIN ( SELECT * FROM exif_info WHERE tag=\'Lens\' ) lens ON i.id=lens.image
                                LEFT JOIN ( SELECT * FROM exif_info WHERE tag=\'LensSpec\') lens_spec ON i.id=lens_spec.image
                        WHERE event=? AND model.tag=\'Model\'
+                       GROUP BY 1,2
                        ORDER BY 1,2')
                        or die "Couldn't prepare to find equipment: $!";
                $eq->execute($event)
@@ -175,8 +177,9 @@ sub handler {
                                #
                                # Some compact cameras seem to add lens info sometimes and not at other
                                # times; if we have seen a camera with at least one specific lens earlier,
-                               # just ignore entries without a lens.
+                               # just combine entries without a lens with the previous one.
                                #
+                               $equipment[$#equipment]->{'num'} += $ref->{'num'};
                                next;
                        }
                        push @equipment, $ref;
@@ -187,11 +190,14 @@ sub handler {
                if (scalar @equipment > 0) {
                        Sesse::pr0n::Templates::print_template($r, "equipment-start");
                        for my $e (@equipment) {
-                               $r->print("  <li>" . $e->{'model'});
-                               if (defined($e->{'lens'})) {
-                                       $r->print(", " . $e->{'lens'} . "</li>\n");
+                               my $eqspec = $e->{'model'};
+                               $eqspec .= ', ' . $e->{'lens'} if (defined($e->{'lens'}));
+
+                               # This isn't correct for all languages. Fix if we ever need to care. :-)
+                               if ($e->{'num'} == 1) {
+                                       Sesse::pr0n::Templates::print_template($r, "equipment-item-singular", { eqspec => $eqspec });
                                } else {
-                                       $r->print("</li>\n");
+                                       Sesse::pr0n::Templates::print_template($r, "equipment-item", { eqspec => $eqspec, num => $e->{'num'} });
                                }
                        }
                        Sesse::pr0n::Templates::print_template($r, "equipment-end");
diff --git a/templates/bilder.knatten.com/equipment-item b/templates/bilder.knatten.com/equipment-item
new file mode 100644 (file)
index 0000000..72ab8da
--- /dev/null
@@ -0,0 +1 @@
+  <li>%EQSPEC% (%NUM% bilder)</li>
diff --git a/templates/bilder.knatten.com/equipment-item-singular b/templates/bilder.knatten.com/equipment-item-singular
new file mode 100644 (file)
index 0000000..51e6465
--- /dev/null
@@ -0,0 +1 @@
+  <li>%EQSPEC% (ett bilde)</li>
diff --git a/templates/default/equipment-item b/templates/default/equipment-item
new file mode 100644 (file)
index 0000000..0e7e86d
--- /dev/null
@@ -0,0 +1 @@
+  <li>%EQSPEC% (%NUM% images)</li>
diff --git a/templates/default/equipment-item-singular b/templates/default/equipment-item-singular
new file mode 100644 (file)
index 0000000..b55a163
--- /dev/null
@@ -0,0 +1 @@
+  <li>%EQSPEC% (one image)</li>
diff --git a/templates/images.tg05.gathering.org/equipment-item b/templates/images.tg05.gathering.org/equipment-item
new file mode 100644 (file)
index 0000000..0e7e86d
--- /dev/null
@@ -0,0 +1 @@
+  <li>%EQSPEC% (%NUM% images)</li>
diff --git a/templates/images.tg05.gathering.org/equipment-item-singular b/templates/images.tg05.gathering.org/equipment-item-singular
new file mode 100644 (file)
index 0000000..b55a163
--- /dev/null
@@ -0,0 +1 @@
+  <li>%EQSPEC% (one image)</li>
diff --git a/templates/skoyen.bilder.knatten.com/equipment-item b/templates/skoyen.bilder.knatten.com/equipment-item
new file mode 100644 (file)
index 0000000..72ab8da
--- /dev/null
@@ -0,0 +1 @@
+  <li>%EQSPEC% (%NUM% bilder)</li>
diff --git a/templates/skoyen.bilder.knatten.com/equipment-item-singular b/templates/skoyen.bilder.knatten.com/equipment-item-singular
new file mode 100644 (file)
index 0000000..51e6465
--- /dev/null
@@ -0,0 +1 @@
+  <li>%EQSPEC% (ett bilde)</li>
diff --git a/templates/skoyen.bildereks.knatten.com/equipment-item b/templates/skoyen.bildereks.knatten.com/equipment-item
new file mode 100644 (file)
index 0000000..72ab8da
--- /dev/null
@@ -0,0 +1 @@
+  <li>%EQSPEC% (%NUM% bilder)</li>
diff --git a/templates/skoyen.bildereks.knatten.com/equipment-item-singular b/templates/skoyen.bildereks.knatten.com/equipment-item-singular
new file mode 100644 (file)
index 0000000..51e6465
--- /dev/null
@@ -0,0 +1 @@
+  <li>%EQSPEC% (ett bilde)</li>