diff options
author | Struan Donald <struan@exo.org.uk> | 2011-05-25 16:43:28 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2011-05-25 16:43:28 +0100 |
commit | 6a679dbe9f0d7021f176ca23106a74bc2475539e (patch) | |
tree | 731af77d81f4855c045faadd3726fadbb1bb0c18 /perllib/FixMyStreet/App/Controller | |
parent | 34296c409fe2ab9f02e5aeb14100570a8fb68dea (diff) |
submission for questionnaire when problem owner marks it fixed
Diffstat (limited to 'perllib/FixMyStreet/App/Controller')
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Questionnaire.pm | 55 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 2 |
2 files changed, 56 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm index 96650a1c6..7169bc9e7 100755 --- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm +++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm @@ -57,6 +57,54 @@ sub load_questionnaire : Private { sub submit : Path('submit') { my ( $self, $c ) = @_; + if ( $c->req->params->{token} ) { + $c->forward('submit_standard'); + } elsif ( $c->req->params->{problem} ) { + $c->forward('submit_creator_fixed'); + } else { + return; + } + + return 1; +} + +sub submit_creator_fixed : Private { + my ( $self, $c ) = @_; + + my @errors; + + map { $c->stash->{$_} = $c->req->params->{$_} || '' } qw(reported problem); + + push @errors, _('Please say whether you\'ve ever reported a problem to your council before') unless $c->stash->{reported}; + + $c->stash->{problem_id} = $c->stash->{problem}; + $c->stash->{errors} = \@errors; + $c->detach( 'creator_fixed' ) if scalar @errors; + + my $questionnaire = $c->model( 'DB::Questionnaire' )->find_or_new( + { + problem_id => $c->stash->{problem}, + old_state => 'confirmed', + new_state => 'fixed', + } + ); + + unless ( $questionnaire->in_storage ) { + $questionnaire->ever_reported( $c->stash->{reported} eq 'Yes' ? 'y' : 'n' ); + $questionnaire->whensent( \'ms_current_timestamp()' ); + $questionnaire->whenanswered( \'ms_current_timestamp()' ); + $questionnaire->insert; + } + + $c->stash->{creator_fixed} = 1; + $c->stash->{template} = 'tokens/confirm_update.html'; + + return 1; +} + +sub submit_standard : Private { + my ( $self, $c ) = @_; + $c->forward( '/tokens/load_questionnaire_id', [ $c->req->params->{token} ] ); $c->forward( 'load_questionnaire' ); @@ -218,6 +266,13 @@ sub display : Private { $c->stash->{cobrand_form_elements} = $c->cobrand->form_elements('questionnaireForm'); } +=head2 creator_fixed + +Display the reduced questionnaire that we display when the reporter of a +problem submits an update marking it as fixed. + +=cut + sub creator_fixed : Private { my ( $self, $c ) = @_; diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 1bc15f1f3..8af3cd2a2 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -68,7 +68,7 @@ sub update_problem : Private { $problem->lastupdate( \'ms_current_timestamp()' ); $problem->update; - $c->stash->{problem} = $problem; + $c->stash->{problem_id} = $problem->id; if ($display_questionnaire) { $c->detach('/questionnaire/creator_fixed'); |