liquid_feedback_core

diff update/core-update.v2.0.9-v2.0.10.sql @ 253:389200fd973d

Added field "participating_member_id" to result of "delegation_info" function
author jbe
date Sun May 20 17:20:50 2012 +0200 (2012-05-20)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/update/core-update.v2.0.9-v2.0.10.sql	Sun May 20 17:20:50 2012 +0200
     1.3 @@ -0,0 +1,121 @@
     1.4 +BEGIN;
     1.5 +
     1.6 +CREATE OR REPLACE VIEW "liquid_feedback_version" AS
     1.7 +  SELECT * FROM (VALUES ('2.0.10', 2, 0, 10))
     1.8 +  AS "subquery"("string", "major", "minor", "revision");
     1.9 +
    1.10 +DROP FUNCTION "delegation_info"
    1.11 +  ( "member"."id"%TYPE,
    1.12 +    "unit"."id"%TYPE,
    1.13 +    "area"."id"%TYPE,
    1.14 +    "issue"."id"%TYPE,
    1.15 +    "member"."id"%TYPE );
    1.16 +
    1.17 +DROP TYPE "delegation_info_type";
    1.18 +
    1.19 +
    1.20 +CREATE TYPE "delegation_info_type" AS (
    1.21 +        "own_participation"           BOOLEAN,
    1.22 +        "own_delegation_scope"        "delegation_scope",
    1.23 +        "first_trustee_id"            INT4,
    1.24 +        "first_trustee_participation" BOOLEAN,
    1.25 +        "first_trustee_ellipsis"      BOOLEAN,
    1.26 +        "other_trustee_id"            INT4,
    1.27 +        "other_trustee_participation" BOOLEAN,
    1.28 +        "other_trustee_ellipsis"      BOOLEAN,
    1.29 +        "delegation_loop"             "delegation_info_loop_type",
    1.30 +        "participating_member_id"     INT4 );
    1.31 +
    1.32 +COMMENT ON TYPE "delegation_info_type" IS 'Type of result returned by "delegation_info" function; For meaning of "participation" check comment on "delegation_chain_row" type';
    1.33 +
    1.34 +COMMENT ON COLUMN "delegation_info_type"."own_participation"           IS 'Member is directly participating';
    1.35 +COMMENT ON COLUMN "delegation_info_type"."own_delegation_scope"        IS 'Delegation scope of member';
    1.36 +COMMENT ON COLUMN "delegation_info_type"."first_trustee_id"            IS 'Direct trustee of member';
    1.37 +COMMENT ON COLUMN "delegation_info_type"."first_trustee_participation" IS 'Direct trustee of member is participating';
    1.38 +COMMENT ON COLUMN "delegation_info_type"."first_trustee_ellipsis"      IS 'Ellipsis in delegation chain after "first_trustee"';
    1.39 +COMMENT ON COLUMN "delegation_info_type"."other_trustee_id"            IS 'Another relevant trustee (due to participation)';
    1.40 +COMMENT ON COLUMN "delegation_info_type"."other_trustee_participation" IS 'Another trustee is participating (redundant field: if "other_trustee_id" is set, then "other_trustee_participation" is always TRUE, else "other_trustee_participation" is NULL)';
    1.41 +COMMENT ON COLUMN "delegation_info_type"."other_trustee_ellipsis"      IS 'Ellipsis in delegation chain after "other_trustee"';
    1.42 +COMMENT ON COLUMN "delegation_info_type"."delegation_loop"             IS 'Non-NULL value, if delegation chain contains a circle; See comment on "delegation_info_loop_type" for details';
    1.43 +COMMENT ON COLUMN "delegation_info_type"."participating_member_id"     IS 'First participating member in delegation chain';
    1.44 +
    1.45 +
    1.46 +CREATE FUNCTION "delegation_info"
    1.47 +  ( "member_id_p"           "member"."id"%TYPE,
    1.48 +    "unit_id_p"             "unit"."id"%TYPE,
    1.49 +    "area_id_p"             "area"."id"%TYPE,
    1.50 +    "issue_id_p"            "issue"."id"%TYPE,
    1.51 +    "simulate_trustee_id_p" "member"."id"%TYPE DEFAULT NULL )
    1.52 +  RETURNS "delegation_info_type"
    1.53 +  LANGUAGE 'plpgsql' STABLE AS $$
    1.54 +    DECLARE
    1.55 +      "current_row" "delegation_chain_row";
    1.56 +      "result"      "delegation_info_type";
    1.57 +    BEGIN
    1.58 +      "result"."own_participation" := FALSE;
    1.59 +      FOR "current_row" IN
    1.60 +        SELECT * FROM "delegation_chain"(
    1.61 +          "member_id_p",
    1.62 +          "unit_id_p", "area_id_p", "issue_id_p",
    1.63 +          "simulate_trustee_id_p")
    1.64 +      LOOP
    1.65 +        IF
    1.66 +          "result"."participating_member_id" ISNULL AND
    1.67 +          "current_row"."participation"
    1.68 +        THEN
    1.69 +          "result"."participating_member_id" := "current_row"."member_id";
    1.70 +        END IF;
    1.71 +        IF "current_row"."member_id" = "member_id_p" THEN
    1.72 +          "result"."own_participation"    := "current_row"."participation";
    1.73 +          "result"."own_delegation_scope" := "current_row"."scope_out";
    1.74 +          IF "current_row"."loop" = 'first' THEN
    1.75 +            "result"."delegation_loop" := 'own';
    1.76 +          END IF;
    1.77 +        ELSIF
    1.78 +          "current_row"."member_valid" AND
    1.79 +          ( "current_row"."loop" ISNULL OR
    1.80 +            "current_row"."loop" != 'repetition' )
    1.81 +        THEN
    1.82 +          IF "result"."first_trustee_id" ISNULL THEN
    1.83 +            "result"."first_trustee_id"            := "current_row"."member_id";
    1.84 +            "result"."first_trustee_participation" := "current_row"."participation";
    1.85 +            "result"."first_trustee_ellipsis"      := FALSE;
    1.86 +            IF "current_row"."loop" = 'first' THEN
    1.87 +              "result"."delegation_loop" := 'first';
    1.88 +            END IF;
    1.89 +          ELSIF "result"."other_trustee_id" ISNULL THEN
    1.90 +            IF "current_row"."participation" AND NOT "current_row"."overridden" THEN
    1.91 +              "result"."other_trustee_id"            := "current_row"."member_id";
    1.92 +              "result"."other_trustee_participation" := TRUE;
    1.93 +              "result"."other_trustee_ellipsis"      := FALSE;
    1.94 +              IF "current_row"."loop" = 'first' THEN
    1.95 +                "result"."delegation_loop" := 'other';
    1.96 +              END IF;
    1.97 +            ELSE
    1.98 +              "result"."first_trustee_ellipsis" := TRUE;
    1.99 +              IF "current_row"."loop" = 'first' THEN
   1.100 +                "result"."delegation_loop" := 'first_ellipsis';
   1.101 +              END IF;
   1.102 +            END IF;
   1.103 +          ELSE
   1.104 +            "result"."other_trustee_ellipsis" := TRUE;
   1.105 +            IF "current_row"."loop" = 'first' THEN
   1.106 +              "result"."delegation_loop" := 'other_ellipsis';
   1.107 +            END IF;
   1.108 +          END IF;
   1.109 +        END IF;
   1.110 +      END LOOP;
   1.111 +      RETURN "result";
   1.112 +    END;
   1.113 +  $$;
   1.114 +
   1.115 +COMMENT ON FUNCTION "delegation_info"
   1.116 +  ( "member"."id"%TYPE,
   1.117 +    "unit"."id"%TYPE,
   1.118 +    "area"."id"%TYPE,
   1.119 +    "issue"."id"%TYPE,
   1.120 +    "member"."id"%TYPE )
   1.121 +  IS 'Notable information about a delegation chain for unit, area, or issue; See "delegation_info_type" for more information';
   1.122 +
   1.123 +
   1.124 +COMMIT;

Impressum / About Us