]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm
added action.survey_response.response_group_id
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Storage / Publisher / action.pm
1 package OpenILS::Application::Storage::Publisher::action;
2 use base qw/OpenILS::Application::Storage/;
3 #use OpenILS::Application::Storage::CDBI::action;
4 #use OpenSRF::Utils::Logger qw/:level/;
5 #use OpenILS::Utils::Fieldmapper;
6 #
7 #my $log = 'OpenSRF::Utils::Logger';
8
9 sub next_resp_group_id {
10         my $self = shift;
11         my $client = shift;
12
13         # XXX This is not replication safe!!!
14
15         my ($id) = action::survey->db_Main->selectrow_array(<<" SQL");
16                 SELECT NEXTVAL('action.survey_response_group_id_seq'::TEXT)
17         SQL
18         return $id;
19 }
20 __PACKAGE__->register_method(
21         api_name        => 'open-ils.storage.action.survey_response.next_group_id',
22         api_level       => 1,
23         method          => 'next_resp_group_id',
24 );
25
26 sub patron_circ_summary {
27         my $self = shift;
28         my $client = shift;
29         my $id = ''.shift();
30
31         return undef unless ($id);
32         my $c_table = action::circulation->table;
33         my $b_table = money::billing->table;
34
35         my $select = <<"        SQL";
36                 SELECT  COUNT(DISTINCT c.id), SUM( COALESCE(b.amount,0) )
37                   FROM  $c_table c
38                         LEFT OUTER JOIN $b_table b ON (c.id = b.xact)
39                   WHERE c.usr = ?
40                         AND c.xact_finish IS NULL
41                         AND c.stop_fines NOT IN ('CLAIMSRETURNED','LOST')
42         SQL
43
44         return action::survey->db_Main->selectrow_arrayref($select, {}, $id);
45 }
46 __PACKAGE__->register_method(
47         api_name        => 'open-ils.storage.action.circulation.patron_summary',
48         api_level       => 1,
49         method          => 'patron_circ_summary',
50 );
51
52 #XXX Fix stored proc calls
53 sub find_local_surveys {
54         my $self = shift;
55         my $client = shift;
56         my $ou = ''.shift();
57
58         return undef unless ($ou);
59         my $s_table = action::survey->table;
60
61         my $select = <<"        SQL";
62                 SELECT  s.*
63                   FROM  $s_table s
64                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
65                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
66         SQL
67
68         my $sth = action::survey->db_Main->prepare_cached($select);
69         $sth->execute($ou);
70
71         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
72
73         return undef;
74 }
75 __PACKAGE__->register_method(
76         api_name        => 'open-ils.storage.action.survey.all',
77         api_level       => 1,
78         stream          => 1,
79         method          => 'find_local_surveys',
80 );
81
82 #XXX Fix stored proc calls
83 sub find_opac_surveys {
84         my $self = shift;
85         my $client = shift;
86         my $ou = ''.shift();
87
88         return undef unless ($ou);
89         my $s_table = action::survey->table;
90
91         my $select = <<"        SQL";
92                 SELECT  s.*
93                   FROM  $s_table s
94                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
95                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
96                         AND s.opac IS TRUE;
97         SQL
98
99         my $sth = action::survey->db_Main->prepare_cached($select);
100         $sth->execute($ou);
101
102         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
103
104         return undef;
105 }
106 __PACKAGE__->register_method(
107         api_name        => 'open-ils.storage.action.survey.opac',
108         api_level       => 1,
109         stream          => 1,
110         method          => 'find_opac_surveys',
111 );
112
113 sub find_optional_surveys {
114         my $self = shift;
115         my $client = shift;
116         my $ou = ''.shift();
117
118         return undef unless ($ou);
119         my $s_table = action::survey->table;
120
121         my $select = <<"        SQL";
122                 SELECT  s.*
123                   FROM  $s_table s
124                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
125                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
126                         AND s.required IS FALSE;
127         SQL
128
129         my $sth = action::survey->db_Main->prepare_cached($select);
130         $sth->execute($ou);
131
132         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
133
134         return undef;
135 }
136 __PACKAGE__->register_method(
137         api_name        => 'open-ils.storage.action.survey.optional',
138         api_level       => 1,
139         stream          => 1,
140         method          => 'find_optional_surveys',
141 );
142
143 sub find_required_surveys {
144         my $self = shift;
145         my $client = shift;
146         my $ou = ''.shift();
147
148         return undef unless ($ou);
149         my $s_table = action::survey->table;
150
151         my $select = <<"        SQL";
152                 SELECT  s.*
153                   FROM  $s_table s
154                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
155                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
156                         AND s.required IS TRUE;
157         SQL
158
159         my $sth = action::survey->db_Main->prepare_cached($select);
160         $sth->execute($ou);
161
162         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
163
164         return undef;
165 }
166 __PACKAGE__->register_method(
167         api_name        => 'open-ils.storage.action.survey.required',
168         api_level       => 1,
169         stream          => 1,
170         method          => 'find_required_surveys',
171 );
172
173 sub find_usr_summary_surveys {
174         my $self = shift;
175         my $client = shift;
176         my $ou = ''.shift();
177
178         return undef unless ($ou);
179         my $s_table = action::survey->table;
180
181         my $select = <<"        SQL";
182                 SELECT  s.*
183                   FROM  $s_table s
184                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
185                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
186                         AND s.usr_summary IS TRUE;
187         SQL
188
189         my $sth = action::survey->db_Main->prepare_cached($select);
190         $sth->execute($ou);
191
192         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
193
194         return undef;
195 }
196 __PACKAGE__->register_method(
197         api_name        => 'open-ils.storage.action.survey.usr_summary',
198         api_level       => 1,
199         stream          => 1,
200         method          => 'find_usr_summary_surveys',
201 );
202
203
204 1;