From: Lebbeous Fogle-Weekley Date: Fri, 24 Feb 2012 23:31:46 +0000 (-0500) Subject: the comments and code here will guide me, but will be rebased away X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=69242f745a512599f09749ef8c0005067b5a9edf;p=evergreen%2Fequinox.git the comments and code here will guide me, but will be rebased away Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm index a6ce788d6e..e4a01d68f6 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm @@ -771,6 +771,8 @@ sub scoped_holding_summary_tree_for_bib { limit => int($limit), offset => int($offset), order_by => [ + # XXX so first order by an array-ized path from root to org, + # THEN order by this date_expected business { class => "sitem", field => "date_expected", diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.serial-holding-groups.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.serial-holding-groups.sql index 6accb3973a..651582b01c 100644 --- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.serial-holding-groups.sql +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.serial-holding-groups.sql @@ -23,18 +23,29 @@ CREATE VIEW serial.any_summary AS generated_coverage, textual_holdings, show_generated FROM serial.supplement_summary ; --- --- SELECT --- sasum.summary_type || '-' || sasum.id AS summary_key, --- sasum.generated_coverage, aou.shortname, siss.label --- FROM serial.any_summary sasum --- JOIN serial.distribution sdist ON (sdist.id = sasum.distribution) --- JOIN actor.org_unit aou ON (aou.id = sdist.holding_lib) -- XXX remove later --- JOIN serial.stream sstr ON (sstr.distribution = sdist.id) --- JOIN serial.item sitem --- ON (sitem.status = 'Received' AND sitem.stream = sstr.id) --- JOIN serial.issuance siss ON (siss.id = sitem.issuance) --- ORDER BY 1, 2, siss.date_published; --- +-- XXX wait, this is cool, but will I actually need this? The problem I really +-- set out to solve was how to order a set of rows that have OU ids in them by +-- those OU's positions in a depth-first tree. can i just sort by something +-- like the path here? i think so +CREATE OR REPLACE FUNCTION actor.org_unit_descendants_depth_first( INT ) RETURNS SETOF actor.org_unit AS $$ + WITH RECURSIVE descendant_depth(id, parent_ou, depth, path) AS ( + SELECT ou.id, + ou.parent_ou, + out.depth, + ARRAY[ou.id] + FROM actor.org_unit ou + JOIN actor.org_unit_type out ON (out.id = ou.ou_type) + WHERE ou.id = $1 + UNION ALL + SELECT ou.id, + ou.parent_ou, + out.depth, + ot.path || ARRAY[ou.id] + FROM actor.org_unit ou + JOIN actor.org_unit_type out ON (out.id = ou.ou_type) + JOIN descendant_depth ot ON (ot.id = ou.parent_ou) + ) SELECT ou.* FROM actor.org_unit ou JOIN descendant_depth dd USING (id) ORDER BY dd.path; +$$ LANGUAGE SQL ROWS 1; + COMMIT;