aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm3
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm31
2 files changed, 32 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index abc454600..9fcb0c46d 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -60,6 +60,7 @@ sub index : Path : Args(0) {
$c->stash->{problems} = \%prob_counts;
$c->stash->{total_problems_live} =
$prob_counts{confirmed} + $prob_counts{fixed};
+ $c->stash->{total_problems_users} = $c->cobrand->problems->unique_users;
my $comments = $c->model('DB::Comment')->summary_count( $site_restriction );
@@ -106,6 +107,8 @@ sub index : Path : Args(0) {
: _('n/a');
$c->stash->{questionnaires} = \%questionnaire_counts;
+ $c->stash->{categories} = $c->cobrand->problems->categories_summary();
+
return 1;
}
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index b1b1e00a4..ca329ab59 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -161,10 +161,10 @@ sub timeline {
}
sub summary_count {
- my ( $rs, $restriction ) = @_;
+ my ( $rs ) = @_;
return $rs->search(
- $restriction,
+ undef,
{
group_by => ['state'],
select => [ 'state', { count => 'id' } ],
@@ -173,4 +173,31 @@ sub summary_count {
);
}
+sub unique_users {
+ my ( $rs ) = @_;
+
+ return $rs->search( {
+ state => [ 'confirmed', 'fixed' ],
+ }, {
+ select => [ { count => { distinct => 'user_id' } } ],
+ as => [ 'count' ]
+ } )->first->get_column('count');
+}
+
+sub categories_summary {
+ my ( $rs ) = @_;
+
+ my $categories = $rs->search( {
+ state => [ 'confirmed', 'fixed' ],
+ whensent => { '<' => \"NOW() - INTERVAL '4 weeks'" },
+ }, {
+ select => [ 'category', { count => 'id' }, { count => \"case when state='fixed' then 1 else null end" } ],
+ as => [ 'category', 'c', 'fixed' ],
+ group_by => [ 'category' ],
+ result_class => 'DBIx::Class::ResultClass::HashRefInflator'
+ } );
+ my %categories = map { $_->{category} => { total => $_->{c}, fixed => $_->{fixed} } } $categories->all;
+ return \%categories;
+}
+
1;