]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm
updating surveys
[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 find_local_surveys {
10         my $self = shift;
11         my $client = shift;
12         my $ou = ''.shift();
13
14         return undef unless ($ou);
15
16         my $select = <<"        SQL";
17                 SELECT  s.*
18                   FROM  action.survey s
19                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
20                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
21         SQL
22
23         my $sth = action::survey->db_Main->prepare_cached($select);
24         $sth->execute($ou);
25
26         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
27
28         return undef;
29 }
30 __PACKAGE__->register_method(
31         api_name        => 'open-ils.storage.action.survey.all',
32         api_level       => 1,
33         stream          => 1,
34         method          => 'find_local_surveys',
35 );
36
37 sub find_opac_surveys {
38         my $self = shift;
39         my $client = shift;
40         my $ou = ''.shift();
41
42         return undef unless ($ou);
43
44         my $select = <<"        SQL";
45                 SELECT  s.*
46                   FROM  action.survey s
47                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
48                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
49                         AND s.opac IS TRUE;
50         SQL
51
52         my $sth = action::survey->db_Main->prepare_cached($select);
53         $sth->execute($ou);
54
55         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
56
57         return undef;
58 }
59 __PACKAGE__->register_method(
60         api_name        => 'open-ils.storage.action.survey.opac',
61         api_level       => 1,
62         stream          => 1,
63         method          => 'find_opac_surveys',
64 );
65
66 sub find_optional_surveys {
67         my $self = shift;
68         my $client = shift;
69         my $ou = ''.shift();
70
71         return undef unless ($ou);
72
73         my $select = <<"        SQL";
74                 SELECT  s.*
75                   FROM  action.survey s
76                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
77                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
78                         AND s.required IS FALSE;
79         SQL
80
81         my $sth = action::survey->db_Main->prepare_cached($select);
82         $sth->execute($ou);
83
84         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
85
86         return undef;
87 }
88 __PACKAGE__->register_method(
89         api_name        => 'open-ils.storage.action.survey.optional',
90         api_level       => 1,
91         stream          => 1,
92         method          => 'find_optional_surveys',
93 );
94
95 sub find_required_surveys {
96         my $self = shift;
97         my $client = shift;
98         my $ou = ''.shift();
99
100         return undef unless ($ou);
101
102         my $select = <<"        SQL";
103                 SELECT  s.*
104                   FROM  action.survey s
105                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
106                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
107                         AND s.required IS TRUE;
108         SQL
109
110         my $sth = action::survey->db_Main->prepare_cached($select);
111         $sth->execute($ou);
112
113         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
114
115         return undef;
116 }
117 __PACKAGE__->register_method(
118         api_name        => 'open-ils.storage.action.survey.required',
119         api_level       => 1,
120         stream          => 1,
121         method          => 'find_required_surveys',
122 );
123
124 sub find_usr_summary_surveys {
125         my $self = shift;
126         my $client = shift;
127         my $ou = ''.shift();
128
129         return undef unless ($ou);
130
131         my $select = <<"        SQL";
132                 SELECT  s.*
133                   FROM  action.survey s
134                         JOIN actor.org_unit_full_path(?) p ON (p.id = s.owner)
135                   WHERE CURRENT_DATE BETWEEN s.start_date AND s.end_date
136                         AND s.usr_summary IS TRUE;
137         SQL
138
139         my $sth = action::survey->db_Main->prepare_cached($select);
140         $sth->execute($ou);
141
142         $client->respond( $_->to_fieldmapper ) for ( map { action::survey->construct($_) } $sth->fetchall_hash );
143
144         return undef;
145 }
146 __PACKAGE__->register_method(
147         api_name        => 'open-ils.storage.action.survey.usr_summary',
148         api_level       => 1,
149         stream          => 1,
150         method          => 'find_usr_summary_surveys',
151 );
152
153
154 1;