]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm
big changes... big
[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         my @fms;
149         push @fms, $_->to_fieldmapper for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
150
151         return \@fms;
152 }
153 __PACKAGE__->register_method(
154         api_name        => 'open-ils.storage.direct.actor.org_unit.retrieve.all',
155         api_level       => 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         my @fms;
173         push @fms, $_->to_fieldmapper for ( map { actor::org_unit_type->construct($_) } $sth->fetchall_hash );
174
175         return \@fms;
176 }
177 __PACKAGE__->register_method(
178         api_name        => 'open-ils.storage.direct.actor.org_unit_type.retrieve.all',
179         api_level       => 1,
180         method          => 'org_unit_type_list',
181 );
182
183 sub org_unit_descendants {
184         my $self = shift;
185         my $client = shift;
186         my $id = shift;
187
188         return undef unless ($id);
189
190         my $select =<<" SQL";
191         SELECT  a.*
192           FROM  connectby('actor.org_unit','id','parent_ou','name',?,'100','.')
193                         as t(keyid text, parent_keyid text, level int, branch text,pos int),
194                 actor.org_unit a
195           WHERE t.keyid = a.id
196           ORDER BY t.pos;
197         SQL
198
199         my $sth = actor::org_unit->db_Main->prepare_cached($select);
200         $sth->execute($id);
201
202         my @fms;
203         push @fms, $_->to_fieldmapper for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
204
205         return \@fms;
206 }
207 __PACKAGE__->register_method(
208         api_name        => 'open-ils.storage.actor.org_unit.descendants',
209         api_level       => 1,
210         method          => 'org_unit_descendants',
211 );
212
213
214 1;