From: erickson Date: Fri, 18 Aug 2006 18:45:21 +0000 (+0000) Subject: added super-simple prototype for generic object fetcher - needs work X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=eb8e217eac38b76aed5c61e042a23ddc02909f1b;p=evergreen%2Fpines.git added super-simple prototype for generic object fetcher - needs work git-svn-id: svn://svn.open-ils.org/ILS/trunk@5592 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm b/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm index 5441d771b7..12cca53ee0 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Circ.pm @@ -789,4 +789,42 @@ sub mark_item { + +# ---------------------------------------------------------------------- +__PACKAGE__->register_method( + method => 'magic_fetch', + api_name => 'open-ils.agent.fetch' +); + +my @FETCH_ALLOWED = qw/ aou aout acp acn bre /; + +sub magic_fetch { + my( $self, $conn, $auth, $args ) = @_; + my $e = new_editor( authtoken => $auth ); + return $e->event unless $e->checkauth; + + my $hint = $$args{hint}; + my $id = $$args{id}; + + # Is the call allowed to fetch this type of object? + return undef unless grep { $_ eq $hint } @FETCH_ALLOWED; + + # Find the class the iplements the given hint + my ($class) = grep { + $Fieldmapper::fieldmap->{$_}{hint} eq $hint } Fieldmapper->classes; + + $class =~ s/Fieldmapper:://og; + $class =~ s/::/_/og; + my $method = "retrieve_$class"; + + my $obj = $e->$method($id) or return $e->event; + return $obj; +} +# ---------------------------------------------------------------------- + + + + + + 1;