aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/App/Controller')
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Contact.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/JSON.pm82
-rw-r--r--perllib/FixMyStreet/App/Controller/Photo.pm2
-rwxr-xr-xperllib/FixMyStreet/App/Controller/Questionnaire.pm3
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/Update.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm5
-rwxr-xr-xperllib/FixMyStreet/App/Controller/Rss.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Tokens.pm2
11 files changed, 58 insertions, 48 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index aed56e58f..1e06beef1 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -130,7 +130,7 @@ sub load_partial : Private {
|| last;
# load the related problem
- my $report = $c->model("DB::Problem") #
+ my $report = $c->cobrand->problems #
->search( { id => $report_id, state => 'partial' } ) #
->first
|| last;
diff --git a/perllib/FixMyStreet/App/Controller/Contact.pm b/perllib/FixMyStreet/App/Controller/Contact.pm
index c74597f3b..bd7d415e7 100644
--- a/perllib/FixMyStreet/App/Controller/Contact.pm
+++ b/perllib/FixMyStreet/App/Controller/Contact.pm
@@ -63,7 +63,7 @@ sub determine_contact_type : Private {
$update_id = undef unless $update_id && $update_id =~ /^[1-9]\d*$/;
if ($id) {
- my $problem = $c->model('DB::Problem')->find(
+ my $problem = $c->cobrand->problems->find(
{ id => $id },
{
'select' => [
diff --git a/perllib/FixMyStreet/App/Controller/JSON.pm b/perllib/FixMyStreet/App/Controller/JSON.pm
index d3688f19a..37df98735 100644
--- a/perllib/FixMyStreet/App/Controller/JSON.pm
+++ b/perllib/FixMyStreet/App/Controller/JSON.pm
@@ -7,6 +7,7 @@ BEGIN { extends 'Catalyst::Controller'; }
use JSON;
use DateTime;
use DateTime::Format::ISO8601;
+use List::MoreUtils 'uniq';
=head1 NAME
@@ -69,42 +70,53 @@ sub problems : Local {
}
# query the database
- $c->stash->{response} =
- $type eq 'new_problems'
- ? Problems::created_in_interval( $start_date, $end_date )
- : Problems::fixed_in_interval( $start_date, $end_date );
-}
+ my ( $state, $date_col );
+ if ( $type eq 'new_problems' ) {
+ $state = 'confirmed';
+ $date_col = 'created';
+ } elsif ( $type eq 'fixed_problems' ) {
+ $state = 'fixed';
+ $date_col = 'lastupdate';
+ }
+
+ my $one_day = DateTime::Duration->new( days => 1 );
+ my @problems = $c->cobrand->problems->search( {
+ $date_col => {
+ '>=' => $start_dt,
+ '<=' => $end_dt + $one_day,
+ },
+ state => $state,
+ }, {
+ columns => [
+ 'id', 'title', 'council', 'category',
+ 'detail', 'name', 'anonymous', 'confirmed',
+ 'whensent', 'service',
+ ]
+ } );
+
+ my @councils;
+ foreach my $problem (@problems) {
+ $problem->name( '' ) if $problem->anonymous == 1;
+ $problem->service( 'Web interface' ) if $problem->service eq '';
+ if ($problem->council) {
+ (my $council = $problem->council) =~ s/\|.*//g;
+ my @council_ids = split /,/, $council;
+ push(@councils, @council_ids);
+ $problem->council( \@council_ids );
+ }
+ }
+ @councils = uniq @councils;
+ my $areas_info = mySociety::MaPit::call('areas', \@councils);
+ foreach my $problem (@problems) {
+ if ($problem->council) {
+ my @council_names = map { $areas_info->{$_}->{name} } @{$problem->council} ;
+ $problem->council( join(' and ', @council_names) );
+ }
+ }
-# If we convert this code to be fully DBIC based then the following snippet is a
-# good start. The roadblock to doing it fully is the 'site_restriction' in the
-# SQL which is currently provided as SQL, rather than something that could be
-# easily added to the DBIC query. The hardest cobrand to change would be the
-# cities - so perhaps do it after we know wether that needs to be kept or not.
-#
-# my $state =
-# $type eq 'new_problems' ? 'confirmed'
-# : $type eq 'fixed_problems' ? 'fixed_problems'
-# : die;
-#
-# my $one_day = DateTime::Duration->new( days => 1 );
-#
-# my $problems = $c->model('DB::Problem')->search(
-# {
-# created => {
-# '>=' => $start_dt,
-# '<=' => $end_dt + $one_day,
-# },
-# state => $state,
-# # ------ add is site_restriction here -------
-# },
-# {
-# columns => [
-# 'id', 'title', 'council', 'category',
-# 'detail', 'name', 'anonymous', 'confirmed',
-# 'whensent', 'service',
-# ]
-# }
-# );
+ @problems = map { { $_->get_columns } } @problems;
+ $c->stash->{response} = \@problems;
+}
sub end : Private {
my ( $self, $c ) = @_;
diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm
index 7b2a04e4b..3c6255f3a 100644
--- a/perllib/FixMyStreet/App/Controller/Photo.pm
+++ b/perllib/FixMyStreet/App/Controller/Photo.pm
@@ -40,7 +40,7 @@ sub index :Path :Args(0) {
photo => { '!=', undef },
} );
} else {
- @photo = $c->model('DB::Problem')->search( {
+ @photo = $c->cobrand->problems->search( {
id => $id,
state => [ 'confirmed', 'fixed', 'partial' ],
photo => { '!=', undef },
diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm
index 58c88979d..b4c9ade92 100755
--- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm
+++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm
@@ -108,8 +108,7 @@ sub submit_creator_fixed : Private {
$c->detach('missing_problem');
}
- my $problem = $c->model('DB::Problem')->find( { id =>
- $c->stash->{problem} } );
+ my $problem = $c->cobrand->problems->find( { id => $c->stash->{problem} } );
# you should not be able to answer questionnaires about problems
# that you've not submitted
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index c4138f4d6..0fe1834e7 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -62,7 +62,7 @@ sub load_problem_or_display_error : Private {
my $problem #
= $id =~ m{\D} # is id non-numeric?
? undef # ...don't even search
- : $c->model('DB::Problem')->find( { id => $id } );
+ : $c->cobrand->problems->find( { id => $id } );
# check that the problem is suitable to show.
if ( !$problem || $problem->state eq 'unconfirmed' ) {
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 5c52d0257..4d9bcd672 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -289,7 +289,7 @@ sub initialize_report : Private {
|| last;
# load the related problem
- $report = $c->model("DB::Problem") #
+ $report = $c->cobrand->problems #
->search( { id => $id, state => 'partial' } ) #
->first;
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm
index fe512d03c..2ca9245ad 100644
--- a/perllib/FixMyStreet/App/Controller/Report/Update.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm
@@ -99,7 +99,7 @@ sub setup_page : Private {
my ( $self, $c ) = @_;
my $problem =
- $c->model('DB::Problem')->find( { id => $c->req->param('id') } );
+ $c->cobrand->problems->find( { id => $c->req->param('id') } );
return unless $problem;
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index 993cd752e..c64bc9054 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -246,8 +246,7 @@ sub load_problems : Private {
my ( $self, $c ) = @_;
my $where = {
- state => [ 'confirmed', 'fixed' ],
- %{ Problems::site_restriction() }
+ state => [ 'confirmed', 'fixed' ]
};
if ($c->stash->{ward}) {
$where->{areas} = { 'like', '%' . $c->stash->{ward}->{id} . '%' }; # FIXME Check this is secure
@@ -255,7 +254,7 @@ sub load_problems : Private {
$where->{areas} = { 'like', '%' . $c->stash->{council}->{id} . '%' };
}
my $current_timestamp = Problems::current_timestamp();
- my $problems = $c->model('DB::Problem')->search(
+ my $problems = $c->cobrand->problems->search(
$where,
{
columns => [
diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm
index f41ffe217..4c048b56d 100755
--- a/perllib/FixMyStreet/App/Controller/Rss.pm
+++ b/perllib/FixMyStreet/App/Controller/Rss.pm
@@ -30,7 +30,7 @@ sub updates : LocalRegex('^(\d+)$') {
my ( $self, $c ) = @_;
my $id = $c->req->captures->[0];
- my $problem = $c->model('DB::Problem')->find( { id => $id } );
+ my $problem = $c->cobrand->problems->find( { id => $id } );
# FIXME Put these 404/410 checks in central place - Report.pm does it too.
if ( !$problem || $problem->state eq 'unconfirmed' ) {
diff --git a/perllib/FixMyStreet/App/Controller/Tokens.pm b/perllib/FixMyStreet/App/Controller/Tokens.pm
index 92a44e756..c75fcc9ee 100644
--- a/perllib/FixMyStreet/App/Controller/Tokens.pm
+++ b/perllib/FixMyStreet/App/Controller/Tokens.pm
@@ -33,7 +33,7 @@ sub confirm_problem : Path('/P') {
# Load the problem
my $problem_id = $auth_token->data;
- my $problem = $c->model('DB::Problem')->find( { id => $problem_id } )
+ my $problem = $c->cobrand->problems->find( { id => $problem_id } )
|| $c->detach('token_error');
$c->stash->{problem} = $problem;