diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 47 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Alert.pm | 12 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Comment.pm | 14 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Contact.pm | 13 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 13 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm | 13 |
6 files changed, 70 insertions, 42 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 930739718..7cd358e72 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -44,14 +44,7 @@ sub index : Path : Args(0) { my ( $sql_restriction, $id, $site_restriction ) = $c->cobrand->site_restriction(); my $cobrand_restriction = $c->cobrand->moniker eq 'fixmystreet' ? {} : { cobrand => $c->cobrand->moniker }; - my $problems = $c->model('DB::Problem')->search( - $site_restriction, - { - group_by => ['state'], - select => [ 'state', { count => 'id' } ], - as => [qw/state state_count/] - } - ); + my $problems = $c->model('DB::Problem')->summary_count( $site_restriction ); my %prob_counts = map { $_->state => $_->get_column('state_count') } $problems->all; @@ -63,29 +56,14 @@ sub index : Path : Args(0) { $c->stash->{total_problems_live} = $prob_counts{confirmed} + $prob_counts{fixed}; - my $comments = $c->model('DB::Comment')->search( - $site_restriction, - { - group_by => ['me.state'], - select => [ 'me.state', { count => 'me.id' } ], - as => [qw/state state_count/], - join => 'problem' - } - ); + my $comments = $c->model('DB::Comment')->summary_count( $site_restriction ); my %comment_counts = map { $_->state => $_->get_column('state_count') } $comments->all; $c->stash->{comments} = \%comment_counts; - my $alerts = $c->model('DB::Alert')->search( - $cobrand_restriction, - { - group_by => ['confirmed'], - select => [ 'confirmed', { count => 'id' } ], - as => [qw/confirmed confirmed_count/] - } - ); + my $alerts = $c->model('DB::Alert')->summary_count( $cobrand_restriction ); my %alert_counts = map { $_->confirmed => $_->get_column('confirmed_count') } $alerts->all; @@ -95,14 +73,7 @@ sub index : Path : Args(0) { $c->stash->{alerts} = \%alert_counts; - my $contacts = $c->model('DB::Contact')->search( - undef, - { - group_by => ['confirmed'], - select => [ 'confirmed', { count => 'id' } ], - as => [qw/confirmed confirmed_count/] - } - ); + my $contacts = $c->model('DB::Contact')->summary_count; my %contact_counts = map { $_->confirmed => $_->get_column('confirmed_count') } $contacts->all; @@ -113,15 +84,7 @@ sub index : Path : Args(0) { $c->stash->{contacts} = \%contact_counts; - my $questionnaires = $c->model('DB::Questionnaire')->search( - $cobrand_restriction, - { - group_by => [ \'whenanswered is not null' ], - select => [ \'(whenanswered is not null)', { count => 'me.id' } ], - as => [qw/answered questionnaire_count/], - join => 'problem' - } - ); + my $questionnaires = $c->model('DB::Questionnaire')->summary_count( $cobrand_restriction ); my %questionnaire_counts = map { $_->get_column('answered') => $_->get_column('questionnaire_count') diff --git a/perllib/FixMyStreet/DB/ResultSet/Alert.pm b/perllib/FixMyStreet/DB/ResultSet/Alert.pm index 62e6120e4..5848265f1 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Alert.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Alert.pm @@ -35,4 +35,16 @@ sub timeline_disabled { ); } +sub summary_count { + my ( $rs, $restriction ) = @_; + + return $rs->search( + $restriction, + { + group_by => ['confirmed'], + select => [ 'confirmed', { count => 'id' } ], + as => [qw/confirmed confirmed_count/] + } + ); +} 1; diff --git a/perllib/FixMyStreet/DB/ResultSet/Comment.pm b/perllib/FixMyStreet/DB/ResultSet/Comment.pm index 4719c7a24..70f8027aa 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Comment.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Comment.pm @@ -24,4 +24,18 @@ sub timeline { ); } +sub summary_count { + my ( $rs, $restriction ) = @_; + + return $rs->search( + $restriction, + { + group_by => ['me.state'], + select => [ 'me.state', { count => 'me.id' } ], + as => [qw/state state_count/], + join => 'problem' + } + ); +} + 1; diff --git a/perllib/FixMyStreet/DB/ResultSet/Contact.pm b/perllib/FixMyStreet/DB/ResultSet/Contact.pm index 52ff498a6..6fa6a03a0 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Contact.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Contact.pm @@ -17,4 +17,17 @@ sub not_deleted { return $rs->search( { deleted => 0 } ); } +sub summary_count { + my ( $rs, $restriction ) = @_; + + return $rs->search( + $restriction, + { + group_by => ['confirmed'], + select => [ 'confirmed', { count => 'id' } ], + as => [qw/confirmed confirmed_count/] + } + ); +} + 1; diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index 8d798a7c1..835ab1b45 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -27,4 +27,17 @@ sub timeline { ); } +sub summary_count { + my ( $rs, $restriction ) = @_; + + return $rs->search( + $restriction, + { + group_by => ['state'], + select => [ 'state', { count => 'id' } ], + as => [qw/state state_count/] + } + ); +} + 1; diff --git a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm index 1f5e26197..ab3acc388 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm @@ -130,4 +130,17 @@ sub timeline { ); } +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' + } + ); +} 1; |