intelligent fix for scoped holdings
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 16 Jun 2006 14:07:42 +0000 (14:07 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 16 Jun 2006 14:07:42 +0000 (14:07 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@4650 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm
Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm

index e1c0d28..82a41c1 100644 (file)
@@ -166,6 +166,19 @@ sub entityize {
        return $stuff;
 }
 
+sub tree_walker {
+       my $tree = shift;
+       my $field = shift;
+       my $filter = shift;
+
+       my @things;
+       for my $v ( @{$tree->$field} ){
+               push @things, $filter->($v);
+               push @things, tree_walker($v, $field, $filter);
+       }
+       return @things
+}
+
 sub new_record_holdings {
        my $self = shift;
        my $client = shift;
@@ -187,6 +200,23 @@ sub new_record_holdings {
                }
        )->gather(1);
 
+       my $o_search = { shortname => $ou };
+       if (!$ou || $ou eq '-') {
+               $o_search = { parent_ou => undef };
+       }
+
+       my $orgs = $_storage->request(
+               "open-ils.cstore.direct.actor.org_unit.search",
+               $o_search,
+               { flesh         => 3,
+                 flesh_fields  => { aou        => [qw/children/] }
+               }
+       )->gather(1);
+
+       my @ou_ids = tree_walker($orgs, 'children', sub {shift->id});
+
+       $logger->debug("Searching for holdings at orgs [".join(',',@ou_ids)."]");
+
        my ($year,$month,$day) = reverse( (localtime)[3,4,5] );
        $year += 1900;
        $month += 1;
@@ -195,9 +225,12 @@ sub new_record_holdings {
 
        for my $cn (@{$tree->call_numbers}) {
 
-               if ($ou ne '-') {
-                       next unless grep {$_->circ_lib->shortname =~ /^$ou/} @{$cn->copies};
+               my $found = 0;
+               for my $c (@{$cn->copies}) {
+                       next unless grep {$c->circ_lib->id == $_} @ou_ids;
+                       $found = 1;
                }
+               next unless $found;
 
                (my $cn_class = $cn->class_name) =~ s/::/-/gso;
                $cn_class =~ s/Fieldmapper-//gso;
@@ -211,9 +244,7 @@ sub new_record_holdings {
                
                for my $cp (@{$cn->copies}) {
 
-                       if ($ou ne '-') {
-                               next unless $cp->circ_lib->shortname =~ /^$ou/;
-                       }
+                       next unless grep { $cp->circ_lib->id == $_ } @ou_ids;
 
                        (my $cp_class = $cp->class_name) =~ s/::/-/gso;
                        $cp_class =~ s/Fieldmapper-//gso;
index f376b0b..c017add 100644 (file)
@@ -626,19 +626,20 @@ sub opensearch_feed {
        $terms =~ s/'//go;
        my $term_copy = $terms;
 
+       my $complex_terms = 0;
        if ($terms eq 'help') {
                print $cgi->header(-type => 'text/html');
-               print <<HTML;
-<html>
- <head>
-  <title>just type something!</title>
- </head>
- <body>
-  <p>You are in a maze of dark, twisty stacks, all alike.</p>
- </body>
-</html>
-HTML
-       return Apache2::Const::OK;
+               print <<"               HTML";
+                       <html>
                       <head>
+                         <title>just type something!</title>
                       </head>
                       <body>
+                         <p>You are in a maze of dark, twisty stacks, all alike.</p>
                       </body>
+                       </html>
+               HTML
+               return Apache2::Const::OK;
        }
 
        my $cache_key = '';
@@ -651,6 +652,7 @@ HTML
                $cache_key .= $c . $term_copy;
                warn "searching for $c -> [$term_copy] via OS $version, response type $type";
                $term_copy = $t;
+               $complex_terms = 1;
        }
 
        if (!keys(%$searches)) {
@@ -706,7 +708,7 @@ HTML
        $feed->search($terms);
        $feed->class($class);
 
-       if (keys(%$searches) > 1) {
+       if ($complex_terms) {
                $feed->title("Search results for [$terms] at ".$org_unit->[0]->name);
        } else {
                $feed->title("Search results for [$class => $terms] at ".$org_unit->[0]->name);