Add a "container_date" sort filter
authorJeff Godin <jgodin@tadl.org>
Fri, 16 May 2014 18:29:55 +0000 (14:29 -0400)
committerJeff Godin <jgodin@tadl.org>
Mon, 19 May 2014 15:19:02 +0000 (11:19 -0400)
Add a "container_date" sort filter

Limited to single bre containers only at this point.

Signed-off-by: Jeff Godin <jgodin@tadl.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm

index 3a7f367..2474a0d 100644 (file)
@@ -768,6 +768,10 @@ sub toSQL {
         $rank = "FIRST((SELECT create_date FROM biblio.record_entry rbr WHERE rbr.id = m.source))";
     } elsif ($sort_filter eq 'edit_date') {
         $rank = "FIRST((SELECT edit_date FROM biblio.record_entry rbr WHERE rbr.id = m.source))";
+    } elsif ($sort_filter eq 'container_date' && @{$$flat_plan{container_list}}) {
+        # Just the first container for now
+        my $container_id = $self->QueryParser->quote_value(@{$$flat_plan{container_list}}[0]);
+        $rank = "FIRST((SELECT create_time FROM container.biblio_record_entry_bucket_item cbrebi WHERE cbrebi.target_biblio_record_entry = m.source AND cbrebi.bucket = " . $container_id . "))";
     } else {
         # default to rel ranking
         $rank = $rel;
@@ -826,6 +830,7 @@ sub flatten {
     my $where = shift || '';
     my $with = '';
     my $uses_bre = 0;
+    my @container_list;
 
     my @rank_list;
     for my $node ( @{$self->query_nodes} ) {
@@ -1060,6 +1065,7 @@ sub flatten {
                     my $rec_field = 'ci.target_biblio_record_entry';
                     if ($class eq 'bre') {
                         $class = 'biblio_record_entry';
+                        push @container_list, $cid;
                     } elsif ($class eq 'acn') {
                         $class = 'call_number';
                         $rec_field = 'cn.record';
@@ -1172,7 +1178,7 @@ sub flatten {
     }
     warn "flatten(): full filter where => $where\n" if $self->QueryParser->debug;
 
-    return { rank_list => \@rank_list, from => $from, where => $where,  with => $with, uses_bre => $uses_bre };
+    return { rank_list => \@rank_list, from => $from, where => $where,  with => $with, uses_bre => $uses_bre, container_list => \@container_list };
 }