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 } ) ) {
19 return $card->usr->to_fieldmapper;
21 $client->respond( $card->usr->to_fieldmapper);
25 __PACKAGE__->register_method(
26 api_name => 'open-ils.storage.direct.actor.user.search.barcode',
28 method => 'user_by_barcode',
41 # group 2 = phone, ident
43 my $usr = join ' AND ', map { "LOWER($_) ~ ?" } grep { ''.$$search{$_}{group} eq '0' } keys %$search;
44 my @usrv = map { "^$$search{$_}{value}" } grep { ''.$$search{$_}{group} eq '0' } keys %$search;
46 my $addr = join ' AND ', map { "LOWER($_) ~ ?" } grep { ''.$$search{$_}{group} eq '1' } keys %$search;
47 my @addrv = map { "^$$search{$_}{value}" } grep { ''.$$search{$_}{group} eq '1' } keys %$search;
49 my $pv = $$search{phone}{value};
50 my $iv = $$search{ident}{value};
56 for my $p ( qw/day_phone evening_phone other_phone/ ) {
57 push @ps, "LOWER($p) ~ ?";
60 $phone = '(' . join(' OR ', @ps) . ')';
67 for my $i ( qw/ident_value ident_value2/ ) {
68 push @is, "LOWER($i) ~ ?";
71 $ident = '(' . join(' OR ', @is) . ')';
74 my $usr_where = join ' AND ', grep { $_ } ($usr,$phone,$ident);
75 my $addr_where = $addr;
78 my $u_table = actor::user->table;
79 my $a_table = actor::user_address->table;
81 my $u_select = "SELECT id FROM $u_table a WHERE $usr_where";
82 my $a_select = "SELECT usr FROM $a_table a WHERE $addr_where";
87 $select = "$u_select INTERSECT $a_select";
91 } elsif ($addr_where) {
97 return actor::user->db_Main->selectcol_arrayref($select." LIMIT 1000", {}, map {lc($_)} (@usrv,@phonev,@identv,@addrv));
99 __PACKAGE__->register_method(
100 api_name => 'open-ils.storage.actor.user.crazy_search',
102 method => 'patron_search',
105 =comment not gonna use it...
110 my $searches = shift;
112 return undef unless (defined $searches);
114 for my $usr ( actor::user->search( $searches ) ) {
116 $client->respond( flesh_user( $usr ) );
120 __PACKAGE__->register_method(
121 api_name => 'open-ils.storage.fleshed.actor.user.search',
123 method => 'fleshed_search',
128 sub fleshed_search_like {
131 my $searches = shift;
133 return undef unless (defined $searches);
135 for my $usr ( actor::user->search_like( $searches ) ) {
137 $client->respond( flesh_user( $usr ) );
141 __PACKAGE__->register_method(
142 api_name => 'open-ils.storage.fleshed.actor.user.search_like',
144 method => 'user_by_barcode',
149 sub retrieve_fleshed_user {
154 return undef unless @ids;
156 @ids = ($ids[0]) unless ($self->api_name =~ /batch/o);
158 $client->respond( flesh_user( actor::user->retrieve( $_ ) ) ) for ( @ids );
162 __PACKAGE__->register_method(
163 api_name => 'open-ils.storage.fleshed.actor.user.retrieve',
165 method => 'retrieve_fleshed_user',
168 __PACKAGE__->register_method(
169 api_name => 'open-ils.storage.fleshed.actor.user.batch.retrieve',
171 method => 'retrieve_fleshed_user',
180 my $standing = $usr->standing;
181 my $profile = $usr->profile;
182 my $ident_type = $usr->ident_type;
184 my $maddress = $usr->mailing_address;
185 my $baddress = $usr->billing_address;
186 my $card = $usr->card;
188 my @addresses = $usr->addresses;
189 my @cards = $usr->cards;
191 my $usr_fm = $usr->to_fieldmapper;
192 $usr_fm->standing( $standing->to_fieldmapper );
193 $usr_fm->profile( $profile->to_fieldmapper );
194 $usr_fm->ident_type( $ident_type->to_fieldmapper );
196 $usr_fm->card( $card->to_fieldmapper );
197 $usr_fm->mailing_address( $maddress->to_fieldmapper ) if ($maddress);
198 $usr_fm->billing_address( $baddress->to_fieldmapper ) if ($baddress);
200 $usr_fm->cards( [ map { $_->to_fieldmapper } @cards ] );
201 $usr_fm->addresses( [ map { $_->to_fieldmapper } @addresses ] );
212 my $select =<<" SQL";
215 ORDER BY CASE WHEN parent_ou IS NULL THEN 0 ELSE 1 END, name;
218 my $sth = actor::org_unit->db_Main->prepare_cached($select);
221 $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
225 __PACKAGE__->register_method(
226 api_name => 'open-ils.storage.direct.actor.org_unit.retrieve.all',
229 method => 'org_unit_list',
232 sub org_unit_type_list {
236 my $select =<<" SQL";
238 FROM actor.org_unit_type
239 ORDER BY depth, name;
242 my $sth = actor::org_unit_type->db_Main->prepare_cached($select);
245 $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit_type->construct($_) } $sth->fetchall_hash );
249 __PACKAGE__->register_method(
250 api_name => 'open-ils.storage.direct.actor.org_unit_type.retrieve.all',
253 method => 'org_unit_type_list',
256 sub org_unit_full_path {
262 return undef unless ($id);
264 my $func = 'actor.org_unit_full_path(?)';
265 my $func = 'actor.org_unit_full_path(?,?)' if defined($depth);
267 my $sth = actor::org_unit->db_Main->prepare_cached("SELECT * FROM $func");
268 $sth->execute($id, $depth);
270 $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
274 __PACKAGE__->register_method(
275 api_name => 'open-ils.storage.actor.org_unit.full_path',
278 method => 'org_unit_full_path',
281 sub org_unit_ancestors {
286 return undef unless ($id);
288 my $func = 'actor.org_unit_ancestors(?)';
290 my $sth = actor::org_unit->db_Main->prepare_cached(<<" SQL");
293 JOIN actor.org_unit_type t ON (f.ou_type = t.id)
294 ORDER BY t.depth, f.name;
296 $sth->execute(''.$id);
298 $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
302 __PACKAGE__->register_method(
303 api_name => 'open-ils.storage.actor.org_unit.ancestors',
306 method => 'org_unit_ancestors',
309 sub org_unit_descendants {
315 return undef unless ($id);
317 my $func = 'actor.org_unit_descendants(?)';
318 if (defined $depth) {
319 $func = 'actor.org_unit_descendants(?,?)';
322 my $sth = actor::org_unit->db_Main->prepare_cached("SELECT * FROM $func");
323 $sth->execute(''.$id, ''.$depth) if (defined $depth);
324 $sth->execute(''.$id) unless (defined $depth);
326 $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
330 __PACKAGE__->register_method(
331 api_name => 'open-ils.storage.actor.org_unit.descendants',
334 method => 'org_unit_descendants',
341 for my $rec ( actor::profile->retrieve_all ) {
342 $client->respond( $rec->to_fieldmapper );
347 __PACKAGE__->register_method(
348 method => 'profile_all',
349 api_name => 'open-ils.storage.direct.actor.profile.retrieve.all',
354 #XXX Fix stored proc calls
355 sub ranged_actor_stat_cat {
360 return undef unless ($ou);
361 my $s_table = actor::stat_cat->table;
363 my $select = <<" SQL";
366 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
371 $fleshed = 1 if ($self->api_name =~ /fleshed/o);
373 my $sth = actor::stat_cat->db_Main->prepare_cached($select);
376 for my $sc ( map { actor::stat_cat->construct($_) } $sth->fetchall_hash ) {
377 my $sc_fm = $sc->to_fieldmapper;
379 [ $self->method_lookup( 'open-ils.storage.ranged.actor.stat_cat_entry.search.stat_cat' )->run($ou,$sc->id) ]
381 $client->respond( $sc_fm );
386 __PACKAGE__->register_method(
387 api_name => 'open-ils.storage.ranged.fleshed.actor.stat_cat.all',
390 method => 'ranged_actor_stat_cat',
393 __PACKAGE__->register_method(
394 api_name => 'open-ils.storage.ranged.actor.stat_cat.all',
397 method => 'ranged_actor_stat_cat',
400 #XXX Fix stored proc calls
401 sub ranged_actor_stat_cat_entry {
407 return undef unless ($ou);
408 my $s_table = actor::stat_cat_entry->table;
410 my $select = <<" SQL";
413 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
418 my $sth = actor::stat_cat->db_Main->prepare_cached($select);
419 $sth->execute($ou,$sc);
421 for my $sce ( map { actor::stat_cat_entry->construct($_) } $sth->fetchall_hash ) {
422 $client->respond( $sce->to_fieldmapper );
427 __PACKAGE__->register_method(
428 api_name => 'open-ils.storage.ranged.actor.stat_cat_entry.search.stat_cat',
431 method => 'ranged_actor_stat_cat_entry',