unapi: Sort volumes in holdings_xml by library, label
authorDan Scott <dscott@laurentian.ca>
Sun, 18 Dec 2011 05:07:22 +0000 (00:07 -0500)
committerDan Scott <dscott@laurentian.ca>
Sun, 18 Dec 2011 05:48:56 +0000 (00:48 -0500)
In-database unapi currently returns volumes sorted strictly by label,
but a more meaningful order would sort the volumes first by copy library
(in alphabetical order), and then by label within each library. This
commit makes it so.

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/src/sql/Pg/990.schema.unapi.sql

index a29f96d..a311a7a 100644 (file)
@@ -278,12 +278,13 @@ CREATE OR REPLACE FUNCTION unapi.holdings_xml (bid BIGINT, ouid INT, org TEXT, d
                          name volumes,
                          (SELECT XMLAGG(acn) FROM (
                             SELECT  unapi.acn(y.id,'xml','volume',evergreen.array_remove_item_by_value( evergreen.array_remove_item_by_value($5,'holdings_xml'),'bre'), $3, $4, $6, $7, FALSE) FROM (
-                                SELECT  distinct acn.id, acn.label_sortkey
+                                SELECT  distinct acn.id, acp.circ_lib, acn.label_sortkey
                                   FROM  asset.call_number acn
                                         JOIN asset.copy acp ON (acn.id = acp.call_number)
                                         JOIN actor.org_unit_descendants( $2 ) aoud ON (acp.circ_lib = aoud.id)
+                                        INNER JOIN actor.org_unit aou ON (aou.id = acp.circ_lib)
                                   WHERE acn.record = $1
-                                  ORDER BY acn.label_sortkey
+                                  ORDER BY acp.circ_lib, acn.label_sortkey
                                   LIMIT ($6 -> 'acn')::INT
                                   OFFSET ($7 -> 'acn')::INT
                             )y
@@ -294,12 +295,13 @@ CREATE OR REPLACE FUNCTION unapi.holdings_xml (bid BIGINT, ouid INT, org TEXT, d
                          name volumes,
                          (SELECT XMLAGG(acn) FROM (
                             SELECT  unapi.acn(y.id,'xml','volume',evergreen.array_remove_item_by_value( evergreen.array_remove_item_by_value($5,'holdings_xml'),'bre'), $3, $4, $6, $7, FALSE) FROM (
-                                SELECT  distinct acn.id, acn.label_sortkey
+                                SELECT  distinct acn.id, acp.circ_lib, acn.label_sortkey
                                   FROM  asset.call_number acn
                                         JOIN asset.copy acp ON (acn.id = acp.call_number)
                                         JOIN actor.org_unit_descendants( $2, $4 ) aoud ON (acp.circ_lib = aoud.id)
+                                        INNER JOIN actor.org_unit aou ON (aou.id = acp.circ_lib)
                                   WHERE acn.record = $1
-                                  ORDER BY acn.label_sortkey
+                                  ORDER BY acp.circ_lib, acn.label_sortkey
                                   LIMIT ($6 -> 'acn')::INT
                                   OFFSET ($7 -> 'acn')::INT
                             )y