From 3ab73b7d4a5216a1e24b21aa64f8f163d2ea0992 Mon Sep 17 00:00:00 2001 From: miker Date: Fri, 22 Apr 2005 17:59:42 +0000 Subject: [PATCH] survey support git-svn-id: svn://svn.open-ils.org/ILS/trunk@551 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../Application/Storage/CDBI/action.pm | 2 +- .../Application/Storage/Publisher/action.pm | 90 +++++++++++++++++++ .../Application/Storage/Publisher/actor.pm | 64 ++++++++++--- .../src/sql/Postgres/020.schema.functions.sql | 8 ++ .../src/sql/Postgres/090.schema.action.sql | 9 +- 5 files changed, 159 insertions(+), 14 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/action.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/action.pm index 54de4a7f69..72ee3b08c4 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/action.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI/action.pm @@ -10,7 +10,7 @@ package action::survey; use base qw/action/; __PACKAGE__->table('action_survey'); __PACKAGE__->columns(Primary => 'id'); -__PACKAGE__->columns(Essential => qw/name start_date end_date usr_summary opac/); +__PACKAGE__->columns(Essential => qw/name description owner start_date end_date usr_summary opac required/); #------------------------------------------------------------------------------- package action::survey_question; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm index 01ffe8f631..1d5af97301 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm @@ -6,4 +6,94 @@ use base qw/OpenILS::Application::Storage/; # #my $log = 'OpenSRF::Utils::Logger'; +sub find_opac_surveys { + my $self = shift; + my $client = shift; + my $ou = ''.shift(); + + return undef unless ($ou); + + my $select = <<" SQL"; + SELECT s.* + FROM action.survey s + JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner) + WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date + AND s.opac IS TRUE; + SQL + + my $sth = action::survey->db_Main->prepare_cached($select); + $sth->execute($ou); + + $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash ); + + return undef; +} +__PACKAGE__->register_method( + api_name => 'open-ils.storage.action.survey.opac', + api_level => 1, + stream => 1, + method => 'find_opac_surveys', +); + +sub find_optional_surveys { + my $self = shift; + my $client = shift; + my $ou = ''.shift(); + + return undef unless ($ou); + + my $select = <<" SQL"; + SELECT s.* + FROM action.survey s + JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner) + WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date + AND s.required IS FALSE; + SQL + + my $sth = action::survey->db_Main->prepare_cached($select); + $sth->execute($ou); + + $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash ); + + return undef; +} +__PACKAGE__->register_method( + api_name => 'open-ils.storage.action.survey.optional', + api_level => 1, + stream => 1, + method => 'find_optional_surveys', +); + +sub find_required_surveys { + my $self = shift; + my $client = shift; + my $ou = ''.shift(); + + return undef unless ($ou); + + my $select = <<" SQL"; + SELECT s.* + FROM action.survey s + JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner) + WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date + AND s.required IS TRUE; + SQL + + my $sth = action::survey->db_Main->prepare_cached($select); + $sth->execute($ou); + + $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash ); + + return undef; +} +__PACKAGE__->register_method( + api_name => 'open-ils.storage.action.survey.required', + api_level => 1, + stream => 1, + method => 'find_required_surveys', +); + + + + 1; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm index 8f00df3ef2..07109f86a1 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm @@ -180,29 +180,73 @@ __PACKAGE__->register_method( method => 'org_unit_type_list', ); -sub org_unit_descendants { +sub org_unit_full_path { my $self = shift; my $client = shift; my $id = shift; return undef unless ($id); - my $select =<<" SQL"; - SELECT a.* - FROM connectby('actor.org_unit','id','parent_ou','name',?,'100','.') - as t(keyid text, parent_keyid text, level int, branch text,pos int), - actor.org_unit a - WHERE t.keyid = a.id - ORDER BY t.pos; - SQL + my $func = 'actor.org_unit_full_path(?)'; - my $sth = actor::org_unit->db_Main->prepare_cached($select); + my $sth = actor::org_unit->db_Main->prepare_cached("SELECT * FROM $func"); $sth->execute(''.$id); $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash ); return undef; } +__PACKAGE__->register_method( + api_name => 'open-ils.storage.actor.org_unit.full_path', + api_level => 1, + stream => 1, + method => 'org_unit_full_path', +); + +sub org_unit_ancestors { + my $self = shift; + my $client = shift; + my $id = shift; + + return undef unless ($id); + + my $func = 'actor.org_unit_ancestors(?)'; + + my $sth = actor::org_unit->db_Main->prepare_cached("SELECT * FROM $func"); + $sth->execute(''.$id); + + $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash ); + + return undef; +} +__PACKAGE__->register_method( + api_name => 'open-ils.storage.actor.org_unit.ancestors', + api_level => 1, + stream => 1, + method => 'org_unit_ancestors', +); + +sub org_unit_descendants { + my $self = shift; + my $client = shift; + my $id = shift; + my $depth = shift; + + return undef unless ($id); + + my $func = 'actor.org_unit_descendants(?)'; + if (defined $depth) { + $func = 'actor.org_unit_descendants(?,?)'; + } + + my $sth = actor::org_unit->db_Main->prepare_cached("SELECT * FROM $func"); + $sth->execute(''.$id, ''.$depth) if (defined $depth); + $sth->execute(''.$id) unless (defined $depth); + + $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash ); + + return undef; +} __PACKAGE__->register_method( api_name => 'open-ils.storage.actor.org_unit.descendants', api_level => 1, diff --git a/Open-ILS/src/sql/Postgres/020.schema.functions.sql b/Open-ILS/src/sql/Postgres/020.schema.functions.sql index 37769b9bed..89fdca33ae 100644 --- a/Open-ILS/src/sql/Postgres/020.schema.functions.sql +++ b/Open-ILS/src/sql/Postgres/020.schema.functions.sql @@ -68,3 +68,11 @@ CREATE OR REPLACE FUNCTION actor.org_unit_descendants ( INT,INT ) RETURNS SETOF ORDER BY CASE WHEN a.parent_ou IS NULL THEN 0 ELSE 1 END, a.name; $$ LANGUAGE SQL STABLE; +CREATE OR REPLACE FUNCTION actor.org_unit_full_path ( INT ) RETURNS SETOF actor.org_unit AS ' + SELECT * + FROM actor.org_unit_ancestors($1) + UNION + SELECT * + FROM actor.org_unit_descendants($1); +' LANGUAGE SQL STABLE; + diff --git a/Open-ILS/src/sql/Postgres/090.schema.action.sql b/Open-ILS/src/sql/Postgres/090.schema.action.sql index 34227232ab..d32bcf2aa9 100644 --- a/Open-ILS/src/sql/Postgres/090.schema.action.sql +++ b/Open-ILS/src/sql/Postgres/090.schema.action.sql @@ -6,11 +6,14 @@ CREATE SCHEMA action; CREATE TABLE action.survey ( id SERIAL PRIMARY KEY, + owner INT NOT NULL REFERENCES actor.org_unit (id), name TEXT NOT NULL UNIQUE, + description TEXT NOT NULL, start_date DATE NOT NULL DEFAULT NOW(), end_date DATE NOT NULL DEFAULT NOW() + '10 years'::INTERVAL, usr_summary BOOL NOT NULL DEFAULT FALSE, - opac BOOL NOT NULL DEFAULT FALSE + opac BOOL NOT NULL DEFAULT FALSE, + required BOOL NOT NULL DEFAULT FALSE ); CREATE TABLE action.survey_question ( @@ -34,12 +37,12 @@ CREATE TABLE action.survey_response ( answer_date DATE, effective_date DATE NOT NULL DEFAULT NOW()::DATE ); -CREATE FUNCTION action.survey_response_answer_date_fixup () RETURNS TRIGGER AS $$ +CREATE OR REPLACE FUNCTION action.survey_response_answer_date_fixup () RETURNS TRIGGER AS ' BEGIN NEW.anser_date := NOW()::DATE; RETURN NEW; END; -$$ LANGUAGE 'plpgsql'; +' LANGUAGE 'plpgsql'; CREATE TRIGGER action_survey_response_answer_date_fixup_tgr BEFORE INSERT ON action.survey_response FOR EACH ROW -- 2.43.2