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;
}
)->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;
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;
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;
$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 = '';
$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)) {
$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);