]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/actor.pm
f312b8e0d0c08b7e765e55390183a7cef1eab939
[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 org_unit_list {
10         my $self = shift;
11         my $client = shift;
12
13         my $select =<<" SQL";
14         SELECT  *
15           FROM  actor.org_unit
16           ORDER BY CASE WHEN parent_ou IS NULL THEN 0 ELSE 1 END, name;
17         SQL
18
19         my $sth = actor::org_unit->db_Main->prepare_cached($select);
20         $sth->execute;
21
22         my @fms;
23         push @fms, $_->to_fieldmapper for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
24
25         return \@fms;
26 }
27 __PACKAGE__->register_method(
28         api_name        => 'open-ils.storage.actor.org_unit_list',
29         api_level       => 1,
30         method          => 'org_unit_list',
31 );
32
33 sub org_unit_descendants {
34         my $self = shift;
35         my $client = shift;
36         my $id = shift;
37
38         return undef unless ($id);
39
40         my $select =<<" SQL";
41         SELECT  a.*
42           FROM  connectby('actor.org_unit','id','parent_ou','name',?,'100','.')
43                         as t(keyid text, parent_keyid text, level int, branch text,pos int),
44                 actor.org_unit a
45           WHERE t.keyid = a.id
46           ORDER BY t.pos;
47         SQL
48
49         my $sth = actor::org_unit->db_Main->prepare_cached($select);
50         $sth->execute($id);
51
52         my @fms;
53         push @fms, $_->to_fieldmapper for ( map { actor::org_unit->construct($_) } $sth->fetchall_hash );
54
55         return \@fms;
56 }
57 __PACKAGE__->register_method(
58         api_name        => 'open-ils.storage.actor.org_unit_descendants',
59         api_level       => 1,
60         method          => 'org_unit_descendants',
61 );
62
63
64 sub get_user_record {
65         my $self = shift;
66         my $client = shift;
67         my @ids = @_;
68
69         my $search_field = 'id';
70         $search_field = 'usrname' if ($self->api_name =~/userid/o);
71         $search_field = 'usrname' if ($self->api_name =~/username/o);
72
73         for my $id ( @ids ) {
74                 next unless ($id);
75                 
76                 $log->debug("Searching for $id using ".$self->api_name, DEBUG);
77
78                 my ($rec) = actor::user->fast_fieldmapper($search_field => "$id");
79                 $client->respond( $rec ) if ($rec);
80
81                 last if ($self->api_name !~ /list$/o);
82         }
83         return undef;
84 }
85 #__PACKAGE__->register_method(
86         #method         => 'get_user_record',
87         #api_name       => 'open-ils.storage.actor.user.retrieve',
88         #api_level      => 1,
89         #argc           => 1,
90 #);
91 #__PACKAGE__->register_method(
92         #method         => 'get_user_record',
93         #api_name       => 'open-ils.storage.actor.user.search.username',
94         #api_level      => 1,
95         #argc           => 1,
96 #);
97 #__PACKAGE__->register_method(
98         #method         => 'get_user_record',
99         #api_name       => 'open-ils.storage.actor.user.search.userid',
100         #api_level      => 1,
101         #argc           => 1,
102 #);
103 #__PACKAGE__->register_method(
104         #method         => 'get_user_record',
105         #api_name       => 'open-ils.storage.actor.user.retrieve.list',
106         #api_level      => 1,
107         #argc           => 1,
108 #);
109 #__PACKAGE__->register_method(
110         #method         => 'get_user_record',
111         #api_name       => 'open-ils.storage.actor.user.search.username.list',
112         #api_level      => 1,
113         #stream         => 1,
114         #argc           => 1,
115 #);
116 #__PACKAGE__->register_method(
117         #method         => 'get_user_record',
118         #api_name       => 'open-ils.storage.actor.user.search.userid.list',
119         #api_level      => 1,
120         #stream         => 1,
121         #argc           => 1,
122 #);
123
124 sub update_user_record {
125         my $self = shift;
126         my $client = shift;
127         my $user = shift;
128
129         my $rec = actor::user->update($user);
130         return 0 unless ($rec);
131         return 1;
132 }
133 #__PACKAGE__->register_method(
134         #method          => 'update_user_record',
135         #api_name        => 'open-ils.storage.actor.user.update',
136         #api_level       => 1,
137         #argc            => 1,
138 #);
139
140 sub delete_record_entry {
141         my $self = shift;
142         my $client = shift;
143         my $user = shift;
144
145         my $rec = actor::user->delete($user);
146         return 0 unless ($rec);
147         return 1;
148 }
149 #__PACKAGE__->register_method(
150         #method          => 'delete_user_record',
151         #api_name        => 'open-ils.storage.actor.user.delete',
152         #api_level       => 1,
153         #argc            => 1,
154 #);
155
156 1;