diff options
author | Matthew Somerville <matthew@mysociety.org> | 2011-06-08 13:51:17 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2011-06-08 13:51:17 +0100 |
commit | 500190d03fcbfd8993f46b61bca9e12a7339dbc2 (patch) | |
tree | 3398fbde51e5ef35040b6d9611cb2eabd618071d | |
parent | e19d63897578e31cf40cc185a663cebd8edb9c14 (diff) |
Switch to using c->cobrand->problems to return all problems for a cobrand (so on Barnet only return Barnet problems).
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Contact.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/JSON.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Photo.pm | 2 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Questionnaire.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 2 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Rss.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Tokens.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Barnet.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 21 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Southampton.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 11 |
15 files changed, 44 insertions, 25 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 cbd483f16..37df98735 100644 --- a/perllib/FixMyStreet/App/Controller/JSON.pm +++ b/perllib/FixMyStreet/App/Controller/JSON.pm @@ -80,7 +80,7 @@ sub problems : Local { } my $one_day = DateTime::Duration->new( days => 1 ); - my @problems = $c->model('DB::Problem')->site_restricted->search( { + my @problems = $c->cobrand->problems->search( { $date_col => { '>=' => $start_dt, '<=' => $end_dt + $one_day, 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 7cb9ad9fb..c64bc9054 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -254,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')->site_restricted->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; diff --git a/perllib/FixMyStreet/Cobrand/Barnet.pm b/perllib/FixMyStreet/Cobrand/Barnet.pm index 5373d8c1d..6468fd934 100644 --- a/perllib/FixMyStreet/Cobrand/Barnet.pm +++ b/perllib/FixMyStreet/Cobrand/Barnet.pm @@ -12,6 +12,13 @@ sub site_restriction { return ( "and council='2489'", 'barnet', { council => '2489' } ); } +sub problems { + my $self = shift; + return $self->{c}->model('DB::Problem')->search( { + council => '2489' + } ); +} + sub base_url { my $base_url = mySociety::Config::get('BASE_URL'); if ( $base_url !~ /barnet/ ) { diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 2c64449c3..208ac6643 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -69,6 +69,18 @@ sub path_to_web_templates { return FixMyStreet->path_to( 'templates/web', $self->moniker ); } +=head1 problems + +Returns a ResultSet of Problems, restricted to a subset if we're on a cobrand +that only wants some of the data. + +=cut + +sub problems { + my $self = shift; + return $self->{c}->model('DB::Problem'); +} + =head1 site_restriction Return a site restriction clause and a site key if the cobrand uses a subset of @@ -209,7 +221,7 @@ Return recent problems on the site. sub recent { my ( $self ) = @_; - return $self->{c}->model('DB::Problem')->recent(); + return $self->problems->recent(); } =item shorten_recency_if_new_greater_than_fixed @@ -232,18 +244,17 @@ can then format. sub front_stats_data { my ( $self ) = @_; - my $c = $self->{c}; my $recency = '1 week'; my $shorter_recency = '3 days'; - my $fixed = $c->model('DB::Problem')->recent_fixed(); + my $fixed = $self->problems->recent_fixed(); my $updates = Problems::number_comments(); - my $new = $c->model('DB::Problem')->recent_new( $recency ); + my $new = $self->problems->recent_new( $recency ); if ( $new > $fixed && $self->shorten_recency_if_new_greater_than_fixed ) { $recency = $shorter_recency; - $new = $c->model('DB::Problem')->recent_new( $recency ); + $new = $self->problems->recent_new( $recency ); } my $stats = { diff --git a/perllib/FixMyStreet/Cobrand/Southampton.pm b/perllib/FixMyStreet/Cobrand/Southampton.pm index 24449cf6e..77032baa8 100644 --- a/perllib/FixMyStreet/Cobrand/Southampton.pm +++ b/perllib/FixMyStreet/Cobrand/Southampton.pm @@ -12,6 +12,13 @@ sub site_restriction { return ( "and council='2567'", 'southampton', { council => '2567' } ); } +sub problems { + my $self = shift; + return $self->{c}->model('DB::Problem')->search( { + council => '2567' + } ); +} + sub base_url { my $base_url = mySociety::Config::get('BASE_URL'); if ($base_url !~ /southampton/) { diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index d73d58b82..af850ecd0 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -13,11 +13,6 @@ sub set_restriction { $site_restriction = $restriction; } -sub site_restricted { - my ( $rs ) = @_; - return $rs->search( $site_restriction ); -} - # Front page statistics sub recent_fixed { @@ -25,7 +20,7 @@ sub recent_fixed { my $key = "recent_fixed:$site_key"; my $result = Memcached::get($key); unless ($result) { - $result = $rs->site_restricted->search( { + $result = $rs->search( { state => 'fixed', lastupdate => { '>', \"current_timestamp-'1 month'::interval" }, } )->count; @@ -40,7 +35,7 @@ sub recent_new { $key = "recent_new:$site_key:$key"; my $result = Memcached::get($key); unless ($result) { - $result = $rs->site_restricted->search( { + $result = $rs->search( { state => [ 'confirmed', 'fixed' ], confirmed => { '>', \"current_timestamp-'$interval'::interval" }, } )->count; @@ -56,7 +51,7 @@ sub recent { my $key = "recent:$site_key"; my $result = Memcached::get($key); unless ($result) { - $result = $rs->site_restricted->search( { + $result = $rs->search( { state => [ 'confirmed', 'fixed' ] }, { columns => [ 'id', 'title' ], |