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>
Sun, 22 May 2016 03:56:10 +0000 (23:56 -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 ea55769..c801661 100644 (file)
@@ -845,6 +845,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 MAX(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;
@@ -908,6 +912,7 @@ sub flatten {
     my $uses_bre = 0;
     my $uses_mrd = 0;
     my $uses_mrv = 0;
+    my @container_list;
 
     my @rank_list;
     for my $node ( @{$self->query_nodes} ) {
@@ -1144,6 +1149,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';
@@ -1280,7 +1286,8 @@ sub flatten {
         with => $with,
         uses_bre => $uses_bre,
         uses_mrv => $uses_mrv,
-        uses_mrd => $uses_mrd
+        uses_mrd => $uses_mrd,
+        container_list => \@container_list
     };
 }