diff options
author | Edmund von der Burg <evdb@mysociety.org> | 2011-04-14 13:05:38 +0100 |
---|---|---|
committer | Edmund von der Burg <evdb@mysociety.org> | 2011-04-14 13:05:38 +0100 |
commit | db605d2095fc8ada23447e93c168f375d6f44738 (patch) | |
tree | f673e0a98714787e96e57b2eccb7306ce790508c /perllib/FixMyStreet/App/Controller/Around.pm | |
parent | 0cc37c30af2ab2826b376cc1406f6a79dd0f46fd (diff) |
fixes to import
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Around.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index ae0976de8..03ad27a54 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -42,6 +42,9 @@ sub around_index : Path : Args(0) { return; } + # Check if we have a partial report + my $partial_report = $c->forward('load_partial'); + # Try to create a location for whatever we have return unless $c->forward('determine_location_from_coords') @@ -52,11 +55,59 @@ sub around_index : Path : Args(0) { # If we have a partial - redirect to /report/new so that it can be # completed. - warn "FIXME - implement"; + if ($partial_report) { + my $new_uri = $c->uri_for( + '/report/new', + { + partial => $c->stash->{partial_token}->token, + latitude => $c->stash->{latitude}, + longitude => $c->stash->{longitude}, + pc => $c->stash->{pc}, + } + ); + return $c->res->redirect($new_uri); + } # Show the nearby reports $c->detach('display_location'); +} + +=head2 load_partial + + my $partial_report = $c->forward('load_partial'); + +Check for the partial token and load the partial report. If found save it and +token to stash and return report. Otherwise return false. + +=cut + +sub load_partial : Private { + my ( $self, $c ) = @_; + + my $partial = scalar $c->req->param('partial') + || return; + + # is it in the database + my $token = + $c->model("DB::Token") + ->find( { scope => 'partial', token => $partial } ) # + || last; + + # can we get an id from it? + my $report_id = $token->data # + || last; + + # load the related problem + my $report = $c->model("DB::Problem") # + ->search( { id => $report_id, state => 'partial' } ) # + ->first + || last; + + # save what we found on the stash. + $c->stash->{partial_token} = $token; + $c->stash->{partial_report} = $report; + return $report; } =head2 display_location |