From 9b71484d47b0851e44944910d546e9686b4bf7cb Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 12 Mar 2007 22:07:21 +0000 Subject: [PATCH] added a method to search up the org tree for ancestor org settings until the first match is found git-svn-id: svn://svn.open-ils.org/ILS/trunk@7067 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/perlmods/OpenILS/Application/Actor.pm | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm index 4c8d60af48..3339695449 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm @@ -152,6 +152,43 @@ sub ou_settings { return { map { ( $_->name => JSON->JSON2perl($_->value) ) } @$s }; } + + +__PACKAGE__->register_method( + api_name => 'open-ils.actor.ou_setting.ancestor_default', + method => 'ou_ancestor_setting', +); + +# ------------------------------------------------------------------ +# Attempts to find the org setting value for a given org. if not +# found at the requested org, searches up the org tree until it +# finds a parent that has the requested setting. +# when found, returns { org => $id, value => $value } +# otherwise, returns NULL +# ------------------------------------------------------------------ +sub ou_ancestor_setting { + my( $self, $client, $orgid, $name ) = @_; + my $e = new_editor(); + + do { + my $setting = $e->search_actor_org_unit_setting({org_unit=>$orgid, name=>$name})->[0]; + + if( $setting ) { + $logger->info("found org_setting $name at org $orgid : " . $setting->value); + return { org => $orgid, value => JSON->JSON2perl($setting->value) }; + } + + my $org = $e->retrieve_actor_org_unit($orgid) or return $e->event; + $orgid = $org->parent_ou or return undef; + + } while(1); + + return undef; +} + + + + __PACKAGE__->register_method ( method => "ou_setting_delete", api_name => 'open-ils.actor.org_setting.delete', -- 2.11.0