diff options
author | Struan Donald <struan@exo.org.uk> | 2011-05-12 11:41:06 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2011-05-12 11:41:06 +0100 |
commit | c0cfc5f8d5c9b1c1728e603a368fbe4570393615 (patch) | |
tree | 86b5f9869f0a5b9ee28b4ab5d6625e6787e1dde6 /perllib/FixMyStreet/App/Controller/Alert.pm | |
parent | d5fa6de56ce14cd32877fc451d2355900eb5b649 (diff) |
move creating local alert to own method
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Alert.pm | 113 |
1 files changed, 61 insertions, 52 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 53defe05e..370992854 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -220,57 +220,7 @@ sub subscribe_email : Private { # $alert_id = FixMyStreet::Alert::create($email, 'new_problems', $cobrand, $cobrand_data); } elsif ( $type eq 'local' ) { - my $feed = $c->req->param('feed'); - - my ( $type, @params ); - if ( $feed =~ /^area:(?:\d+:)?(\d+)/ ) { - $type = 'area_problems'; - push @params, $1; - } - elsif ( $feed =~ /^council:(\d+)/ ) { - $type = 'council_problems'; - push @params, $1, $1; - } - elsif ( $feed =~ /^ward:(\d+):(\d+)/ ) { - $type = 'ward_problems'; - push @params, $1, $2; - } - elsif ( $feed =~ - m{ \A local: ( [\+\-]? \d+ \.? \d* ) : ( [\+\-]? \d+ \.? \d* ) }xms - ) - { - $type = 'local_problems'; - push @params, $1, $2; - -# my $lat = $1; -# my $lon = $2; -# $alert_id = FixMyStreet::Alert::create($email, 'local_problems', $cobrand, $cobrand_data, $lon, $lat); - } - - my $options = { - user => $c->stash->{alert_user}, - alert_type => $type - }; - - if ( scalar @params == 1 ) { - $options->{parameter} = $params[0]; - } - elsif ( scalar @params == 2 ) { - $options->{parameter} = $params[0]; - $options->{parameter2} = $params[1]; - } - - $alert = $c->model('DB::Alert')->find($options); - - unless ($alert) { - $options->{cobrand} = $c->cobrand->moniker(); - $options->{cobrand_data} = $c->cobrand->extra_update_data(); - - $alert = $c->model('DB::Alert')->new($options); - $alert->insert(); - } - - $c->log->debug( 'created alert ' . $alert->id ); + $c->forward('create_local_alert'); $c->stash->{template} = 'email_sent.html'; } else { @@ -280,7 +230,7 @@ sub subscribe_email : Private { my $token = $c->model("DB::Token")->create( { scope => 'alert', - data => { id => $alert->id, type => 'subscribe', email => $email } + data => { id => $c->stash->{alert}->id, type => 'subscribe', email => $email } } ); @@ -319,6 +269,65 @@ sub confirm : Private { } } +=head2 create_local_alert + +Create a local alert + +=cut + +sub create_local_alert : Private { + my ( $self, $c ) = @_; + + my $feed = $c->req->param('feed'); + + my ( $type, @params, $alert ); + if ( $feed =~ /^area:(?:\d+:)?(\d+)/ ) { + $type = 'area_problems'; + push @params, $1; + } + elsif ( $feed =~ /^council:(\d+)/ ) { + $type = 'council_problems'; + push @params, $1, $1; + } + elsif ( $feed =~ /^ward:(\d+):(\d+)/ ) { + $type = 'ward_problems'; + push @params, $1, $2; + } + elsif ( $feed =~ + m{ \A local: ( [\+\-]? \d+ \.? \d* ) : ( [\+\-]? \d+ \.? \d* ) }xms ) + { + $type = 'local_problems'; + push @params, $1, $2; + } + + my $options = { + user => $c->stash->{alert_user}, + alert_type => $type + }; + + if ( scalar @params == 1 ) { + $options->{parameter} = $params[0]; + } + elsif ( scalar @params == 2 ) { + $options->{parameter} = $params[0]; + $options->{parameter2} = $params[1]; + } + + $alert = $c->model('DB::Alert')->find($options); + + unless ($alert) { + $options->{cobrand} = $c->cobrand->moniker(); + $options->{cobrand_data} = $c->cobrand->extra_update_data(); + + $alert = $c->model('DB::Alert')->new($options); + $alert->insert(); + } + + $c->stash->{alert} = $alert; + + $c->log->debug( 'created alert ' . $alert->id ); +} + =head2 prettify_pc This will canonicalise and prettify the postcode and stick a pretty_pc and pretty_pc_text in the stash. |