3 INSERT INTO config.upgrade_log (version) VALUES ('0532'); --gmc
5 CREATE OR REPLACE FUNCTION asset.opac_ou_record_copy_count (org INT, rid BIGINT) RETURNS TABLE (depth INT, org_unit INT, visible BIGINT, available BIGINT, unshadow BIGINT, transcendant INT) AS $f$
10 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;
12 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
17 SUM( CASE WHEN cp.status IN (0,7,12) THEN 1 ELSE 0 END ),
21 actor.org_unit_descendants(ans.id) d
22 JOIN asset.opac_visible_copies av ON (av.record = rid AND av.circ_lib = d.id)
23 JOIN asset.copy cp ON (cp.id = av.copy_id)
27 RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans;
36 CREATE OR REPLACE FUNCTION asset.opac_lasso_record_copy_count (i_lasso INT, rid BIGINT) RETURNS TABLE (depth INT, org_unit INT, visible BIGINT, available BIGINT, unshadow BIGINT, transcendant INT) AS $f$
41 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;
43 FOR ans IN SELECT u.org_unit AS id FROM actor.org_lasso_map AS u WHERE lasso = i_lasso LOOP
48 SUM( CASE WHEN cp.status IN (0,7,12) THEN 1 ELSE 0 END ),
52 actor.org_unit_descendants(ans.id) d
53 JOIN asset.opac_visible_copies av ON (av.record = rid AND av.circ_lib = d.id)
54 JOIN asset.copy cp ON (cp.id = av.copy_id)
58 RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans;
67 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$
72 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;
74 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
79 SUM( CASE WHEN cp.status IN (0,7,12) THEN 1 ELSE 0 END ),
83 actor.org_unit_descendants(ans.id) d
84 JOIN asset.opac_visible_copies av ON (av.record = rid AND av.circ_lib = d.id)
85 JOIN asset.copy cp ON (cp.id = av.copy_id)
86 JOIN metabib.metarecord_source_map m ON (m.source = av.record)
90 RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans;
99 CREATE OR REPLACE FUNCTION asset.opac_lasso_metarecord_copy_count (i_lasso INT, rid BIGINT) RETURNS TABLE (depth INT, org_unit INT, visible BIGINT, available BIGINT, unshadow BIGINT, transcendant INT) AS $f$
104 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;
106 FOR ans IN SELECT u.org_unit AS id FROM actor.org_lasso_map AS u WHERE lasso = i_lasso LOOP
111 SUM( CASE WHEN cp.status IN (0,7,12) THEN 1 ELSE 0 END ),
115 actor.org_unit_descendants(ans.id) d
116 JOIN asset.opac_visible_copies av ON (av.record = rid AND av.circ_lib = d.id)
117 JOIN asset.copy cp ON (cp.id = av.copy_id)
118 JOIN metabib.metarecord_source_map m ON (m.source = av.record)
122 RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans;
129 $f$ LANGUAGE PLPGSQL;