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