aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm59
-rw-r--r--templates/web/default/admin/header.html3
-rw-r--r--templates/web/default/admin/index.html2
-rw-r--r--templates/web/default/admin/questionnaire.html21
4 files changed, 47 insertions, 38 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 68f41c21a..565737e54 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -62,10 +62,12 @@ sub index : Path : Args(0) {
$c->stash->{contacts} = \%contact_counts;
my $questionnaires = $c->model('DB::Questionnaire')->search(
- undef, { group_by => [ \'whenanswered is not null' ], select => [ \'(whenanswered is not null)', { count => 'me.id' } ], as => [qw/answered questionnaire_count/] }
+ undef, { group_by => [ \'whenanswered is not null' ], select => [ \'(whenanswered is not null)', { count => 'me.id' } ], as => [qw/answered questionnaire_count/], join => 'problem' }
);
my %questionnaire_counts = map { $_->get_column( 'answered' ) => $_->get_column( 'questionnaire_count' ) } $questionnaires->all;
+ $questionnaire_counts{1} ||= 0;
+ $questionnaire_counts{0} ||= 0;
$questionnaire_counts{total} = $questionnaire_counts{0} + $questionnaire_counts{1};
$c->stash->{questionnaires_pc} = $questionnaire_counts{total} ? sprintf('%.1f', $questionnaire_counts{1} / $questionnaire_counts{total} * 100) : 'na';
@@ -74,6 +76,26 @@ sub index : Path : Args(0) {
return 1;
}
+sub questionnaire : Path('questionnaire') : Args(0) {
+ my ( $self, $c ) = @_;
+
+ my $questionnaires = $c->model('DB::Questionnaire')->search(
+ { whenanswered => \'is not null' }, { group_by => [ 'ever_reported' ], select => [ 'ever_reported', { count => 'me.id' } ], as => [qw/reported questionnaire_count/] }
+ );
+
+
+ my %questionnaire_counts = map { $_->get_column( 'reported' ) => $_->get_column( 'questionnaire_count' ) } $questionnaires->all;
+
+ $questionnaire_counts{1} ||= 0;
+ $questionnaire_counts{0} ||= 0;
+
+ $questionnaire_counts{total} = $questionnaire_counts{0} + $questionnaire_counts{1};
+ $c->stash->{reported_pc} = ( 100 * $questionnaire_counts{1} ) / $questionnaire_counts{total};
+ $c->stash->{not_reported_pc} = ( 100 * $questionnaire_counts{0} ) / $questionnaire_counts{total};
+ $c->stash->{questionnaires} = \%questionnaire_counts;
+
+ return 1;
+}
# use Encode;
# use POSIX qw(strftime strcoll);
# use Digest::MD5 qw(md5_hex);
@@ -842,41 +864,6 @@ sub index : Path : Args(0) {
#
# }
#
-# sub admin_questionnaire {
-# my $q = shift;
-# my $cobrand = Page::get_cobrand($q);
-# print html_head($q, _('Survey Results'));
-# print $q->h1(_('Survey Results'));
-#
-# # columns in questionnaire is id, problem_id, whensent,
-# # whenanswered, ever_reported, old_state, new_state
-#
-# my $survey = select_all("select ever_reported, count(*) from questionnaire where whenanswered is not null group by ever_reported");
-#
-# my %res;
-# $res{0} = 0;
-# $res{1} = 0;
-# foreach my $h (@$survey) {
-# $res{$h->{ever_reported}} = $h->{count} if (exists $h->{ever_reported});
-# }
-# my $total = $res{0} + $res{1};
-#
-# print $q->start_table({border=>1});
-# print $q->Tr({},
-# $q->th({}, [_("Reported before"),
-# _("Not reported before")]));
-# if ($total) {
-# print $q->Tr({},
-# $q->td([
-# sprintf("%d (%d%%)", $res{1}, (100 * $res{1}) / $total),
-# sprintf("%d (%d%%)", $res{0}, (100 * $res{0}) / $total),
-# ]));
-# } else {
-# print $q->Tr({}, $q->td([ 'n/a', 'n/a' ]));
-# }
-# print $q->end_table();
-# print html_tail($q);
-# }
#
# sub not_found {
# my ($q) = @_;
diff --git a/templates/web/default/admin/header.html b/templates/web/default/admin/header.html
index 5db365a2a..cbc7fcec1 100644
--- a/templates/web/default/admin/header.html
+++ b/templates/web/default/admin/header.html
@@ -15,3 +15,6 @@ dd { margin-left: 8em; }
<a href="">[% loc('Search Reports') %]</a>
<a href="">[% loc('Timeline') %]</a>
<a href="">[% loc('Survey Results') %]</a>
+
+ <h1>[% title %]</h1>
+
diff --git a/templates/web/default/admin/index.html b/templates/web/default/admin/index.html
index ddc822b22..277d2ea76 100644
--- a/templates/web/default/admin/index.html
+++ b/templates/web/default/admin/index.html
@@ -10,8 +10,6 @@
[% END %]
[% END %]
-<h1>Summary</h1>
-
<ul>
<li>[% tprintf( loc('<strong>%d</strong> live problems'), total_problems_live ) %]</li>
<li>[% tprintf( loc('%d live updates'), comments.confirmed ) %]</li>
diff --git a/templates/web/default/admin/questionnaire.html b/templates/web/default/admin/questionnaire.html
new file mode 100644
index 000000000..5a9c74b5e
--- /dev/null
+++ b/templates/web/default/admin/questionnaire.html
@@ -0,0 +1,21 @@
+[% INCLUDE 'admin/header.html' title=loc('Survey Results') %]
+
+<table border="1">
+ <tr>
+ <th>[% loc('Reported before') %]</th>
+ <th>[% loc('Not reported before') %]</th>
+ </tr>
+ [% IF questionnaires.total > 0 %]
+ <tr>
+ <td>[% questionnaires.1 %] ([% reported_pc %]%)</td>
+ <td>[% questionnaires.0 %] ([% not_reported_pc %]%)</td>
+ </tr>
+ [% ELSE %]
+ <tr>
+ <td>n/a</td>
+ <td>n/a</td>
+ </tr>
+ [% END %]
+</table>
+
+[% INCLUDE 'admin/footer.html' %]