} elsif( $hold_type eq OILS_HOLD_TYPE_METARECORD ) {
- my ($recs) = __PACKAGE__->method_lookup('open-ils.circ.holds.metarecord.filterd_records')->run($mrid, $holdable_formats);
+
+ my ($recs) = __PACKAGE__->method_lookup('open-ils.circ.holds.metarecord.filterd_records')->run($mrid, $holdable_formats, $selection_ou, $depth);
my @status = ();
for my $rec (@$recs) {
@status = _check_title_hold_is_possible(
}
sub MR_filter_records {
- return $U->storagereq('open-ils.storage.metarecord.filtered_records.atomic', $_[2], $_[3]);
+ my $self = shift;
+ my $client = shift;
+ my $m = shift;
+ my $f = shift;
+ my $o = shift;
+ my $d = shift;
+
+ my $org_at_depth = defined($d) ? $U->org_unit_ancestor_at_depth($o, $d) : $o;
+ return $U->storagereq('open-ils.storage.metarecord.filtered_records.atomic', $m, $f, $org_at_depth);
}
__PACKAGE__->register_method(
method => 'MR_filter_records',
my $client = shift;
my $MR = shift;
my $filter = shift;
+ my $org = shift;
# find filters for MR holds
my $mr_filter;
my $records = [metabib::metarecord->retrieve($MR)->source_records];
+ my $q = 'SELECT source FROM metabib.record_attr_vector_list WHERE source = ? AND vlist @@ ? AND asset.record_has_holdable_copy(?,?)';
+ my @args = ( $mr_filter, $org );
if (!$mr_filter) {
- $client->respond( $_->id ) for @$records;
- } else {
- for my $r ( map { isTrue($_->deleted) ? () : ($_->id) } @$records ) {
- $client->respond($r) if
- @{action::hold_request->db_Main->selectcol_arrayref(
- 'SELECT source FROM metabib.record_attr_vector_list WHERE source = ? AND vlist @@ ?',
- {},
- $r,
- $mr_filter
- )};
- }
+ $q = 'SELECT true WHERE asset.record_has_holdable_copy(?,?)';
+ @args = ( $org );
}
+
+ for my $r ( map { isTrue($_->deleted) ? () : ($_->id) } @$records ) {
+ # the map{} below is tricky. it puts the record ID in front of each param. see $q above
+ $client->respond($r)
+ if @{action::hold_request->db_Main->selectcol_arrayref( $q, {}, map { ( $r => $_ ) } @args )};
+ }
+
return; # discard final l-val
}
__PACKAGE__->register_method(
END;
$f$ LANGUAGE PLPGSQL;
-CREATE OR REPLACE FUNCTION asset.record_has_holdable_copy ( rid BIGINT ) RETURNS BOOL AS $f$
+CREATE OR REPLACE FUNCTION asset.record_has_holdable_copy ( rid BIGINT, ou INT DEFAULT NULL) RETURNS BOOL AS $f$
BEGIN
PERFORM 1
FROM
AND acpl.holdable = true
AND ccs.holdable = true
AND acp.deleted = false
+ AND acp.circ_lib IN (SELECT id FROM actor.org_unit_descendants(COALESCE($2,(SELECT id FROM evergreen.org_top()))))
LIMIT 1;
IF FOUND THEN
RETURN true;
END;
$f$ LANGUAGE PLPGSQL;
-CREATE OR REPLACE FUNCTION asset.metarecord_has_holdable_copy ( rid BIGINT ) RETURNS BOOL AS $f$
+CREATE OR REPLACE FUNCTION asset.metarecord_has_holdable_copy ( rid BIGINT, ou INT DEFAULT NULL) RETURNS BOOL AS $f$
BEGIN
PERFORM 1
FROM
AND acpl.holdable = true
AND ccs.holdable = true
AND acp.deleted = false
+ AND acp.circ_lib IN (SELECT id FROM actor.org_unit_descendants(COALESCE($2,(SELECT id FROM evergreen.org_top()))))
LIMIT 1;
IF FOUND THEN
RETURN true;
BEGIN;
+DROP FUNCTION asset.record_has_holdable_copy (BIGINT);
+CREATE FUNCTION asset.record_has_holdable_copy ( rid BIGINT, ou INT DEFAULT NULL) RETURNS BOOL AS $f$
+BEGIN
+ PERFORM 1
+ FROM
+ asset.copy acp
+ JOIN asset.call_number acn ON acp.call_number = acn.id
+ JOIN asset.copy_location acpl ON acp.location = acpl.id
+ JOIN config.copy_status ccs ON acp.status = ccs.id
+ WHERE
+ acn.record = rid
+ AND acp.holdable = true
+ AND acpl.holdable = true
+ AND ccs.holdable = true
+ AND acp.deleted = false
+ AND acp.circ_lib IN (SELECT id FROM actor.org_unit_descendants(COALESCE($2,(SELECT id FROM evergreen.org_top()))))
+ LIMIT 1;
+ IF FOUND THEN
+ RETURN true;
+ END IF;
+ RETURN FALSE;
+END;
+$f$ LANGUAGE PLPGSQL;
+
+DROP FUNCTION asset.metarecord_has_holdable_copy (BIGINT);
+CREATE FUNCTION asset.metarecord_has_holdable_copy ( rid BIGINT, ou INT DEFAULT NULL) RETURNS BOOL AS $f$
+BEGIN
+ PERFORM 1
+ FROM
+ asset.copy acp
+ JOIN asset.call_number acn ON acp.call_number = acn.id
+ JOIN asset.copy_location acpl ON acp.location = acpl.id
+ JOIN config.copy_status ccs ON acp.status = ccs.id
+ JOIN metabib.metarecord_source_map mmsm ON acn.record = mmsm.source
+ WHERE
+ mmsm.metarecord = rid
+ AND acp.holdable = true
+ AND acpl.holdable = true
+ AND ccs.holdable = true
+ AND acp.deleted = false
+ AND acp.circ_lib IN (SELECT id FROM actor.org_unit_descendants(COALESCE($2,(SELECT id FROM evergreen.org_top()))))
+ LIMIT 1;
+ IF FOUND THEN
+ RETURN true;
+ END IF;
+ RETURN FALSE;
+END;
+$f$ LANGUAGE PLPGSQL;
+
CREATE OR REPLACE FUNCTION asset.opac_ou_metarecord_copy_count (org INT, rid BIGINT) RETURNS TABLE (depth INT, org_unit INT, visible BIGINT, available BIGINT, unshadow BIGINT, transcendant INT) AS $f$
DECLARE
ans RECORD;