the comments and code here will guide me, but will be rebased away
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Fri, 24 Feb 2012 23:31:46 +0000 (18:31 -0500)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 7 Mar 2012 21:57:09 +0000 (16:57 -0500)
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Serial.pm
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.serial-holding-groups.sql

index a6ce788..e4a01d6 100644 (file)
@@ -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",
index 6accb39..651582b 100644 (file)
@@ -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;