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',
37 my $c = actor::card->table;
38 my $p = actor::user->table;
40 my $sql = "SELECT c.barcode FROM $c c JOIN $p p ON (c.usr = p.id) WHERE p.card <> c.id";
42 my $list = actor::user->db_Main->selectcol_arrayref($sql);
43 for my $bc ( @$list ) {
44 $client->respond($bc);
48 __PACKAGE__->register_method(
49 api_name => 'open-ils.storage.actor.user.lost_barcodes',
52 method => 'lost_barcodes',
53 signature => <<' NOTE',
54 Returns an array of barcodes that belong to lost cards.
55 @return array of barcodes
59 sub expired_barcodes {
63 my $c = actor::card->table;
64 my $p = actor::user->table;
66 my $sql = "SELECT c.barcode FROM $c c JOIN $p p ON (c.usr = p.id) WHERE p.expire_date < CURRENT_DATE";
68 my $list = actor::user->db_Main->selectcol_arrayref($sql);
69 for my $bc ( @$list ) {
70 $client->respond($bc);
74 __PACKAGE__->register_method(
75 api_name => 'open-ils.storage.actor.user.expired_barcodes',
78 method => 'expired_barcodes',
79 signature => <<' NOTE',
80 Returns an array of barcodes that are currently expired.
81 @return array of barcodes
89 my $c = actor::card->table;
90 my $p = actor::user->table;
92 my $sql = "SELECT c.barcode FROM $c c JOIN $p p ON (c.usr = p.id) WHERE p.barred IS TRUE";
94 my $list = actor::user->db_Main->selectcol_arrayref($sql);
95 for my $bc ( @$list ) {
96 $client->respond($bc);
100 __PACKAGE__->register_method(
101 api_name => 'open-ils.storage.actor.user.barred_barcodes',
104 method => 'barred_barcodes',
105 signature => <<' NOTE',
106 Returns an array of barcodes that are currently barred.
107 @return array of barcodes
111 sub penalized_barcodes {
116 my $c = actor::card->table;
117 my $p = actor::user_standing_penalty->table;
119 my $sql = "SELECT c.barcode FROM $c c JOIN $p p USING (usr)";
122 $sql .= ' WHERE penalty_type NOT IN ('. join(',', map { '?' } @ignore) . ')';
125 $sql .= ' GROUP BY c.barcode;';
127 my $list = actor::user->db_Main->selectcol_arrayref($sql, {}, @ignore);
128 for my $bc ( @$list ) {
129 $client->respond($bc);
133 __PACKAGE__->register_method(
134 api_name => 'open-ils.storage.actor.user.penalized_barcodes',
137 method => 'penalized_barcodes',
138 signature => <<' NOTE',
139 Returns an array of barcodes that have penalties not listed
140 as a parameter. Supply a list of any penalty types that should
141 not stop a patron from checking out materials.
143 @param ignore_list Penalty type to ignore
144 @return array of barcodes
153 my $limit = shift || 1000;
155 $sort = ['family_name','first_given_name'] unless ($$sort[0]);
159 # group 2 = phone, ident
161 my $usr = join ' AND ', map { "LOWER($_) ~ ?" } grep { ''.$$search{$_}{group} eq '0' } keys %$search;
162 my @usrv = map { "^$$search{$_}{value}" } grep { ''.$$search{$_}{group} eq '0' } keys %$search;
164 my $addr = join ' AND ', map { "LOWER($_) ~ ?" } grep { ''.$$search{$_}{group} eq '1' } keys %$search;
165 my @addrv = map { "^$$search{$_}{value}" } grep { ''.$$search{$_}{group} eq '1' } keys %$search;
167 my $pv = $$search{phone}{value};
168 my $iv = $$search{ident}{value};
169 my $nv = $$search{name}{value};
175 for my $p ( qw/day_phone evening_phone other_phone/ ) {
176 push @ps, "LOWER($p) ~ ?";
177 push @phonev, "^$pv";
179 $phone = '(' . join(' OR ', @ps) . ')';
186 for my $i ( qw/ident_value ident_value2/ ) {
187 push @is, "LOWER($i) ~ ?";
188 push @identv, "^$iv";
190 $ident = '(' . join(' OR ', @is) . ')';
197 for my $n ( qw/first_given_name second_given_name family_name/ ) {
198 push @ns, "LOWER($i) ~ ?";
201 $name = '(' . join(' OR ', @ns) . ')';
204 my $usr_where = join ' AND ', grep { $_ } ($usr,$phone,$ident,$name);
205 my $addr_where = $addr;
208 my $u_table = actor::user->table;
209 my $a_table = actor::user_address->table;
211 my $u_select = "SELECT id as id FROM $u_table u WHERE $usr_where";
212 my $a_select = "SELECT usr as id FROM $a_table a WHERE $addr_where";
217 $select = "$u_select INTERSECT $a_select";
221 } elsif ($addr_where) {
227 my $order_by = join ', ', map { 'users.'. $_} @$sort;
229 $select = "SELECT users.id FROM $u_table AS users JOIN ($select) AS search USING (id) ORDER BY $order_by LIMIT $limit";
231 return actor::user->db_Main->selectcol_arrayref($select, {}, map {lc($_)} (@usrv,@phonev,@identv,@namev,@addrv));
233 __PACKAGE__->register_method(
234 api_name => 'open-ils.storage.actor.user.crazy_search',
236 method => 'patron_search',
239 =comment not gonna use it...
244 my $searches = shift;
246 return undef unless (defined $searches);
248 for my $usr ( actor::user->search( $searches ) ) {
250 $client->respond( flesh_user( $usr ) );
254 __PACKAGE__->register_method(
255 api_name => 'open-ils.storage.fleshed.actor.user.search',
257 method => 'fleshed_search',
262 sub fleshed_search_like {
265 my $searches = shift;
267 return undef unless (defined $searches);
269 for my $usr ( actor::user->search_like( $searches ) ) {
271 $client->respond( flesh_user( $usr ) );
275 __PACKAGE__->register_method(
276 api_name => 'open-ils.storage.fleshed.actor.user.search_like',
278 method => 'user_by_barcode',
283 sub retrieve_fleshed_user {
288 return undef unless @ids;
290 @ids = ($ids[0]) unless ($self->api_name =~ /batch/o);
292 $client->respond( flesh_user( actor::user->retrieve( $_ ) ) ) for ( @ids );
296 __PACKAGE__->register_method(
297 api_name => 'open-ils.storage.fleshed.actor.user.retrieve',
299 method => 'retrieve_fleshed_user',
302 __PACKAGE__->register_method(
303 api_name => 'open-ils.storage.fleshed.actor.user.batch.retrieve',
305 method => 'retrieve_fleshed_user',
314 my $standing = $usr->standing;
315 my $profile = $usr->profile;
316 my $ident_type = $usr->ident_type;
318 my $maddress = $usr->mailing_address;
319 my $baddress = $usr->billing_address;
320 my $card = $usr->card;
322 my @addresses = $usr->addresses;
323 my @cards = $usr->cards;
325 my $usr_fm = $usr->to_fieldmapper;
326 $usr_fm->standing( $standing->to_fieldmapper );
327 $usr_fm->profile( $profile->to_fieldmapper );
328 $usr_fm->ident_type( $ident_type->to_fieldmapper );
330 $usr_fm->card( $card->to_fieldmapper );
331 $usr_fm->mailing_address( $maddress->to_fieldmapper ) if ($maddress);
332 $usr_fm->billing_address( $baddress->to_fieldmapper ) if ($baddress);
334 $usr_fm->cards( [ map { $_->to_fieldmapper } @cards ] );
335 $usr_fm->addresses( [ map { $_->to_fieldmapper } @addresses ] );
346 my $select =<<" SQL";
349 ORDER BY CASE WHEN parent_ou IS NULL THEN 0 ELSE 1 END, name;
352 my $sth = actor::org_unit->db_Main->prepare_cached($select);
355 $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
359 __PACKAGE__->register_method(
360 api_name => 'open-ils.storage.direct.actor.org_unit.retrieve.all',
363 method => 'org_unit_list',
366 sub org_unit_type_list {
370 my $select =<<" SQL";
372 FROM actor.org_unit_type
373 ORDER BY depth, name;
376 my $sth = actor::org_unit_type->db_Main->prepare_cached($select);
379 $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit_type->construct($_) } $sth->fetchall_hash );
383 __PACKAGE__->register_method(
384 api_name => 'open-ils.storage.direct.actor.org_unit_type.retrieve.all',
387 method => 'org_unit_type_list',
390 sub org_unit_full_path {
395 return undef unless (@binds);
397 my $func = 'actor.org_unit_full_path(?)';
398 $func = 'actor.org_unit_full_path(?,?)' if (@binds > 1);
400 my $sth = actor::org_unit->db_Main->prepare_cached("SELECT * FROM $func");
401 $sth->execute(@binds);
403 $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
407 __PACKAGE__->register_method(
408 api_name => 'open-ils.storage.actor.org_unit.full_path',
411 method => 'org_unit_full_path',
414 sub org_unit_ancestors {
419 return undef unless ($id);
421 my $func = 'actor.org_unit_ancestors(?)';
423 my $sth = actor::org_unit->db_Main->prepare_cached(<<" SQL");
426 JOIN actor.org_unit_type t ON (f.ou_type = t.id)
427 ORDER BY t.depth, f.name;
429 $sth->execute(''.$id);
431 $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
435 __PACKAGE__->register_method(
436 api_name => 'open-ils.storage.actor.org_unit.ancestors',
439 method => 'org_unit_ancestors',
442 sub org_unit_descendants {
448 return undef unless ($id);
450 my $func = 'actor.org_unit_descendants(?)';
451 if (defined $depth) {
452 $func = 'actor.org_unit_descendants(?,?)';
455 my $sth = actor::org_unit->db_Main->prepare_cached("SELECT * FROM $func");
456 $sth->execute(''.$id, ''.$depth) if (defined $depth);
457 $sth->execute(''.$id) unless (defined $depth);
459 $client->respond( $_->to_fieldmapper ) for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
463 __PACKAGE__->register_method(
464 api_name => 'open-ils.storage.actor.org_unit.descendants',
467 method => 'org_unit_descendants',
474 for my $rec ( actor::profile->retrieve_all ) {
475 $client->respond( $rec->to_fieldmapper );
480 __PACKAGE__->register_method(
481 method => 'profile_all',
482 api_name => 'open-ils.storage.direct.actor.profile.retrieve.all',
487 sub fleshed_actor_stat_cat {
492 @list = ($list[0]) unless ($self->api_name =~ /batch/o);
495 my $cat = actor::stat_cat->retrieve($sc);
498 my $sc_fm = $cat->to_fieldmapper;
499 $sc_fm->entries( [ map { $_->to_fieldmapper } $cat->entries ] );
501 $client->respond( $sc_fm );
507 __PACKAGE__->register_method(
508 api_name => 'open-ils.storage.fleshed.actor.stat_cat.retrieve',
511 method => 'fleshed_actor_stat_cat',
514 __PACKAGE__->register_method(
515 api_name => 'open-ils.storage.fleshed.actor.stat_cat.retrieve.batch',
519 method => 'fleshed_actor_stat_cat',
522 #XXX Fix stored proc calls
523 sub ranged_actor_stat_cat_all {
528 return undef unless ($ou);
529 my $s_table = actor::stat_cat->table;
531 my $select = <<" SQL";
534 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
539 $fleshed = 1 if ($self->api_name =~ /fleshed/o);
541 my $sth = actor::stat_cat->db_Main->prepare_cached($select);
544 for my $sc ( map { actor::stat_cat->construct($_) } $sth->fetchall_hash ) {
545 my $sc_fm = $sc->to_fieldmapper;
547 [ $self->method_lookup( 'open-ils.storage.ranged.actor.stat_cat_entry.search.stat_cat' )->run($ou,$sc->id) ]
549 $client->respond( $sc_fm );
554 __PACKAGE__->register_method(
555 api_name => 'open-ils.storage.ranged.fleshed.actor.stat_cat.all',
559 method => 'ranged_actor_stat_cat_all',
562 __PACKAGE__->register_method(
563 api_name => 'open-ils.storage.ranged.actor.stat_cat.all',
567 method => 'ranged_actor_stat_cat_all',
570 #XXX Fix stored proc calls
571 sub ranged_actor_stat_cat_entry {
577 return undef unless ($ou);
578 my $s_table = actor::stat_cat_entry->table;
580 my $select = <<" SQL";
583 JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
588 my $sth = actor::stat_cat->db_Main->prepare_cached($select);
589 $sth->execute($ou,$sc);
591 for my $sce ( map { actor::stat_cat_entry->construct($_) } $sth->fetchall_hash ) {
592 $client->respond( $sce->to_fieldmapper );
597 __PACKAGE__->register_method(
598 api_name => 'open-ils.storage.ranged.actor.stat_cat_entry.search.stat_cat',
601 method => 'ranged_actor_stat_cat_entry',