__PACKAGE__->add_search_filter( 'location_groups' );
__PACKAGE__->add_search_filter( 'bib_source' );
__PACKAGE__->add_search_filter( 'badge_orgs' );
+__PACKAGE__->add_search_filter( 'badges' );
__PACKAGE__->add_search_filter( 'site' );
__PACKAGE__->add_search_filter( 'pref_ou' );
__PACKAGE__->add_search_filter( 'lasso' );
my $pubdate_join = "LEFT JOIN metabib.record_sorter pubdate_t ON m.source = pubdate_t.source AND attr = 'pubdate'";
+ my $badge_join = '';
+ my ($badge_filter) = $self->find_filter('badges');
+ if ($badge_filter && @{$badge_filter->args}) {
+ my $badges = join (',', grep /^\d+$/ @{$badge_filter->args});
+ if ($badges) {
+ $badge_join = "'INNER JOIN rating.record_badge_score badge ON m.source = badge.record AND badge.id = ANY ('{$badges}')";
+ }
+ }
+
my $bre_join = '';
if ($self->find_modifier('deleted')) {
$bre_join = 'INNER JOIN biblio.record_entry bre ON m.source = bre.id AND bre.deleted';
FIRST(pubdate_t.value) AS tie_break
FROM metabib.metarecord_source_map m
$$flat_plan{from}
- $pubdate_join
$mra_join
$mrv_join
$bre_join
- $lang_join
+ $badge_join
+ $pubdate_join
$pop_join
+ $lang_join
WHERE 1=1
$flat_where
GROUP BY 1
my $borgs = undef;
my $site = undef;
- my ($site_filter) = $base_plan->parse_tree->find_filter('site');
- if ($site_filter && @{$site_filter->args}) {
- $site = $top_org if ($site_filter->args->[0] eq '-');
- $site = $top_org if ($site_filter->args->[0] eq $top_org->shortname);
- $site = actor::org_unit->search( { shortname => $site_filter->args->[0] })->next unless ($site);
-
- } elsif ($args{org_unit}) {
- $site = $top_org if ($args{org_unit} eq '-');
- $site = $top_org if ($args{org_unit} eq $top_org->shortname);
- $site = actor::org_unit->search( { shortname => $args{org_unit} })->next unless ($site);
- }
-
- if ($site && $site->id <> $top_org->id) {
- my ($depth_filter) = $base_plan->parse_tree->find_filter('depth');
- my $depth = $depth_filter->args->[0] if ($depth_filter && $depth_filter->args->[0] =~ /^\d+$/);
- $depth = $args{depth} if (!defined($depth) && defined($args{depth}) && $args{depth} =~ /^\d+$/);
-
- if (defined $depth and $depth > 0) { # Not scoped to the top of the tree
- $borgs = OpenSRF::AppSession->create( 'open-ils.cstore' )->request(
- 'open-ils.cstore.json_query.atomic',
- { from => [ 'actor.org_unit_descendants', $site->id, $depth ] }
- )->gather(1);
- } else {
- $borgs = OpenSRF::AppSession->create( 'open-ils.cstore' )->request(
- 'open-ils.cstore.json_query.atomic',
- { from => [ 'actor.org_unit_descendants', $site->id ] }
- )->gather(1);
+ my @lg_id_list = @{$args{location_groups}} if (ref $args{location_groups});
+
+ my ($lg_filter) = $base_plan->parse_tree->find_filter('location_groups');
+ @lg_id_list = @{$lg_filter->args} if ($lg_filter && @{$lg_filter->args});
+
+ if (@lg_id_list) {
+ my @borg_list;
+ for my $lg ( grep { /^\d+$/ } @lg_id_list} ) {
+ my $lg_obj = asset::copy_location_group->retrieve($lg);
+ next unless $lg_obj;
+
+ if (''.$lg_obj->owner == $top_org->id) {
+ $borgs = undef;
+ last;
+ }
+
+ push(@borg_list, ''.$lg_obj->owner);
}
+ $borgs = join(',', @borg_list) if @borg_list;
+ }
- if (ref $borgs && @$borgs) {
- $borgs = join(',', map { $_->{'actor.org_unit_descendants'} } @$borgs);
- } else {
- $borgs = undef;
+ if (!$borgs) {
+ my ($site_filter) = $base_plan->parse_tree->find_filter('site');
+ if ($site_filter && @{$site_filter->args}) {
+ $site = $top_org if ($site_filter->args->[0] eq '-');
+ $site = $top_org if ($site_filter->args->[0] eq $top_org->shortname);
+ $site = actor::org_unit->search( { shortname => $site_filter->args->[0] })->next unless ($site);
+
+ } elsif ($args{org_unit}) {
+ $site = $top_org if ($args{org_unit} eq '-');
+ $site = $top_org if ($args{org_unit} eq $top_org->shortname);
+ $site = actor::org_unit->search( { shortname => $args{org_unit} })->next unless ($site);
+ }
+
+ if ($site && $site->id <> $top_org->id) {
+ my ($depth_filter) = $base_plan->parse_tree->find_filter('depth');
+ my $depth = $depth_filter->args->[0] if ($depth_filter && $depth_filter->args->[0] =~ /^\d+$/);
+ $depth = $args{depth} if (!defined($depth) && defined($args{depth}) && $args{depth} =~ /^\d+$/);
+
+ if (defined $depth and $depth > 0) { # Not scoped to the top of the tree
+ $borgs = OpenSRF::AppSession->create( 'open-ils.cstore' )->request(
+ 'open-ils.cstore.json_query.atomic',
+ { from => [ 'actor.org_unit_descendants', $site->id, $depth ] }
+ )->gather(1);
+ } else {
+ $borgs = OpenSRF::AppSession->create( 'open-ils.cstore' )->request(
+ 'open-ils.cstore.json_query.atomic',
+ { from => [ 'actor.org_unit_descendants', $site->id ] }
+ )->gather(1);
+ }
+
+ if (ref $borgs && @$borgs) {
+ $borgs = join(',', map { $_->{'actor.org_unit_descendants'} } @$borgs);
+ } else {
+ $borgs = undef;
+ }
}
}
$args{item_form} = [ split '', $f ];
}
- for my $filter ( qw/locations location_groups 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 badges/ ) {
if (my $s = $args{$filter}) {
$s = [$s] if (!ref($s));