From: Bill Erickson <berick@esilibrary.com>
Date: Wed, 15 Feb 2012 20:33:29 +0000 (-0500)
Subject: Copy Location Search Groups : location_groups() QP filter
X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=fb1a10e370bf708b1f4fb1c59dc029ed75a85d94;p=evergreen%2Fmasslnc.git

Copy Location Search Groups : location_groups() QP filter

Adds a new QueryParser search filter "location_groups" which takes a
list of asset.copy_location_group IDs and filters on the mapped copy
locations.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Dan Scott <dan@coffeecode.net>
---

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
index c38f5741e7..f88affe468 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm
@@ -422,6 +422,7 @@ __PACKAGE__->add_search_filter( 'during' );
 # used by layers above this
 __PACKAGE__->add_search_filter( 'statuses' );
 __PACKAGE__->add_search_filter( 'locations' );
+__PACKAGE__->add_search_filter( 'location_groups' );
 __PACKAGE__->add_search_filter( 'site' );
 __PACKAGE__->add_search_filter( 'lasso' );
 __PACKAGE__->add_search_filter( 'my_lasso' );
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm
index a5cb550b2f..eb2602a0ae 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/metabib.pm
@@ -2992,6 +2992,22 @@ sub query_parser_fts {
         @location = @{$filter->args} if (@{$filter->args});
     }
 
+    # gather location_groups
+    if (my ($filter) = $query->parse_tree->find_filter('location_groups')) {
+        my @loc_groups = @{$filter->args} if (@{$filter->args});
+        
+        # collect the mapped locations and add them to the locations() filter
+        if (@loc_groups) {
+
+            my $cstore = OpenSRF::AppSession->create( 'open-ils.cstore' );
+            my $maps = $cstore->request(
+                'open-ils.cstore.direct.asset.copy_location_group_map.search.atomic',
+                {lgroup => \@loc_groups})->gather(1);
+
+            push(@location, $_->location) for @$maps;
+        }
+    }
+
 
     my $param_check = $limit || $query->superpage_size || 'NULL';
     my $param_offset = $offset || 'NULL';
@@ -3183,7 +3199,7 @@ sub query_parser_fts_wrapper {
         if ( ref($args{between}) and @{$args{between}} == 2 and $args{between}[0] =~ /^\d+$/ and $args{between}[1] =~ /^\d+$/ );
 
 
-	my (@between,@statuses,@locations,@types,@forms,@lang,@aud,@lit_form,@vformats,@bib_level);
+	my (@between,@statuses,@locations,@location_groups,@types,@forms,@lang,@aud,@lit_form,@vformats,@bib_level);
 
 	# XXX legacy format and item type support
 	if ($args{format}) {
@@ -3192,7 +3208,7 @@ sub query_parser_fts_wrapper {
 		$args{item_form} = [ split '', $f ];
 	}
 
-    for my $filter ( qw/locations statuses between audience language lit_form item_form item_type bib_level vr_format/ ) {
+    for my $filter ( qw/locations location_groups statuses between audience language lit_form item_form item_type bib_level vr_format/ ) {
     	if (my $s = $args{$filter}) {
     		$s = [$s] if (!ref($s));