]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm
survey support
[working/Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Storage / Publisher / actor.pm
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;
6
7 my $log = 'OpenSRF::Utils::Logger';
8
9 sub user_by_barcode {
10         my $self = shift;
11         my $client = shift;
12         my @barcodes = shift;
13
14         return undef unless @barcodes;
15
16         for my $card ( actor::card->search( { barcode => @barcodes } ) ) {
17
18                 next unless $card;
19
20                 $client->respond( $card->usr->to_fieldmapper);
21         }
22         return undef;
23 }
24 __PACKAGE__->register_method(
25         api_name        => 'open-ils.storage.direct.actor.user.search.barcode',
26         api_level       => 1,
27         method          => 'user_by_barcode',
28         stream          => 1,
29         cachable        => 1,
30 );
31
32 =comment not gonna use it...
33
34 sub fleshed_search {
35         my $self = shift;
36         my $client = shift;
37         my $searches = shift;
38
39         return undef unless (defined $searches);
40
41         for my $usr ( actor::user->search( $searches ) ) {
42                 next unless $usr;
43                 $client->respond( flesh_user( $usr ) );
44         }
45         return undef;
46 }
47 __PACKAGE__->register_method(
48         api_name        => 'open-ils.storage.fleshed.actor.user.search',
49         api_level       => 1,
50         method          => 'fleshed_search',
51         stream          => 1,
52         cachable        => 1,
53 );
54
55 sub fleshed_search_like {
56         my $self = shift;
57         my $client = shift;
58         my $searches = shift;
59
60         return undef unless (defined $searches);
61
62         for my $usr ( actor::user->search_like( $searches ) ) {
63                 next unless $usr;
64                 $client->respond( flesh_user( $usr ) );
65         }
66         return undef;
67 }
68 __PACKAGE__->register_method(
69         api_name        => 'open-ils.storage.fleshed.actor.user.search_like',
70         api_level       => 1,
71         method          => 'user_by_barcode',
72         stream          => 1,
73         cachable        => 1,
74 );
75
76 sub retrieve_fleshed_user {
77         my $self = shift;
78         my $client = shift;
79         my @ids = shift;
80
81         return undef unless @ids;
82
83         @ids = ($ids[0]) unless ($self->api_name =~ /batch/o); 
84
85         $client->respond( flesh_user( actor::user->retrieve( $_ ) ) ) for ( @ids );
86
87         return undef;
88 }
89 __PACKAGE__->register_method(
90         api_name        => 'open-ils.storage.fleshed.actor.user.retrieve',
91         api_level       => 1,
92         method          => 'retrieve_fleshed_user',
93         cachable        => 1,
94 );
95 __PACKAGE__->register_method(
96         api_name        => 'open-ils.storage.fleshed.actor.user.batch.retrieve',
97         api_level       => 1,
98         method          => 'retrieve_fleshed_user',
99         stream          => 1,
100         cachable        => 1,
101 );
102
103 sub flesh_user {
104         my $usr = shift;
105
106
107         my $standing = $usr->standing;
108         my $profile = $usr->profile;
109         my $ident_type = $usr->ident_type;
110                 
111         my $maddress = $usr->mailing_address;
112         my $baddress = $usr->billing_address;
113         my $card = $usr->card;
114
115         my @addresses = $usr->addresses;
116         my @cards = $usr->cards;
117
118         my $usr_fm = $usr->to_fieldmapper;
119         $usr_fm->standing( $standing->to_fieldmapper );
120         $usr_fm->profile( $profile->to_fieldmapper );
121         $usr_fm->ident_type( $ident_type->to_fieldmapper );
122
123         $usr_fm->card( $card->to_fieldmapper );
124         $usr_fm->mailing_address( $maddress->to_fieldmapper ) if ($maddress);
125         $usr_fm->billing_address( $baddress->to_fieldmapper ) if ($baddress);
126
127         $usr_fm->cards( [ map { $_->to_fieldmapper } @cards ] );
128         $usr_fm->addresses( [ map { $_->to_fieldmapper } @addresses ] );
129
130         return $usr_fm;
131 }
132
133 =cut
134
135 sub org_unit_list {
136         my $self = shift;
137         my $client = shift;
138
139         my $select =<<" SQL";
140         SELECT  *
141           FROM  actor.org_unit
142           ORDER BY CASE WHEN parent_ou IS NULL THEN 0 ELSE 1 END, name;
143         SQL
144
145         my $sth = actor::org_unit->db_Main->prepare_cached($select);
146         $sth->execute;
147
148         $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
149
150         return undef;
151 }
152 __PACKAGE__->register_method(
153         api_name        => 'open-ils.storage.direct.actor.org_unit.retrieve.all',
154         api_level       => 1,
155         stream          => 1,
156         method          => 'org_unit_list',
157 );
158
159 sub org_unit_type_list {
160         my $self = shift;
161         my $client = shift;
162
163         my $select =<<" SQL";
164         SELECT  *
165           FROM  actor.org_unit_type
166           ORDER BY depth, name;
167         SQL
168
169         my $sth = actor::org_unit_type->db_Main->prepare_cached($select);
170         $sth->execute;
171
172         $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit_type->construct($_) } $sth->fetchall_hash );
173
174         return undef;
175 }
176 __PACKAGE__->register_method(
177         api_name        => 'open-ils.storage.direct.actor.org_unit_type.retrieve.all',
178         api_level       => 1,
179         stream          => 1,
180         method          => 'org_unit_type_list',
181 );
182
183 sub org_unit_full_path {
184         my $self = shift;
185         my $client = shift;
186         my $id = shift;
187
188         return undef unless ($id);
189
190         my $func = 'actor.org_unit_full_path(?)';
191
192         my $sth = actor::org_unit->db_Main->prepare_cached("SELECT * FROM $func");
193         $sth->execute(''.$id);
194
195         $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
196
197         return undef;
198 }
199 __PACKAGE__->register_method(
200         api_name        => 'open-ils.storage.actor.org_unit.full_path',
201         api_level       => 1,
202         stream          => 1,
203         method          => 'org_unit_full_path',
204 );
205
206 sub org_unit_ancestors {
207         my $self = shift;
208         my $client = shift;
209         my $id = shift;
210
211         return undef unless ($id);
212
213         my $func = 'actor.org_unit_ancestors(?)';
214
215         my $sth = actor::org_unit->db_Main->prepare_cached("SELECT * FROM $func");
216         $sth->execute(''.$id);
217
218         $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
219
220         return undef;
221 }
222 __PACKAGE__->register_method(
223         api_name        => 'open-ils.storage.actor.org_unit.ancestors',
224         api_level       => 1,
225         stream          => 1,
226         method          => 'org_unit_ancestors',
227 );
228
229 sub org_unit_descendants {
230         my $self = shift;
231         my $client = shift;
232         my $id = shift;
233         my $depth = shift;
234
235         return undef unless ($id);
236
237         my $func = 'actor.org_unit_descendants(?)';
238         if (defined $depth) {
239                 $func = 'actor.org_unit_descendants(?,?)';
240         }
241
242         my $sth = actor::org_unit->db_Main->prepare_cached("SELECT * FROM $func");
243         $sth->execute(''.$id, ''.$depth) if (defined $depth);
244         $sth->execute(''.$id) unless (defined $depth);
245
246         $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
247
248         return undef;
249 }
250 __PACKAGE__->register_method(
251         api_name        => 'open-ils.storage.actor.org_unit.descendants',
252         api_level       => 1,
253         stream          => 1,
254         method          => 'org_unit_descendants',
255 );
256
257 sub profile_all {
258         my $self = shift;
259         my $client = shift;
260
261         for my $rec ( actor::profile->retrieve_all ) {
262                 $client->respond( $rec->to_fieldmapper );
263         }
264
265         return undef;
266 }
267 __PACKAGE__->register_method(
268         method          => 'profile_all',
269         api_name        => 'open-ils.storage.direct.actor.profile.retrieve.all',
270         argc            => 0,
271         stream          => 1,
272 );
273
274
275 1;