1 CREATE OR REPLACE FUNCTION asset.staff_ou_record_copy_count(org integer, rid bigint)
2 RETURNS TABLE(depth integer, org_unit integer, visible bigint, available bigint, unshadow bigint, transcendant integer)
9 SELECT 1 INTO trans FROM biblio.record_entry b JOIN config.bib_source src ON (b.source = src.id) WHERE src.transcendant AND b.id = rid;
11 FOR ans IN SELECT u.id, t.depth FROM actor.org_unit_ancestors(org) AS u JOIN actor.org_unit_type t ON (u.ou_type = t.id) LOOP
13 WITH available_statuses AS (SELECT ARRAY_AGG(id) AS ids FROM config.copy_status WHERE is_available),
16 (cp.status = ANY (available_statuses.ids))::INT as available,
17 (cl.opac_visible AND cp.opac_visible)::INT as opac_visible
20 actor.org_unit_descendants(ans.id) d
21 JOIN asset.copy cp ON (cp.circ_lib = d.id AND NOT cp.deleted)
22 JOIN asset.copy_location cl ON (cp.location = cl.id AND NOT cl.deleted)
23 JOIN asset.call_number cn ON (cn.record = rid AND cn.id = cp.call_number AND NOT cn.deleted)
27 (cp.status = ANY (available_statuses.ids))::INT as available,
28 (cl.opac_visible AND cp.opac_visible)::INT as opac_visible
31 actor.org_unit_descendants(ans.id) d
32 JOIN asset.copy cp ON (cp.circ_lib = d.id AND NOT cp.deleted)
33 JOIN asset.copy_location cl ON (cp.location = cl.id AND NOT cl.deleted)
34 JOIN biblio.peer_bib_copy_map bp ON (bp.peer_record = rid AND bp.target_copy = cp.id)
36 SELECT ans.depth, ans.id, count(id), sum(x.available::int), sum(x.opac_visible::int), trans
37 FROM ((select * from cp) union (select * from peer)) x
41 RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans;
49 CREATE OR REPLACE FUNCTION asset.opac_ou_record_copy_count(org integer, rid bigint)
50 RETURNS TABLE(depth integer, org_unit integer, visible bigint, available bigint, unshadow bigint, transcendant integer)
57 SELECT 1 INTO trans FROM biblio.record_entry b JOIN config.bib_source src ON (b.source = src.id) WHERE src.transcendant AND b.id = rid;
59 FOR ans IN SELECT u.id, t.depth FROM actor.org_unit_ancestors(org) AS u JOIN actor.org_unit_type t ON (u.ou_type = t.id) LOOP
61 WITH org_list AS (SELECT ARRAY_AGG(id)::BIGINT[] AS orgs FROM actor.org_unit_descendants(ans.id) x),
62 available_statuses AS (SELECT ARRAY_AGG(id) AS ids FROM config.copy_status WHERE is_available),
63 mask AS (SELECT c_attrs FROM asset.patron_default_visibility_mask() x)
67 SUM( (cp.status = ANY (available_statuses.ids))::INT ),
73 asset.copy_vis_attr_cache av
74 JOIN asset.copy cp ON (cp.id = av.target_copy AND av.record = rid)
75 JOIN asset.call_number cn ON (cp.call_number = cn.id AND not cn.deleted)
76 WHERE cp.circ_lib = ANY (org_list.orgs) AND av.vis_attr_vector @@ mask.c_attrs::query_int
80 RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans;