1 package OpenILS::Application::Storage::Publisher::actor;
2 use base qw/OpenILS::Application::Storage/;
3 use OpenILS::Application::Storage::CDBI::actor;
4 use OpenSRF::Utils::Logger qw/:level/;
5 use OpenILS::Utils::Fieldmapper;
7 my $log = 'OpenSRF::Utils::Logger';
14 return undef unless @barcodes;
16 for my $card ( actor::card->search( { barcode => @barcodes } ) ) {
20 my $usr_fm = flesh_user( $card->usr );
21 $client->respond( $usr_fm );
25 __PACKAGE__->register_method(
26 api_name => 'open-ils.storage.fleshed.actor.user.search.barcode',
28 method => 'user_by_barcode',
38 return undef unless (defined $searches);
40 for my $usr ( actor::user->search( $searches ) ) {
42 $client->respond( flesh_user( $usr ) );
46 __PACKAGE__->register_method(
47 api_name => 'open-ils.storage.fleshed.actor.user.search',
49 method => 'fleshed_search',
54 sub fleshed_search_like {
59 return undef unless (defined $searches);
61 for my $usr ( actor::user->search_like( $searches ) ) {
63 $client->respond( flesh_user( $usr ) );
67 __PACKAGE__->register_method(
68 api_name => 'open-ils.storage.fleshed.actor.user.search_like',
70 method => 'user_by_barcode',
75 sub retrieve_fleshed_user {
80 return undef unless @ids;
82 @ids = ($ids[0]) unless ($self->api_name =~ /batch/o);
84 $client->respond( flesh_user( actor::user->retrieve( $_ ) ) ) for ( @ids );
88 __PACKAGE__->register_method(
89 api_name => 'open-ils.storage.fleshed.actor.user.retrieve',
91 method => 'retrieve_fleshed_user',
94 __PACKAGE__->register_method(
95 api_name => 'open-ils.storage.fleshed.actor.user.batch.retrieve',
97 method => 'retrieve_fleshed_user',
106 my $standing = $usr->standing;
107 my $profile = $usr->profile;
108 my $ident_type = $usr->ident_type;
110 my $maddress = $usr->mailing_address;
111 my $baddress = $usr->billing_address;
112 my $card = $usr->card;
114 my @addresses = $usr->addresses;
115 my @cards = $usr->cards;
117 my $usr_fm = $usr->to_fieldmapper;
118 $usr_fm->standing( $standing->to_fieldmapper );
119 $usr_fm->profile( $profile->to_fieldmapper );
120 $usr_fm->ident_type( $ident_type->to_fieldmapper );
122 $usr_fm->card( $card->to_fieldmapper );
123 $usr_fm->mailing_address( $maddress->to_fieldmapper ) if ($maddress);
124 $usr_fm->billing_address( $baddress->to_fieldmapper ) if ($baddress);
126 $usr_fm->cards( [ map { $_->to_fieldmapper } @cards ] );
127 $usr_fm->addresses( [ map { $_->to_fieldmapper } @addresses ] );
136 my $select =<<" SQL";
139 ORDER BY CASE WHEN parent_ou IS NULL THEN 0 ELSE 1 END, name;
142 my $sth = actor::org_unit->db_Main->prepare_cached($select);
146 push @fms, $_->to_fieldmapper for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
150 __PACKAGE__->register_method(
151 api_name => 'open-ils.storage.direct.actor.org_unit.retrieve.all',
153 method => 'org_unit_list',
156 sub org_unit_type_list {
160 my $select =<<" SQL";
162 FROM actor.org_unit_type
163 ORDER BY depth, name;
166 my $sth = actor::org_unit_type->db_Main->prepare_cached($select);
170 push @fms, $_->to_fieldmapper for ( map { actor::org_unit_type->construct($_) } $sth->fetchall_hash );
174 __PACKAGE__->register_method(
175 api_name => 'open-ils.storage.direct.actor.org_unit_type.retrieve.all',
177 method => 'org_unit_type_list',
180 sub org_unit_descendants {
185 return undef unless ($id);
187 my $select =<<" SQL";
189 FROM connectby('actor.org_unit','id','parent_ou','name',?,'100','.')
190 as t(keyid text, parent_keyid text, level int, branch text,pos int),
196 my $sth = actor::org_unit->db_Main->prepare_cached($select);
200 push @fms, $_->to_fieldmapper for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
204 __PACKAGE__->register_method(
205 api_name => 'open-ils.storage.actor.org_unit.descendants',
207 method => 'org_unit_descendants',