aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2015-10-23 14:58:30 +0100
committerMatthew Somerville <matthew@mysociety.org>2015-10-23 14:58:30 +0100
commitda52879e407ffa683567e349c744f30171065a76 (patch)
tree4d02bc41b672de596903d8224894bb10745c7f12 /perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
parent239148e9ba1e55ce205f4ec134c0baab104b0208 (diff)
parentaf7a602d2c83bdf0371ae253f5ba3f80cece077d (diff)
Merge branch '1251-json-status-page'
Diffstat (limited to 'perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm')
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm30
1 files changed, 17 insertions, 13 deletions
diff --git a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
index db4b6e23e..bf1c68c49 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
@@ -113,6 +113,13 @@ sub send_questionnaires_period {
sub timeline {
my ( $rs, $restriction ) = @_;
+ my $attrs;
+ if (%$restriction) {
+ $attrs = {
+ -select => [qw/me.*/],
+ prefetch => [qw/problem/],
+ }
+ }
return $rs->search(
{
-or => {
@@ -121,24 +128,21 @@ sub timeline {
},
%{ $restriction },
},
- {
- -select => [qw/me.*/],
- prefetch => [qw/problem/],
- }
+ $attrs
);
}
sub summary_count {
my ( $rs, $restriction ) = @_;
- return $rs->search(
- $restriction,
- {
- group_by => [ \'whenanswered is not null' ],
- select => [ \'(whenanswered is not null)', { count => 'me.id' } ],
- as => [qw/answered questionnaire_count/],
- join => 'problem'
- }
- );
+ my $params = {
+ group_by => [ \'whenanswered is not null' ],
+ select => [ \'(whenanswered is not null)', { count => 'me.id' } ],
+ as => [qw/answered questionnaire_count/],
+ };
+ if (%$restriction) {
+ $params->{join} = 'problem';
+ }
+ return $rs->search($restriction, $params);
}
1;