From 737097f7d0691953d8fdd8be4a5a228730b99a3c Mon Sep 17 00:00:00 2001 From: miker Date: Wed, 16 Mar 2005 22:56:53 +0000 Subject: [PATCH] adding org_unit stuff git-svn-id: svn://svn.open-ils.org/ILS/trunk@374 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Storage/Driver/Pg.pm | 4 +- .../OpenILS/Application/Storage/Publisher.pm | 9 ++- .../Application/Storage/Publisher/actor.pm | 58 +++++++++++++++++++ .../src/perlmods/OpenILS/Utils/Fieldmapper.pm | 3 +- 4 files changed, 68 insertions(+), 6 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg.pm index 5d24794e4a..4992278f74 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Driver/Pg.pm @@ -431,8 +431,8 @@ #--------------------------------------------------------------------- package actor::org_unit; - actor::org_unit_type->table( 'actor.org_unit' ); - actor::org_unit_type->sequence( 'actor.org_unit_id_seq' ); + actor::org_unit->table( 'actor.org_unit' ); + actor::org_unit->sequence( 'actor.org_unit_id_seq' ); #--------------------------------------------------------------------- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm index 7c504145b8..af71611360 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher.pm @@ -57,17 +57,20 @@ sub search { sub search_one_field { my $self = shift; my $client = shift; - my $term = shift; + my @terms = @_; (my $search_type = $self->api_name) =~ s/.*\.(search[^.]*).*/$1/o; (my $col = $self->api_name) =~ s/.*\.$search_type\.([^.]+).*/$1/; my $cdbi = $self->{cdbi}; - $log->debug("Searching $cdbi for $col using type $search_type, value '$term'",DEBUG); my $like = 0; $like = 1 if ($search_type =~ /like$/o); - return [ $cdbi->fast_fieldmapper($term,$col,$like) ]; + for my $term (@terms) { + $log->debug("Searching $cdbi for $col using type $search_type, value '$term'",DEBUG); + $client->respond( [ $cdbi->fast_fieldmapper($term,$col,$like) ] ); + } + return undef; } 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 c5fa3ef293..d783f08514 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm @@ -6,6 +6,64 @@ use OpenILS::Utils::Fieldmapper; my $log = 'OpenSRF::Utils::Logger'; +sub org_unit_list { + my $self = shift; + my $client = shift; + my $id = shift; + + return undef unless ($id); + + my $select =<<" SQL"; + SELECT * + FROM actor.org_unit + ORDER BY CASE WHEN parent_ou IS NULL THEN 0 ELSE 1 END, name; + SQL + + my $sth = actor::org_unit->db_Main->prepare_cached($select); + $sth->execute($id); + + my @fms; + push @fms, $_->to_fieldmapper for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash ); + + return \@fms; +} +__PACKAGE__->register_method( + api_name => 'open-ils.storage.actor.org_unit_list', + api_level => 1, + method => 'org_unit_list', +); + +sub org_unit_descendants { + 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 $sth = actor::org_unit->db_Main->prepare_cached($select); + $sth->execute($id); + + my @fms; + push @fms, $_->to_fieldmapper for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash ); + + return \@fms; +} +__PACKAGE__->register_method( + api_name => 'open-ils.storage.actor.org_unit_descendants', + api_level => 1, + method => 'org_unit_descendants', +); + + sub get_user_record { my $self = shift; my $client = shift; diff --git a/Open-ILS/src/perlmods/OpenILS/Utils/Fieldmapper.pm b/Open-ILS/src/perlmods/OpenILS/Utils/Fieldmapper.pm index f0f6e0d07c..872ee39a0e 100644 --- a/Open-ILS/src/perlmods/OpenILS/Utils/Fieldmapper.pm +++ b/Open-ILS/src/perlmods/OpenILS/Utils/Fieldmapper.pm @@ -49,7 +49,8 @@ sub _init { { 'Fieldmapper::actor::user' => { hint => 'au' }, 'Fieldmapper::actor::org_unit' => { hint => 'aou' }, - 'Fieldmapper::actor::org_unit_type' => { hint => 'aout' }, + 'Fieldmapper::actor::org_unit_type' => { hint => 'aout', + proto_fields => { children => 1 } }, 'Fieldmapper::biblio::record_node' => { hint => 'brn', proto_fields => { children => 1 } }, -- 2.43.2